Skip to content

Commit a20b69a

Browse files
committed
e2e test for recreate volume
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 977530c commit a20b69a

File tree

5 files changed

+45
-8
lines changed

5 files changed

+45
-8
lines changed

pkg/e2e/fixtures/recreate-volumes/compose.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ services:
66

77
volumes:
88
my_vol:
9-
external: true
10-
name: test_external_volume
9+
labels:
10+
foo: bar

pkg/e2e/fixtures/recreate-volumes/compose2.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ services:
66

77
volumes:
88
my_vol:
9-
external: true
10-
name: test_external_volume_2
9+
labels:
10+
foo: zot
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
services:
2+
app:
3+
image: alpine
4+
volumes:
5+
- my_vol:/my_vol
6+
7+
volumes:
8+
my_vol:
9+
external: true
10+
name: test_external_volume
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
services:
2+
app:
3+
image: alpine
4+
volumes:
5+
- my_vol:/my_vol
6+
7+
volumes:
8+
my_vol:
9+
external: true
10+
name: test_external_volume_2

pkg/e2e/volumes_test.go

+21-4
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ func TestProjectVolumeBind(t *testing.T) {
123123
})
124124
}
125125

126-
func TestUpRecreateVolumes(t *testing.T) {
126+
func TestUpSwitchVolumes(t *testing.T) {
127127
c := NewCLI(t)
128-
const projectName = "compose-e2e-recreate-volumes"
128+
const projectName = "compose-e2e-switch-volumes"
129129
t.Cleanup(func() {
130130
c.cleanupWithDown(t, projectName)
131131
c.RunDockerCmd(t, "volume", "rm", "-f", "test_external_volume")
@@ -135,12 +135,29 @@ func TestUpRecreateVolumes(t *testing.T) {
135135
c.RunDockerCmd(t, "volume", "create", "test_external_volume")
136136
c.RunDockerCmd(t, "volume", "create", "test_external_volume_2")
137137

138-
c.RunDockerComposeCmd(t, "-f", "./fixtures/recreate-volumes/compose.yaml", "--project-name", projectName, "up", "-d")
138+
c.RunDockerComposeCmd(t, "-f", "./fixtures/switch-volumes/compose.yaml", "--project-name", projectName, "up", "-d")
139139

140140
res := c.RunDockerCmd(t, "inspect", fmt.Sprintf("%s-app-1", projectName), "-f", "{{ (index .Mounts 0).Name }}")
141141
res.Assert(t, icmd.Expected{Out: "test_external_volume"})
142142

143-
c.RunDockerComposeCmd(t, "-f", "./fixtures/recreate-volumes/compose2.yaml", "--project-name", projectName, "up", "-d")
143+
c.RunDockerComposeCmd(t, "-f", "./fixtures/switch-volumes/compose2.yaml", "--project-name", projectName, "up", "-d")
144144
res = c.RunDockerCmd(t, "inspect", fmt.Sprintf("%s-app-1", projectName), "-f", "{{ (index .Mounts 0).Name }}")
145145
res.Assert(t, icmd.Expected{Out: "test_external_volume_2"})
146146
}
147+
148+
func TestUpRecreateVolumes(t *testing.T) {
149+
c := NewCLI(t)
150+
const projectName = "compose-e2e-recreate-volumes"
151+
t.Cleanup(func() {
152+
c.cleanupWithDown(t, projectName)
153+
})
154+
155+
c.RunDockerComposeCmd(t, "-f", "./fixtures/recreate-volumes/compose.yaml", "--project-name", projectName, "up", "-d")
156+
157+
res := c.RunDockerCmd(t, "volume", "inspect", fmt.Sprintf("%s_my_vol", projectName), "-f", "{{ index .Labels \"foo\" }}")
158+
res.Assert(t, icmd.Expected{Out: "bar"})
159+
160+
c.RunDockerComposeCmd(t, "-f", "./fixtures/recreate-volumes/compose2.yaml", "--project-name", projectName, "up", "-d", "-y")
161+
res = c.RunDockerCmd(t, "volume", "inspect", fmt.Sprintf("%s_my_vol", projectName), "-f", "{{ index .Labels \"foo\" }}")
162+
res.Assert(t, icmd.Expected{Out: "zot"})
163+
}

0 commit comments

Comments
 (0)