-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/docker: add tests for flag-completions, and refactor
Remove the registerCompletionFuncForGlobalFlags for now, as the error it returned was ignored, so it didn't add much benefit, other than abstracting things. Split the underlying completion-functions to separate functions, and add some basic tests for them. Remove the completions helper, as it now didn't add much, and it saved having the dependency on the package. Signed-off-by: Sebastiaan van Stijn <[email protected]>
- Loading branch information
Showing
3 changed files
with
61 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/docker/cli/cli/context/store" | ||
"github.com/spf13/cobra" | ||
"gotest.tools/v3/assert" | ||
is "gotest.tools/v3/assert/cmp" | ||
) | ||
|
||
type fakeCLI struct { | ||
contextStore store.Store | ||
} | ||
|
||
func (c *fakeCLI) ContextStore() store.Store { | ||
return c.contextStore | ||
} | ||
|
||
type fakeContextStore struct { | ||
store.Store | ||
names []string | ||
} | ||
|
||
func (f fakeContextStore) List() (c []store.Metadata, _ error) { | ||
for _, name := range f.names { | ||
c = append(c, store.Metadata{Name: name}) | ||
} | ||
return c, nil | ||
} | ||
|
||
func TestCompleteContextNames(t *testing.T) { | ||
expectedNames := []string{"context-b", "context-c", "context-a"} | ||
cli := &fakeCLI{ | ||
contextStore: fakeContextStore{ | ||
names: expectedNames, | ||
}, | ||
} | ||
|
||
values, directives := completeContextNames(cli)(nil, nil, "") | ||
assert.Check(t, is.Equal(directives, cobra.ShellCompDirectiveNoFileComp)) | ||
assert.Check(t, is.DeepEqual(values, expectedNames)) | ||
} | ||
|
||
func TestCompleteLogLevels(t *testing.T) { | ||
values, directives := completeLogLevels(nil, nil, "") | ||
assert.Check(t, is.Equal(directives, cobra.ShellCompDirectiveNoFileComp)) | ||
assert.Check(t, is.DeepEqual(values, logLevels)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters