Ver Fonte

Add tests for ps --all

Djordje Lukic há 5 anos atrás
pai
commit
a0dda2d094
3 ficheiros alterados com 22 adições e 4 exclusões
  1. 1 1
      cli/cmd/ps.go
  2. 12 3
      example/backend.go
  3. 9 0
      tests/e2e/e2e.go

+ 1 - 1
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
 }

+ 12 - 3
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 {

+ 9 - 0
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"))