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>
This commit is contained in:
Sebastiaan van Stijn 2024-10-13 18:48:47 +02:00
parent 3b38dc67be
commit 35d7b1a7a6
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
1 changed files with 7 additions and 5 deletions

View File

@ -38,7 +38,7 @@ func waitFn(cid string) (<-chan container.WaitResponse, <-chan error) {
} }
func TestWaitExitOrRemoved(t *testing.T) { func TestWaitExitOrRemoved(t *testing.T) {
testcases := []struct { tests := []struct {
cid string cid string
exitCode int exitCode int
}{ }{
@ -61,9 +61,11 @@ func TestWaitExitOrRemoved(t *testing.T) {
} }
client := &fakeClient{waitFunc: waitFn, Version: api.DefaultVersion} client := &fakeClient{waitFunc: waitFn, Version: api.DefaultVersion}
for _, testcase := range testcases { for _, tc := range tests {
statusC := waitExitOrRemoved(context.Background(), client, testcase.cid, true) t.Run(tc.cid, func(t *testing.T) {
exitCode := <-statusC statusC := waitExitOrRemoved(context.Background(), client, tc.cid, true)
assert.Check(t, is.Equal(testcase.exitCode, exitCode)) exitCode := <-statusC
assert.Check(t, is.Equal(tc.exitCode, exitCode))
})
} }
} }