This commit is contained in:
Djordje Lukic 2020-05-18 14:16:32 +02:00
Родитель a26dd81307
Коммит a0dda2d094
3 изменённых файлов: 22 добавлений и 4 удалений

Просмотреть файл

@ -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
}

Просмотреть файл

@ -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 {

Просмотреть файл

@ -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"))