From a0dda2d094075db02153b5dcabca5980a4a5bd24 Mon Sep 17 00:00:00 2001 From: Djordje Lukic Date: Mon, 18 May 2020 14:16:32 +0200 Subject: [PATCH] Add tests for ps --all --- cli/cmd/ps.go | 2 +- example/backend.go | 15 ++++++++++++--- tests/e2e/e2e.go | 9 +++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/cli/cmd/ps.go b/cli/cmd/ps.go index 49123b46..0ea4c749 100644 --- a/cli/cmd/ps.go +++ b/cli/cmd/ps.go @@ -31,7 +31,7 @@ func PsCommand() *cobra.Command { } cmd.Flags().BoolVarP(&opts.quiet, "quiet", "q", false, "Only display IDs") - cmd.Flags().BoolVarP(&opts.quiet, "all", "a", false, "Show all containers (default shows just running)") + cmd.Flags().BoolVarP(&opts.all, "all", "a", false, "Show all containers (default shows just running)") return cmd } diff --git a/example/backend.go b/example/backend.go index fc94bc0a..0fb2edb5 100644 --- a/example/backend.go +++ b/example/backend.go @@ -38,8 +38,8 @@ func init() { type containerService struct{} -func (cs *containerService) List(ctx context.Context, _ bool) ([]containers.Container, error) { - return []containers.Container{ +func (cs *containerService) List(ctx context.Context, all bool) ([]containers.Container, error) { + result := []containers.Container{ { ID: "id", Image: "nginx", @@ -48,7 +48,16 @@ func (cs *containerService) List(ctx context.Context, _ bool) ([]containers.Cont ID: "1234", Image: "alpine", }, - }, nil + } + + if all { + result = append(result, containers.Container{ + ID: "stopped", + Image: "nginx", + }) + } + + return result, nil } func (cs *containerService) Run(ctx context.Context, r containers.ContainerConfig) error { diff --git a/tests/e2e/e2e.go b/tests/e2e/e2e.go index c371259a..1b577dd5 100644 --- a/tests/e2e/e2e.go +++ b/tests/e2e/e2e.go @@ -80,6 +80,15 @@ func main() { Expect(lines[1]).To(Equal("1234")) }) + It("can run ps command with all ", func() { + output := NewDockerCommand("ps", "-q", "--all").ExecOrDie() + lines := Lines(output) + Expect(len(lines)).To(Equal(3)) + Expect(lines[0]).To(Equal("id")) + Expect(lines[1]).To(Equal("1234")) + Expect(lines[2]).To(Equal("stopped")) + }) + It("can run 'run' command", func() { output := NewDockerCommand("run", "nginx", "-p", "80:80").ExecOrDie() Expect(output).To(ContainSubstring("Running container \"nginx\" with name"))