Use subtests

Signed-off-by: Harald Albers <github@albersweb.de>
This commit is contained in:
Harald Albers 2024-10-30 19:40:55 +00:00
parent 33d3246a37
commit ef6cca9699
1 changed files with 14 additions and 11 deletions

View File

@ -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))
})
}
}