From ef6cca9699016004b53003c4dab2f52f2f534052 Mon Sep 17 00:00:00 2001 From: Harald Albers Date: Wed, 30 Oct 2024 19:40:55 +0000 Subject: [PATCH] Use subtests Signed-off-by: Harald Albers --- cli/command/container/completion_test.go | 25 +++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/cli/command/container/completion_test.go b/cli/command/container/completion_test.go index dce3237092..ca75a49b5f 100644 --- a/cli/command/container/completion_test.go +++ b/cli/command/container/completion_test.go @@ -1,7 +1,6 @@ package container import ( - "fmt" "strings" "testing" @@ -56,14 +55,15 @@ func TestCompletePid(t *testing.T) { } for _, tc := range tests { - cli := test.NewFakeCli(&fakeClient{ - containerListFunc: tc.containerListFunc, + tc := tc + t.Run(tc.toComplete, func(t *testing.T) { + cli := test.NewFakeCli(&fakeClient{ + containerListFunc: tc.containerListFunc, + }) + completions, directive := completePid(cli)(NewRunCommand(cli), nil, tc.toComplete) + assert.Check(t, is.DeepEqual(completions, tc.expectedCompletions)) + assert.Check(t, is.Equal(directive, tc.expectedDirective)) }) - - completions, directive := completePid(cli)(NewRunCommand(cli), nil, tc.toComplete) - - assert.DeepEqual(t, completions, tc.expectedCompletions) - assert.Equal(t, directive, tc.expectedDirective, fmt.Sprintf("wrong directive in completion for '%s'", tc.toComplete)) } } @@ -119,9 +119,12 @@ func TestCompleteSecurityOpts(t *testing.T) { } for _, tc := range tests { - completions, directive := completeSecurityOpt(nil, nil, tc.toComplete) - assert.DeepEqual(t, completions, tc.expectedCompletions) - assert.Equal(t, directive, tc.expectedDirective, fmt.Sprintf("wrong directive in completion for '%s'", tc.toComplete)) + tc := tc + t.Run(tc.toComplete, func(t *testing.T) { + completions, directive := completeSecurityOpt(nil, nil, tc.toComplete) + assert.Check(t, is.DeepEqual(completions, tc.expectedCompletions)) + assert.Check(t, is.Equal(directive, tc.expectedDirective)) + }) } }