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

Function TestLocalComposeVolume

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

Source from the content-addressed store, hash-verified

30)
31
32func TestLocalComposeVolume(t *testing.T) {
33 c := NewParallelCLI(t)
34
35 const projectName = "compose-e2e-volume"
36
37 t.Run("up with build and no image name, volume", func(t *testing.T) {
38 // ensure local test run does not reuse previously build image
39 c.RunDockerOrExitError(t, "rmi", "compose-e2e-volume-nginx")
40 c.RunDockerOrExitError(t, "volume", "rm", projectName+"-staticVol")
41 c.RunDockerOrExitError(t, "volume", "rm", "myvolume")
42 c.RunDockerComposeCmd(t, "--project-directory", "fixtures/volume-test", "--project-name", projectName, "up",
43 "-d")
44 })
45
46 t.Run("access bind mount data", func(t *testing.T) {
47 output := HTTPGetWithRetry(t, "http://localhost:8090", http.StatusOK, 2*time.Second, 20*time.Second)
48 assert.Assert(t, strings.Contains(output, "Hello from Nginx container"))
49 })
50
51 t.Run("check container volume specs", func(t *testing.T) {
52 res := c.RunDockerCmd(t, "inspect", "compose-e2e-volume-nginx2-1", "--format", "{{ json .Mounts }}")
53 output := res.Stdout()
54 assert.Assert(t, strings.Contains(output, `"Destination":"/usr/src/app/node_modules","Driver":"local","Mode":"z","RW":true,"Propagation":""`), output)
55 assert.Assert(t, strings.Contains(output, `"Destination":"/myconfig","Mode":"","RW":false,"Propagation":"rprivate"`), output)
56 })
57
58 t.Run("check config content", func(t *testing.T) {
59 output := c.RunDockerCmd(t, "exec", "compose-e2e-volume-nginx2-1", "cat", "/myconfig").Stdout()
60 assert.Assert(t, strings.Contains(output, `Hello from Nginx container`), output)
61 })
62
63 t.Run("check secrets content", func(t *testing.T) {
64 output := c.RunDockerCmd(t, "exec", "compose-e2e-volume-nginx2-1", "cat", "/run/secrets/mysecret").Stdout()
65 assert.Assert(t, strings.Contains(output, `Hello from Nginx container`), output)
66 })
67
68 t.Run("check container bind-mounts specs", func(t *testing.T) {
69 res := c.RunDockerCmd(t, "inspect", "compose-e2e-volume-nginx-1", "--format", "{{ json .Mounts }}")
70 output := res.Stdout()
71 assert.Assert(t, strings.Contains(output, `"Type":"bind"`))
72 assert.Assert(t, strings.Contains(output, `"Destination":"/usr/share/nginx/html"`))
73 })
74
75 t.Run("should inherit anonymous volumes", func(t *testing.T) {
76 c.RunDockerOrExitError(t, "exec", "compose-e2e-volume-nginx2-1", "touch", "/usr/src/app/node_modules/test")
77 c.RunDockerComposeCmd(t, "--project-directory", "fixtures/volume-test", "--project-name", projectName, "up", "--force-recreate", "-d")
78 c.RunDockerOrExitError(t, "exec", "compose-e2e-volume-nginx2-1", "ls", "/usr/src/app/node_modules/test")
79 })
80
81 t.Run("should renew anonymous volumes", func(t *testing.T) {
82 c.RunDockerOrExitError(t, "exec", "compose-e2e-volume-nginx2-1", "touch", "/usr/src/app/node_modules/test")
83 c.RunDockerComposeCmd(t, "--project-directory", "fixtures/volume-test", "--project-name", projectName, "up", "--force-recreate", "--renew-anon-volumes", "-d")
84 c.RunDockerOrExitError(t, "exec", "compose-e2e-volume-nginx2-1", "ls", "/usr/src/app/node_modules/test")
85 })
86
87 t.Run("cleanup volume project", func(t *testing.T) {
88 c.RunDockerComposeCmd(t, "--project-name", projectName, "down", "--volumes")
89 ls := c.RunDockerCmd(t, "volume", "ls").Stdout()

Callers

nothing calls this directly

Calls 5

NewParallelCLIFunction · 0.85
HTTPGetWithRetryFunction · 0.85
RunDockerOrExitErrorMethod · 0.80
RunDockerComposeCmdMethod · 0.80
RunDockerCmdMethod · 0.80

Tested by

no test coverage detected