-
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.
Add tests for
events --filter container=
Signed-off-by: Harald Albers <[email protected]>
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 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,45 @@ | ||
package system | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"testing" | ||
|
||
"github.com/docker/cli/internal/test" | ||
"github.com/docker/cli/internal/test/builders" | ||
"github.com/docker/docker/api/types/container" | ||
"github.com/spf13/cobra" | ||
"gotest.tools/v3/assert" | ||
) | ||
|
||
// Successful completion lists all container names, prefixed with "container=". | ||
// Filtering the completions by the current word is delegated to the completion script. | ||
func TestCompleteEventFilterContainer(t *testing.T) { | ||
cli := test.NewFakeCli(&fakeClient{ | ||
containerListFunc: func(_ context.Context, _ container.ListOptions) ([]container.Summary, error) { | ||
return []container.Summary{ | ||
*builders.Container("foo"), | ||
*builders.Container("bar"), | ||
}, nil | ||
}, | ||
}) | ||
|
||
completions, directive := completeFilters(cli)(NewEventsCommand(cli), nil, "container=") | ||
|
||
assert.DeepEqual(t, completions, []string{"container=foo", "container=bar"}) | ||
assert.Equal(t, directive, cobra.ShellCompDirectiveNoFileComp) | ||
} | ||
|
||
// In case of API errors, no completions are returned. | ||
func TestCompleteEventFilterContainerAPIError(t *testing.T) { | ||
cli := test.NewFakeCli(&fakeClient{ | ||
containerListFunc: func(_ context.Context, _ container.ListOptions) ([]container.Summary, error) { | ||
return nil, errors.New("API error") | ||
}, | ||
}) | ||
|
||
completions, directive := completeFilters(cli)(NewEventsCommand(cli), nil, "container=") | ||
|
||
assert.DeepEqual(t, completions, []string{}) | ||
assert.Equal(t, directive, cobra.ShellCompDirectiveNoFileComp) | ||
} |