Skip to content

Commit

Permalink
Fixing volume error failure for compose down
Browse files Browse the repository at this point in the history
Signed-off-by: Monirul Islam <[email protected]>
  • Loading branch information
monirul committed Apr 11, 2023
1 parent c18375a commit 9d9476f
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion tests/compose_down.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ package tests

import (
"fmt"
"os"
"regexp"

"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
"github.com/runfinch/common-tests/command"
"github.com/runfinch/common-tests/ffs"
"github.com/runfinch/common-tests/option"
"os"
)

// ComposeDown tests functionality of `compose down` command.
Expand All @@ -37,9 +39,33 @@ func ComposeDown(o *option.Option) {
containerShouldNotExist(o, containerNames...)
volumeShouldExist(o, "compose_data_volume")
})

for _, volumes := range []string{"-v", "--volumes"} {
volumes := volumes
ginkgo.It(fmt.Sprintf("should stop compose services and delete volumes by specifying %s flag", volumes), func() {
volumes := volumes
output := command.StdoutStr(o, "compose", "down", volumes, "--file", composeFilePath)
containerShouldNotExist(o, containerNames...)
if !isVolumeInUse(output) {
volumeShouldNotExist(o, "compose_data_volume")
}
})
}
})
}

// sometimes nerdctl fails to delete the volume due to concurrent usage of the volume by the container.
// For more details - https://github.com/runfinch/finch/issues/261
func isVolumeInUse(output string) bool {
if len(output) < 1 {
return false
}
// Error msg is generated from nerdctl volume rm cmd.
// see: https://github.com/containerd/nerdctl/blob/main/pkg/cmd/volume/rm.go#L52
re := regexp.MustCompile(`volume.*in use`)
return re.MatchString(output)
}

func createComposeYmlForDownCmd(serviceNames []string, containerNames []string) (string, string) {
gomega.Expect(serviceNames).Should(gomega.HaveLen(2))
gomega.Expect(containerNames).Should(gomega.HaveLen(2))
Expand Down

0 comments on commit 9d9476f

Please sign in to comment.