Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 9c615dc

Browse files
authored
Merge pull request #2025 from ulyssessouza/tolower-projectname-on-down
Lowercase project name for "compose down"
2 parents 32ae40f + 682c7d7 commit 9c615dc

File tree

6 files changed

+30
-20
lines changed

6 files changed

+30
-20
lines changed

pkg/compose/down.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type downOp func() error
3737

3838
func (s *composeService) Down(ctx context.Context, projectName string, options api.DownOptions) error {
3939
return progress.Run(ctx, func(ctx context.Context) error {
40-
return s.down(ctx, projectName, options)
40+
return s.down(ctx, strings.ToLower(projectName), options)
4141
})
4242
}
4343

pkg/compose/down_test.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package compose
1818

1919
import (
2020
"context"
21+
"strings"
2122
"testing"
2223

2324
compose "github.com/docker/compose-cli/pkg/api"
@@ -47,11 +48,12 @@ func TestDown(t *testing.T) {
4748
api.EXPECT().ContainerRemove(gomock.Any(), "456", moby.ContainerRemoveOptions{Force: true}).Return(nil)
4849
api.EXPECT().ContainerRemove(gomock.Any(), "789", moby.ContainerRemoveOptions{Force: true}).Return(nil)
4950

50-
api.EXPECT().NetworkList(gomock.Any(), moby.NetworkListOptions{Filters: filters.NewArgs(projectFilter(testProject))}).Return([]moby.NetworkResource{{ID: "myProject_default"}}, nil)
51+
api.EXPECT().NetworkList(gomock.Any(), moby.NetworkListOptions{Filters: filters.NewArgs(projectFilter(strings.ToLower(testProject)))}).Return([]moby.NetworkResource{{ID: "myProject_default"}},
52+
nil)
5153

5254
api.EXPECT().NetworkRemove(gomock.Any(), "myProject_default").Return(nil)
5355

54-
err := tested.Down(context.Background(), testProject, compose.DownOptions{})
56+
err := tested.Down(context.Background(), strings.ToLower(testProject), compose.DownOptions{})
5557
assert.NilError(t, err)
5658
}
5759

@@ -72,11 +74,12 @@ func TestDownRemoveOrphans(t *testing.T) {
7274
api.EXPECT().ContainerRemove(gomock.Any(), "789", moby.ContainerRemoveOptions{Force: true}).Return(nil)
7375
api.EXPECT().ContainerRemove(gomock.Any(), "321", moby.ContainerRemoveOptions{Force: true}).Return(nil)
7476

75-
api.EXPECT().NetworkList(gomock.Any(), moby.NetworkListOptions{Filters: filters.NewArgs(projectFilter(testProject))}).Return([]moby.NetworkResource{{ID: "myProject_default"}}, nil)
77+
api.EXPECT().NetworkList(gomock.Any(), moby.NetworkListOptions{Filters: filters.NewArgs(projectFilter(strings.ToLower(testProject)))}).Return([]moby.NetworkResource{{ID: "myProject_default"}},
78+
nil)
7679

7780
api.EXPECT().NetworkRemove(gomock.Any(), "myProject_default").Return(nil)
7881

79-
err := tested.Down(context.Background(), testProject, compose.DownOptions{RemoveOrphans: true})
82+
err := tested.Down(context.Background(), strings.ToLower(testProject), compose.DownOptions{RemoveOrphans: true})
8083
assert.NilError(t, err)
8184
}
8285

@@ -92,11 +95,11 @@ func TestDownRemoveVolumes(t *testing.T) {
9295
api.EXPECT().ContainerStop(gomock.Any(), "123", nil).Return(nil)
9396
api.EXPECT().ContainerRemove(gomock.Any(), "123", moby.ContainerRemoveOptions{Force: true, RemoveVolumes: true}).Return(nil)
9497

95-
api.EXPECT().NetworkList(gomock.Any(), moby.NetworkListOptions{Filters: filters.NewArgs(projectFilter(testProject))}).Return(nil, nil)
98+
api.EXPECT().NetworkList(gomock.Any(), moby.NetworkListOptions{Filters: filters.NewArgs(projectFilter(strings.ToLower(testProject)))}).Return(nil, nil)
9699

97-
api.EXPECT().VolumeList(gomock.Any(), filters.NewArgs(projectFilter(testProject))).Return(volume.VolumeListOKBody{Volumes: []*moby.Volume{{Name: "myProject_volume"}}}, nil)
100+
api.EXPECT().VolumeList(gomock.Any(), filters.NewArgs(projectFilter(strings.ToLower(testProject)))).Return(volume.VolumeListOKBody{Volumes: []*moby.Volume{{Name: "myProject_volume"}}}, nil)
98101
api.EXPECT().VolumeRemove(gomock.Any(), "myProject_volume", true).Return(nil)
99102

100-
err := tested.Down(context.Background(), testProject, compose.DownOptions{Volumes: true})
103+
err := tested.Down(context.Background(), strings.ToLower(testProject), compose.DownOptions{Volumes: true})
101104
assert.NilError(t, err)
102105
}

pkg/compose/kill_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package compose
1919
import (
2020
"context"
2121
"path/filepath"
22+
"strings"
2223
"testing"
2324

2425
"github.com/compose-spec/compose-go/types"
@@ -41,7 +42,7 @@ func TestKillAll(t *testing.T) {
4142
api := mocks.NewMockAPIClient(mockCtrl)
4243
tested.apiClient = api
4344

44-
project := types.Project{Name: testProject, Services: []types.ServiceConfig{testService("service1"), testService("service2")}}
45+
project := types.Project{Name: strings.ToLower(testProject), Services: []types.ServiceConfig{testService("service1"), testService("service2")}}
4546

4647
ctx := context.Background()
4748
api.EXPECT().ContainerList(ctx, projectFilterListOpt()).Return(
@@ -60,7 +61,7 @@ func TestKillSignal(t *testing.T) {
6061
api := mocks.NewMockAPIClient(mockCtrl)
6162
tested.apiClient = api
6263

63-
project := types.Project{Name: testProject, Services: []types.ServiceConfig{testService("service1")}}
64+
project := types.Project{Name: strings.ToLower(testProject), Services: []types.ServiceConfig{testService("service1")}}
6465

6566
ctx := context.Background()
6667
api.EXPECT().ContainerList(ctx, projectFilterListOpt()).Return([]moby.Container{testContainer("service1", "123")}, nil)
@@ -89,7 +90,7 @@ func containerLabels(service string) map[string]string {
8990
compose.ServiceLabel: service,
9091
compose.ConfigFilesLabel: composefile,
9192
compose.WorkingDirLabel: workingdir,
92-
compose.ProjectLabel: testProject}
93+
compose.ProjectLabel: strings.ToLower(testProject)}
9394
}
9495

9596
func anyCancellableContext() gomock.Matcher {
@@ -100,7 +101,7 @@ func anyCancellableContext() gomock.Matcher {
100101

101102
func projectFilterListOpt() moby.ContainerListOptions {
102103
return moby.ContainerListOptions{
103-
Filters: filters.NewArgs(projectFilter(testProject)),
104+
Filters: filters.NewArgs(projectFilter(strings.ToLower(testProject))),
104105
All: true,
105106
}
106107
}

pkg/compose/ps_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package compose
1818

1919
import (
2020
"context"
21+
"strings"
2122
"testing"
2223

2324
"github.com/golang/mock/gomock"
@@ -37,7 +38,7 @@ func TestPs(t *testing.T) {
3738
tested.apiClient = api
3839

3940
ctx := context.Background()
40-
args := filters.NewArgs(projectFilter(testProject))
41+
args := filters.NewArgs(projectFilter(strings.ToLower(testProject)))
4142
args.Add("label", "com.docker.compose.oneoff=False")
4243
listOpts := moby.ContainerListOptions{Filters: args, All: true}
4344
c1, inspect1 := containerDetails("service1", "123", "running", "healthy", 0)
@@ -49,12 +50,13 @@ func TestPs(t *testing.T) {
4950
api.EXPECT().ContainerInspect(anyCancellableContext(), "456").Return(inspect2, nil)
5051
api.EXPECT().ContainerInspect(anyCancellableContext(), "789").Return(inspect3, nil)
5152

52-
containers, err := tested.Ps(ctx, testProject, compose.PsOptions{})
53+
containers, err := tested.Ps(ctx, strings.ToLower(testProject), compose.PsOptions{})
5354

5455
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: "exited", Health: "", ExitCode: 130, Publishers: nil},
56+
{ID: "123", Name: "123", Project: strings.ToLower(testProject), Service: "service1", State: "running", Health: "healthy", Publishers: nil},
57+
{ID: "456", Name: "456", Project: strings.ToLower(testProject), Service: "service1", State: "running", Health: "", Publishers: []compose.PortPublisher{{URL: "localhost:80", TargetPort: 90,
58+
PublishedPort: 80}}},
59+
{ID: "789", Name: "789", Project: strings.ToLower(testProject), Service: "service2", State: "exited", Health: "", ExitCode: 130, Publishers: nil},
5860
}
5961
assert.NilError(t, err)
6062
assert.DeepEqual(t, containers, expected)

pkg/compose/stop_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package compose
1818

1919
import (
2020
"context"
21+
"strings"
2122
"testing"
2223
"time"
2324

@@ -50,7 +51,7 @@ func TestStopTimeout(t *testing.T) {
5051
api.EXPECT().ContainerStop(gomock.Any(), "789", &timeout).Return(nil)
5152

5253
err := tested.Stop(ctx, &types.Project{
53-
Name: testProject,
54+
Name: strings.ToLower(testProject),
5455
Services: []types.ServiceConfig{
5556
{Name: "service1"},
5657
{Name: "service2"},

pkg/e2e/compose_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ func TestLocalComposeUp(t *testing.T) {
6262
t.Run("top", func(t *testing.T) {
6363
res := c.RunDockerCmd("compose", "-p", projectName, "top")
6464
output := res.Stdout()
65-
assert.Assert(t, strings.Contains(output, `UID PID PPID C STIME TTY TIME CMD`), output)
65+
head := []string{"UID", "PID", "PPID", "C", "STIME", "TTY", "TIME", "CMD"}
66+
for _, h := range head {
67+
assert.Assert(t, strings.Contains(output, h), output)
68+
}
6669
assert.Assert(t, strings.Contains(output, `java -Xmx8m -Xms8m -jar /app/words.jar`), output)
6770
assert.Assert(t, strings.Contains(output, `/dispatcher`), output)
6871
})
@@ -139,7 +142,7 @@ func TestDownComposefileInParentFolder(t *testing.T) {
139142

140143
tmpFolder, err := ioutil.TempDir("fixtures/simple-composefile", "test-tmp")
141144
assert.NilError(t, err)
142-
defer os.Remove(tmpFolder) //nolint: errcheck
145+
defer os.Remove(tmpFolder) // nolint: errcheck
143146
projectName := filepath.Base(tmpFolder)
144147

145148
res := c.RunDockerCmd("compose", "--project-directory", tmpFolder, "up", "-d")

0 commit comments

Comments
 (0)