Skip to content

Commit

Permalink
cli/command/container: TestWaitExitOrRemoved use subtests
Browse files Browse the repository at this point in the history
    === 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 <[email protected]>
  • Loading branch information
thaJeztah committed Oct 13, 2024
1 parent 26fa5dc commit b7c142d
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions cli/command/container/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func waitFn(cid string) (<-chan container.WaitResponse, <-chan error) {
}

func TestWaitExitOrRemoved(t *testing.T) {
testcases := []struct {
tests := []struct {
cid string
exitCode int
}{
Expand All @@ -60,10 +60,13 @@ func TestWaitExitOrRemoved(t *testing.T) {
},
}

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

statusC := waitExitOrRemoved(context.Background(), client, tc.cid, true)
exitCode := <-statusC
assert.Check(t, is.Equal(tc.exitCode, exitCode))
})
}
}

0 comments on commit b7c142d

Please sign in to comment.