Skip to content

Commit f56aa95

Browse files
committed
one off container name use configured Separator for naming
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent fc4d2df commit f56aa95

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

pkg/compose/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (s *composeService) prepareRun(ctx context.Context, project *types.Project,
6262

6363
slug := stringid.GenerateRandomID()
6464
if service.ContainerName == "" {
65-
service.ContainerName = fmt.Sprintf("%s_%s_run_%s", project.Name, service.Name, stringid.TruncateID(slug))
65+
service.ContainerName = fmt.Sprintf("%[1]s%[4]s%[2]s%[4]srun%[4]s%[3]s", project.Name, service.Name, stringid.TruncateID(slug), api.Separator)
6666
}
6767
service.Scale = 1
6868
service.Restart = ""

pkg/e2e/compose_run_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ func TestLocalComposeRun(t *testing.T) {
4848
for _, line := range lines {
4949
fields := strings.Fields(line)
5050
containerID := fields[len(fields)-1]
51-
assert.Assert(t, !strings.HasPrefix(containerID, "run-test_front"))
52-
if strings.HasPrefix(containerID, "run-test_back") {
51+
assert.Assert(t, !strings.HasPrefix(containerID, "run-test-front"))
52+
if strings.HasPrefix(containerID, "run-test-back") {
5353
// only the one-off container for back service
54-
assert.Assert(t, strings.HasPrefix(containerID, "run-test_back_run_"), containerID)
55-
truncatedSlug = strings.Replace(containerID, "run-test_back_run_", "", 1)
54+
assert.Assert(t, strings.HasPrefix(containerID, "run-test-back-run-"), containerID)
55+
truncatedSlug = strings.Replace(containerID, "run-test-back-run-", "", 1)
5656
runContainerID = containerID
5757
}
5858
if strings.HasPrefix(containerID, "run-test-db-1") {
@@ -75,7 +75,7 @@ func TestLocalComposeRun(t *testing.T) {
7575
assert.Equal(t, lines[len(lines)-1], "Hello again", res.Stdout())
7676

7777
res = c.RunDockerCmd(t, "ps", "--all")
78-
assert.Assert(t, strings.Contains(res.Stdout(), "run-test_back"), res.Stdout())
78+
assert.Assert(t, strings.Contains(res.Stdout(), "run-test-back"), res.Stdout())
7979
})
8080

8181
t.Run("down", func(t *testing.T) {
@@ -92,7 +92,7 @@ func TestLocalComposeRun(t *testing.T) {
9292
res.Assert(t, icmd.Expected{Out: "compose_run_test.go"})
9393

9494
res = c.RunDockerCmd(t, "ps", "--all")
95-
assert.Assert(t, strings.Contains(res.Stdout(), "run-test_back"), res.Stdout())
95+
assert.Assert(t, strings.Contains(res.Stdout(), "run-test-back"), res.Stdout())
9696
})
9797

9898
t.Run("compose run --publish", func(t *testing.T) {

pkg/e2e/start_stop_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,31 +143,31 @@ func TestStartStopWithOneOffs(t *testing.T) {
143143
res := c.RunDockerComposeCmd(t, "--project-name", projectName, "ps", "-a")
144144
assert.Assert(t, strings.Contains(res.Combined(), "e2e-start-stop-with-oneoffs-foo-1"), res.Combined())
145145
assert.Assert(t, strings.Contains(res.Combined(), "e2e-start-stop-with-oneoffs-bar-1"), res.Combined())
146-
assert.Assert(t, strings.Contains(res.Combined(), "e2e-start-stop-with-oneoffs_bar_run"), res.Combined())
146+
assert.Assert(t, strings.Contains(res.Combined(), "e2e-start-stop-with-oneoffs-bar-run"), res.Combined())
147147
})
148148

149149
t.Run("stop (not one-off containers)", func(t *testing.T) {
150150
res := c.RunDockerComposeCmd(t, "--project-name", projectName, "stop")
151151
assert.Assert(t, strings.Contains(res.Combined(), "e2e-start-stop-with-oneoffs-foo-1"), res.Combined())
152152
assert.Assert(t, strings.Contains(res.Combined(), "e2e-start-stop-with-oneoffs-bar-1"), res.Combined())
153-
assert.Assert(t, !strings.Contains(res.Combined(), "e2e_start_stop_with_oneoffs_bar_run"), res.Combined())
153+
assert.Assert(t, !strings.Contains(res.Combined(), "e2e_start_stop_with_oneoffs-bar-run"), res.Combined())
154154

155155
res = c.RunDockerComposeCmd(t, "--project-name", projectName, "ps", "-a", "--status", "running")
156-
assert.Assert(t, strings.Contains(res.Combined(), "e2e-start-stop-with-oneoffs_bar_run"), res.Combined())
156+
assert.Assert(t, strings.Contains(res.Combined(), "e2e-start-stop-with-oneoffs-bar-run"), res.Combined())
157157
})
158158

159159
t.Run("start (not one-off containers)", func(t *testing.T) {
160160
res := c.RunDockerComposeCmd(t, "--project-name", projectName, "start")
161161
assert.Assert(t, strings.Contains(res.Combined(), "e2e-start-stop-with-oneoffs-foo-1"), res.Combined())
162162
assert.Assert(t, strings.Contains(res.Combined(), "e2e-start-stop-with-oneoffs-bar-1"), res.Combined())
163-
assert.Assert(t, !strings.Contains(res.Combined(), "e2e-start-stop-with-oneoffs_bar_run"), res.Combined())
163+
assert.Assert(t, !strings.Contains(res.Combined(), "e2e-start-stop-with-oneoffs-bar-run"), res.Combined())
164164
})
165165

166166
t.Run("restart (not one-off containers)", func(t *testing.T) {
167167
res := c.RunDockerComposeCmd(t, "--project-name", projectName, "restart")
168168
assert.Assert(t, strings.Contains(res.Combined(), "e2e-start-stop-with-oneoffs-foo-1"), res.Combined())
169169
assert.Assert(t, strings.Contains(res.Combined(), "e2e-start-stop-with-oneoffs-bar-1"), res.Combined())
170-
assert.Assert(t, !strings.Contains(res.Combined(), "e2e-start-stop-with-oneoffs_bar_run"), res.Combined())
170+
assert.Assert(t, !strings.Contains(res.Combined(), "e2e-start-stop-with-oneoffs-bar-run"), res.Combined())
171171
})
172172

173173
t.Run("down", func(t *testing.T) {

0 commit comments

Comments
 (0)