@@ -40,10 +40,10 @@ func TestPs(t *testing.T) {
4040 args := filters .NewArgs (projectFilter (testProject ))
4141 args .Add ("label" , "com.docker.compose.oneoff=False" )
4242 listOpts := apitypes.ContainerListOptions {Filters : args , All : true }
43- c1 , inspect1 := containerDetails ("service1" , "123" , "Running " , "healthy" )
44- c2 , inspect2 := containerDetails ("service1" , "456" , "Running " , "" )
43+ c1 , inspect1 := containerDetails ("service1" , "123" , "running " , "healthy" , 0 )
44+ c2 , inspect2 := containerDetails ("service1" , "456" , "running " , "" , 0 )
4545 c2 .Ports = []apitypes.Port {{PublicPort : 80 , PrivatePort : 90 , IP : "localhost" }}
46- c3 , inspect3 := containerDetails ("service2" , "789" , "Running " , "" )
46+ c3 , inspect3 := containerDetails ("service2" , "789" , "exited " , "" , 130 )
4747 api .EXPECT ().ContainerList (ctx , listOpts ).Return ([]apitypes.Container {c1 , c2 , c3 }, nil )
4848 api .EXPECT ().ContainerInspect (anyCancellableContext (), "123" ).Return (inspect1 , nil )
4949 api .EXPECT ().ContainerInspect (anyCancellableContext (), "456" ).Return (inspect2 , nil )
@@ -52,45 +52,21 @@ func TestPs(t *testing.T) {
5252 containers , err := tested .Ps (ctx , testProject , compose.PsOptions {})
5353
5454 expected := []compose.ContainerSummary {
55- {ID : "123" , Name : "123" , Project : testProject , Service : "service1" , State : "Running " , Health : "healthy" , Publishers : nil },
56- {ID : "456" , Name : "456" , Project : testProject , Service : "service1" , State : "Running " , Health : "" , Publishers : []compose.PortPublisher {{URL : "localhost:80" , TargetPort : 90 , PublishedPort : 80 }}},
57- {ID : "789" , Name : "789" , Project : testProject , Service : "service2" , State : "Running " , Health : "" , Publishers : nil },
55+ {ID : "123" , Name : "123" , Project : testProject , Service : "service1" , State : "running " , Health : "healthy" , Publishers : nil },
56+ {ID : "456" , Name : "456" , Project : testProject , Service : "service1" , State : "running " , Health : "" , Publishers : []compose.PortPublisher {{URL : "localhost:80" , TargetPort : 90 , PublishedPort : 80 }}},
57+ {ID : "789" , Name : "789" , Project : testProject , Service : "service2" , State : "exited " , Health : "" , ExitCode : 130 , Publishers : nil },
5858 }
5959 assert .NilError (t , err )
6060 assert .DeepEqual (t , containers , expected )
6161}
6262
63- func TestPsAll (t * testing.T ) {
64- mockCtrl := gomock .NewController (t )
65- defer mockCtrl .Finish ()
66- api := mocks .NewMockAPIClient (mockCtrl )
67- tested .apiClient = api
68-
69- ctx := context .Background ()
70- listOpts := apitypes.ContainerListOptions {Filters : filters .NewArgs (projectFilter (testProject )), All : true }
71- c1 , inspect1 := containerDetails ("service1" , "123" , "Running" , "healthy" )
72- c2 , inspect2 := containerDetails ("service1" , "456" , "Stopped" , "" )
73- api .EXPECT ().ContainerList (ctx , listOpts ).Return ([]apitypes.Container {c1 , c2 }, nil )
74- api .EXPECT ().ContainerInspect (anyCancellableContext (), "123" ).Return (inspect1 , nil )
75- api .EXPECT ().ContainerInspect (anyCancellableContext (), "456" ).Return (inspect2 , nil )
76-
77- containers , err := tested .Ps (ctx , testProject , compose.PsOptions {All : true })
78-
79- expected := []compose.ContainerSummary {
80- {ID : "123" , Name : "123" , Project : testProject , Service : "service1" , State : "Running" , Health : "healthy" , Publishers : nil },
81- {ID : "456" , Name : "456" , Project : testProject , Service : "service1" , State : "Stopped" , Health : "" , Publishers : nil },
82- }
83- assert .NilError (t , err )
84- assert .DeepEqual (t , containers , expected )
85- }
86-
87- func containerDetails (service string , id string , status string , health string ) (apitypes.Container , apitypes.ContainerJSON ) {
63+ func containerDetails (service string , id string , status string , health string , exitCode int ) (apitypes.Container , apitypes.ContainerJSON ) {
8864 container := apitypes.Container {
8965 ID : id ,
9066 Names : []string {"/" + id },
9167 Labels : containerLabels (service ),
9268 State : status ,
9369 }
94- inspect := apitypes.ContainerJSON {ContainerJSONBase : & apitypes.ContainerJSONBase {State : & apitypes.ContainerState {Status : status , Health : & apitypes.Health {Status : health }}}}
70+ inspect := apitypes.ContainerJSON {ContainerJSONBase : & apitypes.ContainerJSONBase {State : & apitypes.ContainerState {Status : status , Health : & apitypes.Health {Status : health }, ExitCode : exitCode }}}
9571 return container , inspect
9672}
0 commit comments