mirror of
				https://github.com/docker/compose.git
				synced 2025-10-31 11:14:02 +01:00 
			
		
		
		
	Add tests for ps --all
This commit is contained in:
		
							parent
							
								
									a26dd81307
								
							
						
					
					
						commit
						a0dda2d094
					
				| @ -31,7 +31,7 @@ func PsCommand() *cobra.Command { | |||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	cmd.Flags().BoolVarP(&opts.quiet, "quiet", "q", false, "Only display IDs") | 	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 | 	return cmd | ||||||
| } | } | ||||||
|  | |||||||
| @ -38,8 +38,8 @@ func init() { | |||||||
| 
 | 
 | ||||||
| type containerService struct{} | type containerService struct{} | ||||||
| 
 | 
 | ||||||
| func (cs *containerService) List(ctx context.Context, _ bool) ([]containers.Container, error) { | func (cs *containerService) List(ctx context.Context, all bool) ([]containers.Container, error) { | ||||||
| 	return []containers.Container{ | 	result := []containers.Container{ | ||||||
| 		{ | 		{ | ||||||
| 			ID:    "id", | 			ID:    "id", | ||||||
| 			Image: "nginx", | 			Image: "nginx", | ||||||
| @ -48,7 +48,16 @@ func (cs *containerService) List(ctx context.Context, _ bool) ([]containers.Cont | |||||||
| 			ID:    "1234", | 			ID:    "1234", | ||||||
| 			Image: "alpine", | 			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 { | func (cs *containerService) Run(ctx context.Context, r containers.ContainerConfig) error { | ||||||
|  | |||||||
| @ -80,6 +80,15 @@ func main() { | |||||||
| 		Expect(lines[1]).To(Equal("1234")) | 		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() { | 	It("can run 'run' command", func() { | ||||||
| 		output := NewDockerCommand("run", "nginx", "-p", "80:80").ExecOrDie() | 		output := NewDockerCommand("run", "nginx", "-p", "80:80").ExecOrDie() | ||||||
| 		Expect(output).To(ContainSubstring("Running container \"nginx\" with name")) | 		Expect(output).To(ContainSubstring("Running container \"nginx\" with name")) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user