Skip to content

Commit 35d7b1a

Browse files
committed
cli/command/container: TestWaitExitOrRemoved use subtests
=== RUN TestWaitExitOrRemoved === RUN TestWaitExitOrRemoved/normal-container === RUN TestWaitExitOrRemoved/give-me-exit-code-42 === RUN TestWaitExitOrRemoved/i-want-a-wait-error time="2024-10-13T18:48:14+02:00" level=error msg="Error waiting for container: removal failed" === RUN TestWaitExitOrRemoved/non-existent-container-id time="2024-10-13T18:48:14+02:00" level=error msg="error waiting for container: no such container: non-existent-container-id" --- PASS: TestWaitExitOrRemoved (0.00s) --- PASS: TestWaitExitOrRemoved/normal-container (0.00s) --- PASS: TestWaitExitOrRemoved/give-me-exit-code-42 (0.00s) --- PASS: TestWaitExitOrRemoved/i-want-a-wait-error (0.00s) --- PASS: TestWaitExitOrRemoved/non-existent-container-id (0.00s) PASS Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 3b38dc6 commit 35d7b1a

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

cli/command/container/utils_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func waitFn(cid string) (<-chan container.WaitResponse, <-chan error) {
3838
}
3939

4040
func TestWaitExitOrRemoved(t *testing.T) {
41-
testcases := []struct {
41+
tests := []struct {
4242
cid string
4343
exitCode int
4444
}{
@@ -61,9 +61,11 @@ func TestWaitExitOrRemoved(t *testing.T) {
6161
}
6262

6363
client := &fakeClient{waitFunc: waitFn, Version: api.DefaultVersion}
64-
for _, testcase := range testcases {
65-
statusC := waitExitOrRemoved(context.Background(), client, testcase.cid, true)
66-
exitCode := <-statusC
67-
assert.Check(t, is.Equal(testcase.exitCode, exitCode))
64+
for _, tc := range tests {
65+
t.Run(tc.cid, func(t *testing.T) {
66+
statusC := waitExitOrRemoved(context.Background(), client, tc.cid, true)
67+
exitCode := <-statusC
68+
assert.Check(t, is.Equal(tc.exitCode, exitCode))
69+
})
6870
}
6971
}

0 commit comments

Comments
 (0)