Skip to content

Commit

Permalink
Add e2e test
Browse files Browse the repository at this point in the history
Signed-off-by: Joana Hrotko <[email protected]>
  • Loading branch information
jhrotko committed Oct 25, 2024
1 parent dd9944b commit 5b8a8b0
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/e2e/fixtures/recreate-volumes/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
app:
image: alpine
volumes:
- my_vol:/my_vol

volumes:
my_vol:
12 changes: 12 additions & 0 deletions pkg/e2e/fixtures/recreate-volumes/compose2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
services:
app:
image: alpine
volumes:
- my_vol:/my_vol

volumes:
my_vol:
driver_opts:
type: none
device: "/Users/joanahrotko/workspace/issues/volume-change-recreate/smt"
o: bind
31 changes: 31 additions & 0 deletions pkg/e2e/up_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,34 @@ func TestUpWithAllResources(t *testing.T) {
assert.Assert(t, strings.Contains(res.Combined(), fmt.Sprintf(`Volume "%s_my_vol" Created`, projectName)), res.Combined())
assert.Assert(t, strings.Contains(res.Combined(), fmt.Sprintf(`Network %s_my_net Created`, projectName)), res.Combined())
}

func TestUpRecreateVolumes(t *testing.T) {
c := NewCLI(t)
const projectName = "compose-e2e-recreate-volumes"
t.Cleanup(func() {
c.RunDockerComposeCmd(t, "--project-name", projectName, "down", "-v")
})

res := c.RunDockerComposeCmd(t, "-f", "./fixtures/recreate-volumes/compose.yaml", "--project-name", projectName, "up")
assert.NilError(t, res.Error)
assert.Assert(t, strings.Contains(res.Combined(), fmt.Sprintf(`Volume "%s_my_vol" Created`, projectName)), res.Combined())

// If there are no changes it does not recreate volume
res = c.RunDockerComposeCmd(t, "-f", "./fixtures/recreate-volumes/compose.yaml", "--project-name", projectName, "up", "--recreate-volumes")
assert.NilError(t, res.Error)
assert.Assert(t, strings.Contains(res.Combined(), fmt.Sprintf(`Container %s-app-1 Recreated`, projectName)), res.Combined())
assert.Assert(t, !strings.Contains(res.Combined(), fmt.Sprintf(`Volume "%s_my_vol"`, projectName)), res.Combined())

// If there are no changes it does not recreate volume
res = c.RunDockerComposeCmd(t, "-f", "./fixtures/recreate-volumes/compose2.yaml", "--project-name", projectName, "up", "--recreate-volumes")
assert.NilError(t, res.Error)

// removes the affected container
assert.Assert(t, strings.Contains(res.Combined(), fmt.Sprintf(`Container %s-app-1 Stopped`, projectName)), res.Combined())
assert.Assert(t, strings.Contains(res.Combined(), fmt.Sprintf(`Container %s-app-1 Removed`, projectName)), res.Combined())
// recreates the changed volume
assert.Assert(t, strings.Contains(res.Combined(), fmt.Sprintf(`Volume %s_my_vol Removed`, projectName)), res.Combined())
assert.Assert(t, strings.Contains(res.Combined(), fmt.Sprintf(`Volume "%s_my_vol" Created`, projectName)), res.Combined())
// starts the container
assert.Assert(t, strings.Contains(res.Combined(), fmt.Sprintf(`Container %s-app-1 Created`, projectName)), res.Combined())
}

0 comments on commit 5b8a8b0

Please sign in to comment.