Skip to content

Commit

Permalink
fix: make tests compatible with nerdctlv1.5
Browse files Browse the repository at this point in the history
nerdctl released v1.5 and we saw some test regressions in
runfinch/finch#521:

* compose container suffix changed
* cp now works with stopped containers
* nested bind mounts issue resolved

Signed-off-by: Gavin Inglis <[email protected]>
  • Loading branch information
ginglis13 committed Aug 8, 2023
1 parent 2755cb2 commit 775eaa4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 48 deletions.
2 changes: 1 addition & 1 deletion tests/compose_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
// ComposeBuild tests functionality of `compose build` command.
func ComposeBuild(o *option.Option) {
services := []string{"svc1_build_cmd", "svc2_build_cmd"}
imageSuffix := []string{"alpine:latest", "_svc2_build_cmd:latest"}
imageSuffix := []string{"alpine:latest", "-svc2_build_cmd:latest"}
ginkgo.Describe("Compose build command", func() {
var composeContext string
var composeFilePath string
Expand Down
9 changes: 6 additions & 3 deletions tests/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,23 @@ func Cp(o *option.Option) {
})

ginkgo.When("the container is not running", func() {
// TODO: not working either with Run or RunWithoutSuccessfulExit..
ginkgo.It("should not be able to copy file from host to container", func() {
command.Run(o, "run", "--name", testContainerName, defaultImage)
path := ffs.CreateTempFile(filename, content)
ginkgo.DeferCleanup(os.RemoveAll, filepath.Dir(path))
command.RunWithoutSuccessfulExit(o, "cp", path, containerResource)
command.Run(o, "cp", path, containerResource)
fileShouldExistInContainer(o, testContainerName, containerFilepath, content)
})

ginkgo.It("should not be able to copy file from container to host", func() {
ginkgo.It("should be able to copy file from container to host", func() {
cmd := fmt.Sprintf("echo -n %s > %s", content, containerFilepath)
command.Run(o, "run", "--name", testContainerName, defaultImage, "sh", "-c", cmd)
fileDir := ffs.CreateTempDir("finch-test")
path := filepath.Join(fileDir, filename)
ginkgo.DeferCleanup(os.RemoveAll, fileDir)
command.RunWithoutSuccessfulExit(o, "cp", containerResource, path)
command.Run(o, "cp", containerResource, path)
fileShouldExist(path, content)
})
})
})
Expand Down
45 changes: 1 addition & 44 deletions tests/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"
"github.com/runfinch/common-tests/fenv"

"github.com/runfinch/common-tests/command"
"github.com/runfinch/common-tests/ffs"
Expand Down Expand Up @@ -448,54 +447,12 @@ func Run(o *RunOption) {
verifyMountsInfo(actualMount, expectedMount)
})

// TODO: Remove FINCH_DOCKER_COMPAT=1 check when FINCH_DOCKER_COMPAT flag is removed in finch
ginkgo.It("should create nested bind mounts within a container when FINCH_DOCKER_COMPAT is not set", func() {
ginkgo.It("should create nested bind mounts within a container", func() {
const (
outerDir = "/outer"
nestedDir = "/outer/nested"
)

if fenv.GetEnv("FINCH_DOCKER_COMPAT") == "1" {
ginkgo.Skip("Skipping test: FINCH_DOCKER_COMPAT is set to 1")
}
// Create the nested directory on the host
hostDirectory := ffs.CreateNestedDir(outerDir)
nestedDirectory := ffs.CreateNestedDir(nestedDir)
defer ffs.DeleteDirectory(hostDirectory)

// Directory on host to be mounted at hostDirectory in container
tempDir := ffs.CreateTempDir("some_dir")
defer ffs.DeleteDirectory(tempDir)
// Write a file to the nested directory
nestedFilePath := filepath.Join(nestedDirectory, "file1.txt")
ffs.WriteFile(nestedFilePath, "test")

// Mount nested directory first followed by parent directory
// Upstream issue: https://github.com/containerd/nerdctl/issues/2254
command.RunWithoutSuccessfulExit(o.BaseOpt, "run", "--rm", "--name", testContainerName,
"-v", nestedDirectory+":"+nestedDirectory,
"-v", tempDir+":"+hostDirectory,
defaultImage, "sh", "-c", "ls "+nestedDirectory)

// Mount parent directory first followed by nested
output := command.StdoutStr(o.BaseOpt, "run", "--rm", "--name", testContainerName2,
"-v", tempDir+":"+hostDirectory,
"-v", nestedDirectory+":"+nestedDirectory,
defaultImage, "sh", "-c", "ls "+nestedDirectory)
gomega.Expect(output).Should(gomega.ContainSubstring("file1.txt"))
})

// TODO: Remove FINCH_DOCKER_COMPAT=1 check when FINCH_DOCKER_COMPAT flag is removed in finch
// https://github.com/runfinch/finch/pull/417/files

ginkgo.It("should create nested bind mounts within a container when FINCH_DOCKER_COMPAT is set", func() {
const (
outerDir = "/outer"
nestedDir = "/outer/nested"
)
if fenv.GetEnv("FINCH_DOCKER_COMPAT") != "1" {
ginkgo.Skip("Skipping test: FINCH_DOCKER_COMPAT is not set to 1")
}
// Create the nested directory on the host
hostDirectory := ffs.CreateNestedDir(outerDir)
nestedDirectory := ffs.CreateNestedDir(nestedDir)
Expand Down

0 comments on commit 775eaa4

Please sign in to comment.