MCPcopy
hub / github.com/docker/compose / TestImageVolumeRecreateOnRebuild

Function TestImageVolumeRecreateOnRebuild

pkg/e2e/volumes_test.go:194–236  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

192}
193
194func TestImageVolumeRecreateOnRebuild(t *testing.T) {
195 c := NewCLI(t)
196 const projectName = "compose-e2e-image-volume-recreate"
197 t.Cleanup(func() {
198 c.cleanupWithDown(t, projectName)
199 c.RunDockerOrExitError(t, "rmi", "-f", "image-volume-source")
200 })
201
202 version := c.RunDockerCmd(t, "version", "-f", "{{.Server.Version}}")
203 major, _, found := strings.Cut(version.Combined(), ".")
204 assert.Assert(t, found)
205 if major == "26" || major == "27" {
206 t.Skip("Skipping test due to docker version < 28")
207 }
208
209 // First build and run with initial content
210 c.RunDockerComposeCmd(t, "-f", "./fixtures/image-volume-recreate/compose.yaml",
211 "--project-name", projectName, "build", "--build-arg", "CONTENT=foo")
212 res := c.RunDockerComposeCmd(t, "-f", "./fixtures/image-volume-recreate/compose.yaml",
213 "--project-name", projectName, "up", "-d")
214 assert.Check(t, !strings.Contains(res.Combined(), "error"))
215
216 // Check initial content
217 res = c.RunDockerComposeCmd(t, "-f", "./fixtures/image-volume-recreate/compose.yaml",
218 "--project-name", projectName, "logs", "consumer")
219 assert.Check(t, strings.Contains(res.Combined(), "foo"), "Expected 'foo' in output, got: %s", res.Combined())
220
221 // Rebuild source image with different content
222 c.RunDockerComposeCmd(t, "-f", "./fixtures/image-volume-recreate/compose.yaml",
223 "--project-name", projectName, "build", "--build-arg", "CONTENT=bar")
224
225 // Run up again - consumer should be recreated because source image changed
226 res = c.RunDockerComposeCmd(t, "-f", "./fixtures/image-volume-recreate/compose.yaml",
227 "--project-name", projectName, "up", "-d")
228 // The consumer container should be recreated
229 assert.Check(t, strings.Contains(res.Combined(), "Recreate") || strings.Contains(res.Combined(), "Created"),
230 "Expected container to be recreated, got: %s", res.Combined())
231
232 // Check updated content
233 res = c.RunDockerComposeCmd(t, "-f", "./fixtures/image-volume-recreate/compose.yaml",
234 "--project-name", projectName, "logs", "consumer")
235 assert.Check(t, strings.Contains(res.Combined(), "bar"), "Expected 'bar' in output after rebuild, got: %s", res.Combined())
236}

Callers

nothing calls this directly

Calls 5

cleanupWithDownMethod · 0.95
RunDockerOrExitErrorMethod · 0.95
RunDockerCmdMethod · 0.95
RunDockerComposeCmdMethod · 0.95
NewCLIFunction · 0.85

Tested by

no test coverage detected