Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
Add tests for ps --all
Browse files Browse the repository at this point in the history
  • Loading branch information
rumpl committed May 18, 2020
1 parent 89a0a46 commit a428ab2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cli/cmd/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
15 changes: 12 additions & 3 deletions example/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions tests/e2e/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,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"))
Expand Down

0 comments on commit a428ab2

Please sign in to comment.