-
Notifications
You must be signed in to change notification settings - Fork 13
/
job_test.go
155 lines (139 loc) · 4.83 KB
/
job_test.go
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package opslevel_test
import (
"testing"
ol "github.com/opslevel/opslevel-go/v2024"
"github.com/rocktavious/autopilot/v2023"
)
func TestRunnerRegister(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation RunnerRegister{runnerRegister{runner{id,status},errors{message,path}}}`,
`{}`,
`{"data": {"runnerRegister": { "runner": { "id": "1234", "status": "registered" }, "errors": [] }}}`,
)
client := BestTestClient(t, "job/register", testRequest)
// Act
result, err := client.RunnerRegister()
// Assert
autopilot.Ok(t, err)
autopilot.Equals(t, ol.ID("1234"), result.Id)
}
func TestRunnerGetScale(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`query RunnerScale($currentReplicaCount:Int!$jobConcurrency:Int!$runnerId:ID!){account{runnerScale(runnerId: $runnerId, currentReplicaCount: $currentReplicaCount, jobConcurrency: $jobConcurrency){recommendedReplicaCount}}}`,
`{"currentReplicaCount":2, "jobConcurrency":3, "runnerId":"1234567890" }`,
`{"data": { "account": { "runnerScale": { "recommendedReplicaCount": 6 }}}}`,
)
client := BestTestClient(t, "job/scale", testRequest)
// Act
result, err := client.RunnerScale("1234567890", 2, 3)
// Assert
autopilot.Ok(t, err)
autopilot.Equals(t, 6, result.RecommendedReplicaCount)
}
func TestRunnerGetPendingJobs(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation RunnerGetPendingJob($id:ID!$token:ID){runnerGetPendingJob(runnerId: $id lastUpdateToken: $token){runnerJob{commands,id,image,outcome,status,variables{key,sensitive,value},files{name,contents}},lastUpdateToken,errors{message,path}}}`,
`{"id":"1234567890", "token": "1234"}`,
`{"data": {
"runnerGetPendingJob": {
"runnerJob": {
{{ template "id1" }},
"image": "public.ecr.aws/opslevel/cli:v2022.02.25",
"outcome": "unstarted",
"status": "running",
"commands": [
"pwd",
"ls -al",
"env | grep AWS"
],
"variables": [
{
"key": "AWS_ACCESS_KEY",
"value": "XXXXXXX"
}
]
},
"lastUpdateToken": "12344321",
"errors": []
}}}`,
)
client := BestTestClient(t, "job/get_pending", testRequest)
// Act
result, token, err := client.RunnerGetPendingJob("1234567890", "1234")
// Assert
autopilot.Ok(t, err)
autopilot.Equals(t, "public.ecr.aws/opslevel/cli:v2022.02.25", result.Image)
autopilot.Equals(t, "ls -al", result.Commands[1])
autopilot.Equals(t, ol.ID("12344321"), token)
}
func TestRunnerAppendJobLog(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation RunnerAppendJobLog($input:RunnerAppendJobLogInput!){runnerAppendJobLog(input: $input){errors{message,path}}}`,
`{"input":{ "logChunk":["Log1", "Log2"], "runnerId":"1234", "runnerJobId":"5678", "sentAt":"2022-07-01T01:00:00Z" }}`,
`{"data": { "runnerAppendJobLog": { "errors": [] }}}`,
)
client := BestTestClient(t, "job/append_log", testRequest)
// Act
err := client.RunnerAppendJobLog(ol.RunnerAppendJobLogInput{
RunnerId: "1234",
RunnerJobId: "5678",
SentAt: ol.NewISO8601Date("2022-07-01T01:00:00.000Z"),
Logs: []string{"Log1", "Log2"},
})
// Assert
autopilot.Ok(t, err)
}
func TestRunnerReportJobOutcome(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation RunnerReportJobOutcome($input:RunnerReportJobOutcomeInput!){runnerReportJobOutcome(input: $input){errors{message,path}}}`,
`{"input": { "runnerId":"1234567890", "runnerJobId": "{{ template "id1_string" }}", "outcome":"execution_timeout" }}`,
`{"data": { "runnerReportJobOutcome": { "errors": [] }}}`,
)
client := BestTestClient(t, "job/report_outcome", testRequest)
// Act
err := client.RunnerReportJobOutcome(ol.RunnerReportJobOutcomeInput{
RunnerId: "1234567890",
RunnerJobId: id1,
Outcome: ol.RunnerJobOutcomeEnumExecutionTimeout,
})
// Assert
autopilot.Ok(t, err)
}
func TestRunnerUnregister(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation RunnerUnregister($runnerId:ID!){runnerUnregister(runnerId: $runnerId){errors{message,path}}}`,
`{"runnerId": "1234" }`,
`{"data": { "runnerUnregister": { "errors": [] }}}`,
)
client := BestTestClient(t, "job/unregister", testRequest)
// Act
err := client.RunnerUnregister("1234")
// Assert
autopilot.Ok(t, err)
}
func TestRunnerJobNumber(t *testing.T) {
// Arrange
job := ol.RunnerJob{
Id: "Z2lkOi8vb3BzbGV2ZWwvUnVubmVyczo6Sm9iUnVuLzIyNQ",
}
// Act
jobNumber := job.Number()
// Assert
autopilot.Equals(t, "225", jobNumber)
}
func TestRunnerJobNumberFailure(t *testing.T) {
// Arrange
job := ol.RunnerJob{
Id: "Z2lkOi8vb3BzbGV2ZWwvUnVubmVyczo6Sm9iU",
}
// Act
jobNumber := job.Number()
// Assert
autopilot.Equals(t, "Z2lkOi8vb3BzbGV2ZWwvUnVubmVyczo6Sm9iU", jobNumber)
}