Skip to content

Commit ebb45b4

Browse files
committed
e2e: unmarshal json into container summaries
Signed-off-by: Nick Sieger <[email protected]>
1 parent c83133f commit ebb45b4

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

pkg/e2e/ps_test.go

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import (
2222
"testing"
2323

2424
"github.com/stretchr/testify/assert"
25+
26+
"github.com/docker/compose/v2/pkg/api"
2527
)
2628

2729
func TestPs(t *testing.T) {
@@ -57,37 +59,34 @@ func TestPs(t *testing.T) {
5759

5860
t.Run("json", func(t *testing.T) {
5961
res = c.RunDockerComposeCmd("-f", "./fixtures/ps-test/compose.yaml", "--project-name", projectName, "ps", "--format", "json")
60-
var output []map[string]interface{}
62+
var output []api.ContainerSummary
6163
err := json.Unmarshal([]byte(res.Combined()), &output)
6264
assert.NoError(t, err)
6365

6466
count := 0
6567
assert.Equal(t, 2, len(output))
6668
for _, service := range output {
67-
publishers := service["Publishers"].([]interface{})
68-
if service["Name"] == "e2e-ps-busybox-1" {
69+
publishers := service.Publishers
70+
if service.Name == "e2e-ps-busybox-1" {
6971
assert.Equal(t, 1, len(publishers))
70-
publisher := publishers[0].(map[string]interface{})
71-
assert.Equal(t, "127.0.0.1", publisher["URL"])
72-
assert.Equal(t, 8000.0, publisher["TargetPort"])
73-
assert.Equal(t, 8001.0, publisher["PublishedPort"])
74-
assert.Equal(t, "tcp", publisher["Protocol"])
72+
assert.Equal(t, api.PortPublishers{
73+
{
74+
URL: "127.0.0.1",
75+
TargetPort: 8000,
76+
PublishedPort: 8001,
77+
Protocol: "tcp",
78+
},
79+
}, publishers)
7580
count++
7681
}
77-
if service["Name"] == "e2e-ps-nginx-1" {
82+
if service.Name == "e2e-ps-nginx-1" {
7883
assert.Equal(t, 3, len(publishers))
79-
publisher := publishers[0].(map[string]interface{})
80-
assert.Equal(t, 80.0, publisher["TargetPort"])
81-
assert.Equal(t, 0.0, publisher["PublishedPort"])
82-
assert.Equal(t, "tcp", publisher["Protocol"])
83-
publisher = publishers[1].(map[string]interface{})
84-
assert.Equal(t, 443.0, publisher["TargetPort"])
85-
assert.Equal(t, 0.0, publisher["PublishedPort"])
86-
assert.Equal(t, "tcp", publisher["Protocol"])
87-
publisher = publishers[2].(map[string]interface{})
88-
assert.Equal(t, 8080.0, publisher["TargetPort"])
89-
assert.Equal(t, 0.0, publisher["PublishedPort"])
90-
assert.Equal(t, "tcp", publisher["Protocol"])
84+
assert.Equal(t, api.PortPublishers{
85+
{TargetPort: 80, Protocol: "tcp"},
86+
{TargetPort: 443, Protocol: "tcp"},
87+
{TargetPort: 8080, Protocol: "tcp"},
88+
}, publishers)
89+
9190
count++
9291
}
9392
}

0 commit comments

Comments
 (0)