Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make tests compatible with nerdctlv1.5 #75

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
17 changes: 12 additions & 5 deletions tests/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,27 @@ func Cp(o *option.Option) {
})

ginkgo.When("the container is not running", func() {
ginkgo.It("should not be able to copy file from host to container", func() {
command.Run(o, "run", "--name", testContainerName, defaultImage)
ginkgo.It("should be able to copy file from host to container", func() {
command.Run(o, "run", "--name", testContainerName, defaultImage, "sleep", "1")
command.Run(o, "stop", testContainerName)
path := ffs.CreateTempFile(filename, content)
ginkgo.DeferCleanup(os.RemoveAll, filepath.Dir(path))
command.RunWithoutSuccessfulExit(o, "cp", path, containerResource)
command.Run(o, "cp", path, containerResource)

// Need to run container to cat file, can't exec in stopped container.
// Start here will sleep 1s again so we can check file in container.
command.Run(o, "container", "start", testContainerName)
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