@@ -40,10 +40,10 @@ func TestPs(t *testing.T) {
40
40
args := filters .NewArgs (projectFilter (testProject ))
41
41
args .Add ("label" , "com.docker.compose.oneoff=False" )
42
42
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 )
45
45
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 )
47
47
api .EXPECT ().ContainerList (ctx , listOpts ).Return ([]apitypes.Container {c1 , c2 , c3 }, nil )
48
48
api .EXPECT ().ContainerInspect (anyCancellableContext (), "123" ).Return (inspect1 , nil )
49
49
api .EXPECT ().ContainerInspect (anyCancellableContext (), "456" ).Return (inspect2 , nil )
@@ -52,45 +52,21 @@ func TestPs(t *testing.T) {
52
52
containers , err := tested .Ps (ctx , testProject , compose.PsOptions {})
53
53
54
54
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 },
58
58
}
59
59
assert .NilError (t , err )
60
60
assert .DeepEqual (t , containers , expected )
61
61
}
62
62
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 ) {
88
64
container := apitypes.Container {
89
65
ID : id ,
90
66
Names : []string {"/" + id },
91
67
Labels : containerLabels (service ),
92
68
State : status ,
93
69
}
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 }}}
95
71
return container , inspect
96
72
}
0 commit comments