-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrestart_application.lua
94 lines (86 loc) · 1.87 KB
/
restart_application.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
Helper.readK8sResources("k8s_resources/simple")
-- Ensure the default user has the role "Team member" for the team "slug-1"
Helper.SQLExec([[
INSERT INTO
user_roles (role_name, user_id, target_team_slug)
VALUES (
'Team member',
(SELECT id FROM users WHERE email = '[email protected]'),
'slug-1'
)
ON CONFLICT DO NOTHING;
;
]])
Test.gql("as team member", function(t)
t.query [[
mutation {
restartApplication(
input: {teamSlug: "slug-1", environmentName: "dev", name: "another-app"}
) {
application {
name
}
}
}
]]
t.check {
data = {
restartApplication = {
application = {
name = "another-app",
},
},
},
}
end)
local nonTeamMemberEmail = "[email protected]"
Helper.SQLExec([[
DELETE FROM user_roles WHERE user_id = (SELECT id FROM users WHERE email = $1);
]], nonTeamMemberEmail)
Test.gql("as non-team member", function(t)
t.query([[
mutation {
restartApplication(
input: {teamSlug: "slug-1", environmentName: "dev", name: "another-app"}
) {
application {
name
}
}
}
]], { ["x-user-email"] = nonTeamMemberEmail })
t.check {
data = Null,
errors = {
{
message = Contains("you need the \"applications:update\""),
path = { "restartApplication" },
},
},
}
end)
Test.k8s("The resource has proper annotations", function(t)
t.check("apps/v1", "deployments", "dev", "slug-1", "another-app", {
apiVersion = "apps/v1",
kind = "Deployment",
metadata = Ignore(),
spec = {
replicas = Ignore(),
selector = Ignore(),
strategy = Ignore(),
template = {
spec = NotNull(),
metadata = {
annotations = {
["kubectl.kubernetes.io/restartedAt"] = NotNull(),
["prometheus.io/port"] = "8080",
["prometheus.io/scrape"] = "true",
},
creationTimestamp = Ignore(),
labels = Ignore(),
},
},
},
status = Ignore(),
})
end)