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

feat: Tests for bind mounts #66

Merged
merged 4 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 17 additions & 0 deletions ffs/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,20 @@ func CreateTempDir(directoryPrefix string) string {
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
return tempDir
}

// CreateNestedDir creates a nested directory and returns the path of the created directory.
// It is the caller's responsibility to remove the directory when it is no longer needed.
func CreateNestedDir(dirPath string) string {
homeDir, err := os.UserHomeDir()
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
fullPath := filepath.Join(homeDir, dirPath)
err = os.MkdirAll(fullPath, 0o740)
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
return fullPath
}

// DeleteDirectory deletes the directory including nested directories.
func DeleteDirectory(directoryPath string) {
err := os.RemoveAll(directoryPath)
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
}
34 changes: 34 additions & 0 deletions tests/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,40 @@ func Run(o *RunOption) {
verifyMountsInfo(actualMount, expectedMount)
})

ginkgo.It("should create nested bind mounts within a container", func() {
const (
outerDir = "/outer"
nestedDir = "/outer/nested"
)

// 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
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"))

// Test with env variable
})

ginkgo.It("should create a tmpfs mount using --mount type=tmpfs flag", func() {
tmpfsDir := "/tmpfsDir"
command.Run(o.BaseOpt, "run", "-d", "--name", testContainerName, "--mount",
Expand Down