mirror of
https://github.com/docker/compose.git
synced 2025-07-16 18:24:26 +02:00
e2e: unmarshal json into container summaries
Signed-off-by: Nick Sieger <nick@nicksieger.com>
This commit is contained in:
parent
c83133f73b
commit
ebb45b400c
@ -22,6 +22,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/docker/compose/v2/pkg/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPs(t *testing.T) {
|
func TestPs(t *testing.T) {
|
||||||
@ -57,37 +59,34 @@ func TestPs(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("json", func(t *testing.T) {
|
t.Run("json", func(t *testing.T) {
|
||||||
res = c.RunDockerComposeCmd("-f", "./fixtures/ps-test/compose.yaml", "--project-name", projectName, "ps", "--format", "json")
|
res = c.RunDockerComposeCmd("-f", "./fixtures/ps-test/compose.yaml", "--project-name", projectName, "ps", "--format", "json")
|
||||||
var output []map[string]interface{}
|
var output []api.ContainerSummary
|
||||||
err := json.Unmarshal([]byte(res.Combined()), &output)
|
err := json.Unmarshal([]byte(res.Combined()), &output)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
count := 0
|
count := 0
|
||||||
assert.Equal(t, 2, len(output))
|
assert.Equal(t, 2, len(output))
|
||||||
for _, service := range output {
|
for _, service := range output {
|
||||||
publishers := service["Publishers"].([]interface{})
|
publishers := service.Publishers
|
||||||
if service["Name"] == "e2e-ps-busybox-1" {
|
if service.Name == "e2e-ps-busybox-1" {
|
||||||
assert.Equal(t, 1, len(publishers))
|
assert.Equal(t, 1, len(publishers))
|
||||||
publisher := publishers[0].(map[string]interface{})
|
assert.Equal(t, api.PortPublishers{
|
||||||
assert.Equal(t, "127.0.0.1", publisher["URL"])
|
{
|
||||||
assert.Equal(t, 8000.0, publisher["TargetPort"])
|
URL: "127.0.0.1",
|
||||||
assert.Equal(t, 8001.0, publisher["PublishedPort"])
|
TargetPort: 8000,
|
||||||
assert.Equal(t, "tcp", publisher["Protocol"])
|
PublishedPort: 8001,
|
||||||
|
Protocol: "tcp",
|
||||||
|
},
|
||||||
|
}, publishers)
|
||||||
count++
|
count++
|
||||||
}
|
}
|
||||||
if service["Name"] == "e2e-ps-nginx-1" {
|
if service.Name == "e2e-ps-nginx-1" {
|
||||||
assert.Equal(t, 3, len(publishers))
|
assert.Equal(t, 3, len(publishers))
|
||||||
publisher := publishers[0].(map[string]interface{})
|
assert.Equal(t, api.PortPublishers{
|
||||||
assert.Equal(t, 80.0, publisher["TargetPort"])
|
{TargetPort: 80, Protocol: "tcp"},
|
||||||
assert.Equal(t, 0.0, publisher["PublishedPort"])
|
{TargetPort: 443, Protocol: "tcp"},
|
||||||
assert.Equal(t, "tcp", publisher["Protocol"])
|
{TargetPort: 8080, Protocol: "tcp"},
|
||||||
publisher = publishers[1].(map[string]interface{})
|
}, publishers)
|
||||||
assert.Equal(t, 443.0, publisher["TargetPort"])
|
|
||||||
assert.Equal(t, 0.0, publisher["PublishedPort"])
|
|
||||||
assert.Equal(t, "tcp", publisher["Protocol"])
|
|
||||||
publisher = publishers[2].(map[string]interface{})
|
|
||||||
assert.Equal(t, 8080.0, publisher["TargetPort"])
|
|
||||||
assert.Equal(t, 0.0, publisher["PublishedPort"])
|
|
||||||
assert.Equal(t, "tcp", publisher["Protocol"])
|
|
||||||
count++
|
count++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user