From b7c142de128a793ad928e38a6a37c4cc1e04c3a4 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sun, 13 Oct 2024 18:48:47 +0200 Subject: [PATCH] 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 --- cli/command/container/utils_test.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/cli/command/container/utils_test.go b/cli/command/container/utils_test.go index 7903113c566f..431c709a3782 100644 --- a/cli/command/container/utils_test.go +++ b/cli/command/container/utils_test.go @@ -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 }{ @@ -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)) + }) } }