@@ -22,11 +22,11 @@ import (
22
22
"testing"
23
23
24
24
containerType "github.com/docker/docker/api/types/container"
25
+ "github.com/docker/docker/api/types/filters"
25
26
"go.uber.org/mock/gomock"
26
27
"gotest.tools/v3/assert"
27
28
28
29
compose "github.com/docker/compose/v2/pkg/api"
29
- "github.com/docker/docker/api/types/filters"
30
30
)
31
31
32
32
func TestPs (t * testing.T ) {
@@ -42,10 +42,10 @@ func TestPs(t *testing.T) {
42
42
args := filters .NewArgs (projectFilter (strings .ToLower (testProject )), hasConfigHashLabel ())
43
43
args .Add ("label" , "com.docker.compose.oneoff=False" )
44
44
listOpts := containerType.ListOptions {Filters : args , All : false }
45
- c1 , inspect1 := containerDetails ("service1" , "123" , "running" , "healthy" , 0 )
46
- c2 , inspect2 := containerDetails ("service1" , "456" , "running" , "" , 0 )
45
+ c1 , inspect1 := containerDetails ("service1" , "123" , containerType . StateRunning , containerType . Healthy , 0 )
46
+ c2 , inspect2 := containerDetails ("service1" , "456" , containerType . StateRunning , "" , 0 )
47
47
c2 .Ports = []containerType.Port {{PublicPort : 80 , PrivatePort : 90 , IP : "localhost" }}
48
- c3 , inspect3 := containerDetails ("service2" , "789" , "exited" , "" , 130 )
48
+ c3 , inspect3 := containerDetails ("service2" , "789" , containerType . StateExited , "" , 130 )
49
49
api .EXPECT ().ContainerList (ctx , listOpts ).Return ([]containerType.Summary {c1 , c2 , c3 }, nil )
50
50
api .EXPECT ().ContainerInspect (anyCancellableContext (), "123" ).Return (inspect1 , nil )
51
51
api .EXPECT ().ContainerInspect (anyCancellableContext (), "456" ).Return (inspect2 , nil )
@@ -56,7 +56,9 @@ func TestPs(t *testing.T) {
56
56
expected := []compose.ContainerSummary {
57
57
{
58
58
ID : "123" , Name : "123" , Names : []string {"/123" }, Image : "foo" , Project : strings .ToLower (testProject ), Service : "service1" ,
59
- State : "running" , Health : "healthy" , Publishers : []compose.PortPublisher {},
59
+ State : containerType .StateRunning ,
60
+ Health : containerType .Healthy ,
61
+ Publishers : []compose.PortPublisher {},
60
62
Labels : map [string ]string {
61
63
compose .ProjectLabel : strings .ToLower (testProject ),
62
64
compose .ConfigFilesLabel : "/src/pkg/compose/testdata/compose.yaml" ,
@@ -66,7 +68,8 @@ func TestPs(t *testing.T) {
66
68
},
67
69
{
68
70
ID : "456" , Name : "456" , Names : []string {"/456" }, Image : "foo" , Project : strings .ToLower (testProject ), Service : "service1" ,
69
- State : "running" , Health : "" ,
71
+ State : containerType .StateRunning ,
72
+ Health : "" ,
70
73
Publishers : []compose.PortPublisher {{URL : "localhost" , TargetPort : 90 , PublishedPort : 80 }},
71
74
Labels : map [string ]string {
72
75
compose .ProjectLabel : strings .ToLower (testProject ),
@@ -77,7 +80,10 @@ func TestPs(t *testing.T) {
77
80
},
78
81
{
79
82
ID : "789" , Name : "789" , Names : []string {"/789" }, Image : "foo" , Project : strings .ToLower (testProject ), Service : "service2" ,
80
- State : "exited" , Health : "" , ExitCode : 130 , Publishers : []compose.PortPublisher {},
83
+ State : containerType .StateExited ,
84
+ Health : "" ,
85
+ ExitCode : 130 ,
86
+ Publishers : []compose.PortPublisher {},
81
87
Labels : map [string ]string {
82
88
compose .ProjectLabel : strings .ToLower (testProject ),
83
89
compose .ConfigFilesLabel : "/src/pkg/compose/testdata/compose.yaml" ,
@@ -90,8 +96,8 @@ func TestPs(t *testing.T) {
90
96
assert .DeepEqual (t , containers , expected )
91
97
}
92
98
93
- func containerDetails (service string , id string , status string , health string , exitCode int ) (containerType.Summary , containerType.InspectResponse ) {
94
- container := containerType.Summary {
99
+ func containerDetails (service string , id string , status containerType. ContainerState , health containerType. HealthStatus , exitCode int ) (containerType.Summary , containerType.InspectResponse ) {
100
+ ctr := containerType.Summary {
95
101
ID : id ,
96
102
Names : []string {"/" + id },
97
103
Image : "foo" ,
@@ -107,5 +113,5 @@ func containerDetails(service string, id string, status string, health string, e
107
113
},
108
114
},
109
115
}
110
- return container , inspect
116
+ return ctr , inspect
111
117
}
0 commit comments