-
Notifications
You must be signed in to change notification settings - Fork 0
/
stop_test.go
68 lines (59 loc) · 2.15 KB
/
stop_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
package dockworker
import (
"fmt"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestStop(t *testing.T) {
ts, whRecorder, webhookServer := testSetup(t)
jobURL := fmt.Sprintf("%s/%s", ts.URL, "jobs")
for i, tc := range stopTestCases {
jobPOST := createJob(t, i, jobURL, fmt.Sprintf(tc.requestBody, webhookServer.URL))
waitUntilRunning(t, i, jobURL, jobPOST.ID)
// let the job run for a bit
time.Sleep(time.Second * 4)
stopJob(t, i, jobURL, jobPOST.ID)
waitUntilDone(t, i, jobURL, jobPOST.ID)
jobGET := getJob(t, i, jobURL, jobPOST.ID)
assert.Equal(t, tc.resultStatus, jobGET.Status, "Case %d: Status should match", i)
assert.Equal(t, tc.job.Results, jobGET.Results, "Case %d: Results should match", i)
assert.Equal(t, tc.numContainers, len(jobGET.Containers), "Case %d: Number of containers should match", i)
assert.Equal(t, tc.numImages, len(jobGET.Images), "Case %d: Number of images should match", i)
// check the logs of the job
logs := getLogs(t, i, jobURL, jobPOST.ID)
assert.Equal(t, tc.logs, logs, "Case %d: Logs should match", i)
assert.Condition(t, func() bool { return i < len(whRecorder.webhookRequests) }, "Case %d: Webhook requests length not great enough", i)
whJob := whRecorder.webhookRequests[i]
assert.Equal(t, tc.resultStatus, whJob.Status, "Case %d: Webhook status should match", i)
assert.Equal(t, tc.job.Results, whJob.Results, "Case %d: Webhook results should match", i)
assert.Equal(t, tc.numContainers, len(whJob.Containers), "Case %d: Webhook number of containers should match", i)
assert.Equal(t, tc.numImages, len(whJob.Images), "Case %d: Webhook number of images should match", i)
}
defer webhookServer.Close()
defer ts.Close()
}
var stopTestCases = []testCase{
testCase{
requestBody: `{
"image": "ubuntu:14.04",
"cmds": [
["echo", "Sleeping..."],
["sleep", "30"]
],
"webhook_url": "%s"
}`,
job: Job{
ImageName: "ubuntu:14.04",
Cmds: []Cmd{
[]string{"echo", "Sleeping..."},
[]string{"sleep", "30"},
},
Results: []CmdResult{0, 137},
},
resultStatus: JobStatusStopped,
numContainers: 2,
numImages: 1,
logs: "Sleeping...\n",
},
}