From 446008a4b601283cdaf06b22f68bf4e2dfcf5ff7 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Tue, 8 Dec 2020 14:38:21 +0100 Subject: [PATCH] on ACI container ID is `project_service` and name is `service` Signed-off-by: Nicolas De Loof --- aci/compose.go | 5 +- cli/cmd/compose/ps.go | 4 +- ecs/sdk.go | 2 +- local/compose/compose_test.go | 143 ---------------------------------- local/compose/create_test.go | 25 +++++- tests/aci-e2e/e2e-aci_test.go | 13 ++-- tests/ecs-e2e/e2e-ecs_test.go | 2 +- 7 files changed, 38 insertions(+), 156 deletions(-) delete mode 100644 local/compose/compose_test.go diff --git a/aci/compose.go b/aci/compose.go index 5fe89e62f..03bbbb895 100644 --- a/aci/compose.go +++ b/aci/compose.go @@ -150,9 +150,10 @@ func (cs *aciComposeService) Ps(ctx context.Context, project string) ([]compose. Protocol: string(p.Protocol), }) } + id := getContainerID(group, container) res = append(res, compose.ContainerSummary{ - ID: *container.Name, - Name: *container.Name, + ID: id, + Name: id, Project: project, Service: *container.Name, State: convert.GetStatus(container, group), diff --git a/cli/cmd/compose/ps.go b/cli/cmd/compose/ps.go index e9ffe2951..b7b5ffed7 100644 --- a/cli/cmd/compose/ps.go +++ b/cli/cmd/compose/ps.go @@ -80,8 +80,8 @@ func runPs(ctx context.Context, opts composeOptions) error { ports = append(ports, fmt.Sprintf("%s->%d/%s", p.URL, p.TargetPort, p.Protocol)) } } - _, _ = fmt.Fprintf(w, "%s\t%s\t%s\n", container.Name, container.State, strings.Join(ports, ", ")) + _, _ = fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", container.Name, container.Service, container.State, strings.Join(ports, ", ")) } }, - "NAME", "STATE", "PORTS") + "NAME", "SERVICE", "STATE", "PORTS") } diff --git a/ecs/sdk.go b/ecs/sdk.go index e9b7abacc..b44ecbfab 100644 --- a/ecs/sdk.go +++ b/ecs/sdk.go @@ -869,7 +869,7 @@ func (s sdk) DescribeServiceTasks(ctx context.Context, cluster string, project s Name: id.Resource, Project: project, Service: service, - State: aws.StringValue(t.LastStatus), + State: strings.Title(strings.ToLower(aws.StringValue(t.LastStatus))), }) } diff --git a/local/compose/compose_test.go b/local/compose/compose_test.go deleted file mode 100644 index 6aa295558..000000000 --- a/local/compose/compose_test.go +++ /dev/null @@ -1,143 +0,0 @@ -/* - Copyright 2020 Docker Compose CLI authors - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package compose - -import ( - "path/filepath" - "testing" - - composetypes "github.com/compose-spec/compose-go/types" - "github.com/docker/docker/api/types" - mountTypes "github.com/docker/docker/api/types/mount" - "gotest.tools/v3/assert" - - "github.com/docker/compose-cli/api/compose" -) - -func TestContainersToStacks(t *testing.T) { - containers := []types.Container{ - { - ID: "service1", - State: "running", - Labels: map[string]string{projectLabel: "project1"}, - }, - { - ID: "service2", - State: "running", - Labels: map[string]string{projectLabel: "project1"}, - }, - { - ID: "service3", - State: "running", - Labels: map[string]string{projectLabel: "project2"}, - }, - } - stacks, err := containersToStacks(containers) - assert.NilError(t, err) - assert.DeepEqual(t, stacks, []compose.Stack{ - { - ID: "project1", - Name: "project1", - Status: "running(2)", - }, - { - ID: "project2", - Name: "project2", - Status: "running(1)", - }, - }) -} - -func TestContainersToServiceStatus(t *testing.T) { - containers := []types.Container{ - { - ID: "c1", - State: "running", - Labels: map[string]string{serviceLabel: "service1"}, - }, - { - ID: "c2", - State: "exited", - Labels: map[string]string{serviceLabel: "service1"}, - }, - { - ID: "c3", - State: "running", - Labels: map[string]string{serviceLabel: "service1"}, - }, - { - ID: "c4", - State: "running", - Labels: map[string]string{serviceLabel: "service2"}, - }, - } - services, err := containersToServiceStatus(containers) - assert.NilError(t, err) - assert.DeepEqual(t, services, []compose.ServiceStatus{ - { - ID: "service1", - Name: "service1", - Replicas: 2, - Desired: 3, - }, - { - ID: "service2", - Name: "service2", - Replicas: 1, - Desired: 1, - }, - }) -} - -func TestStacksMixedStatus(t *testing.T) { - assert.Equal(t, combinedStatus([]string{"running"}), "running(1)") - assert.Equal(t, combinedStatus([]string{"running", "running", "running"}), "running(3)") - assert.Equal(t, combinedStatus([]string{"running", "exited", "running"}), "exited(1), running(2)") -} - -func TestBuildBindMount(t *testing.T) { - project := composetypes.Project{} - volume := composetypes.ServiceVolumeConfig{ - Type: composetypes.VolumeTypeBind, - Source: "e2e/volume-test", - Target: "/data", - } - mount, err := buildMount(project, volume) - assert.NilError(t, err) - assert.Assert(t, filepath.IsAbs(mount.Source)) - assert.Equal(t, mount.Type, mountTypes.TypeBind) -} - -func TestBuildVolumeMount(t *testing.T) { - project := composetypes.Project{ - Name: "myProject", - Volumes: composetypes.Volumes(map[string]composetypes.VolumeConfig{ - "myVolume": { - Name: "myProject_myVolume", - }, - }), - } - volume := composetypes.ServiceVolumeConfig{ - Type: composetypes.VolumeTypeVolume, - Source: "myVolume", - Target: "/data", - } - mount, err := buildMount(project, volume) - assert.NilError(t, err) - assert.Equal(t, mount.Source, "myProject_myVolume") - assert.Equal(t, mount.Type, mountTypes.TypeVolume) -} diff --git a/local/compose/create_test.go b/local/compose/create_test.go index 2ae4254e6..fa1b3681e 100644 --- a/local/compose/create_test.go +++ b/local/compose/create_test.go @@ -27,15 +27,36 @@ import ( ) func TestBuildBindMount(t *testing.T) { + project := composetypes.Project{} volume := composetypes.ServiceVolumeConfig{ Type: composetypes.VolumeTypeBind, - Source: "e2e/volume-test", + Source: "", Target: "/data", } - mount, err := buildMount(volume) + mount, err := buildMount(project, volume) assert.NilError(t, err) assert.Assert(t, filepath.IsAbs(mount.Source)) _, err = os.Stat(mount.Source) assert.NilError(t, err) assert.Equal(t, mount.Type, mountTypes.TypeBind) } + +func TestBuildVolumeMount(t *testing.T) { + project := composetypes.Project{ + Name: "myProject", + Volumes: composetypes.Volumes(map[string]composetypes.VolumeConfig{ + "myVolume": { + Name: "myProject_myVolume", + }, + }), + } + volume := composetypes.ServiceVolumeConfig{ + Type: composetypes.VolumeTypeVolume, + Source: "myVolume", + Target: "/data", + } + mount, err := buildMount(project, volume) + assert.NilError(t, err) + assert.Equal(t, mount.Source, "myProject_myVolume") + assert.Equal(t, mount.Type, mountTypes.TypeVolume) +} diff --git a/tests/aci-e2e/e2e-aci_test.go b/tests/aci-e2e/e2e-aci_test.go index ee0702d6d..edc2b3cef 100644 --- a/tests/aci-e2e/e2e-aci_test.go +++ b/tests/aci-e2e/e2e-aci_test.go @@ -734,20 +734,23 @@ func TestUpUpdate(t *testing.T) { var wordsDisplayed, webDisplayed, dbDisplayed bool for _, line := range l { fields := strings.Fields(line) - containerID := fields[0] - switch containerID { + name := fields[0] + switch name { case wordsContainer: wordsDisplayed = true - assert.DeepEqual(t, fields, []string{containerID, "words", "Running"}) + assert.Equal(t, fields[2], "Running") case dbContainer: dbDisplayed = true - assert.DeepEqual(t, fields, []string{containerID, "db", "Running"}) + assert.Equal(t, fields[2], "Running") case serverContainer: webDisplayed = true - assert.Equal(t, fields[1], "web") + assert.Equal(t, fields[2], "Running") assert.Check(t, strings.Contains(fields[3], ":80->80/tcp")) } } + assert.Check(t, webDisplayed, "webDisplayed"+res.Stdout()) + assert.Check(t, wordsDisplayed, "wordsDisplayed"+res.Stdout()) + assert.Check(t, dbDisplayed, "dbDisplayed"+res.Stdout()) assert.Check(t, webDisplayed && wordsDisplayed && dbDisplayed, "\n%s\n", res.Stdout()) }) diff --git a/tests/ecs-e2e/e2e-ecs_test.go b/tests/ecs-e2e/e2e-ecs_test.go index 6c04823f9..9a8e8880a 100644 --- a/tests/ecs-e2e/e2e-ecs_test.go +++ b/tests/ecs-e2e/e2e-ecs_test.go @@ -100,7 +100,7 @@ func TestCompose(t *testing.T) { switch serviceName { case "db": dbDisplayed = true - assert.DeepEqual(t, fields, []string{containerID, serviceName, "1/1"}) + assert.DeepEqual(t, fields, []string{containerID, serviceName, "Running"}) case "words": wordsDisplayed = true assert.Check(t, strings.Contains(fields[3], ":8080->8080/tcp"))