Files
overlayfs/overlayfs_linux_test.go
Matheus Sampaio Queiroga 87f8824bf8
Some checks are pending
Golang test / go-test (freebsd-latest) (push) Waiting to run
Golang test / go-test (windows-latest) (push) Waiting to run
Golang test / go-test (ubuntu-latest) (push) Successful in 12s
rename files
Signed-off-by: Matheus Sampaio Queiroga <srherobrine20@gmail.com>
2025-07-06 23:53:15 -03:00

48 lines
1.1 KiB
Go

//go:build linux
package overlayfs
import (
"os"
"path/filepath"
"testing"
)
func TestLinuxOverlayfs(t *testing.T) {
targetPath := filepath.Join(t.TempDir(), "target")
overlayMount := &Overlayfs{
Target: targetPath,
Upper: filepath.Join(t.TempDir(), "up"),
Workdir: filepath.Join(t.TempDir(), "work"),
Lower: []string{
filepath.Join(t.TempDir(), "low1"),
filepath.Join(t.TempDir(), "low2"),
filepath.Join(t.TempDir(), "low3"),
filepath.Join(t.TempDir(), "low4"),
},
}
for _, folderPath := range append(overlayMount.Lower, overlayMount.Target, overlayMount.Upper, overlayMount.Workdir) {
if err := os.Mkdir(folderPath, 0777); err != nil {
t.Skipf("skiping, cannot make folders: %q", err.Error())
return
}
}
err := overlayMount.Mount()
if err != nil {
t.Errorf("cannot mount overlayfs, run with unshare or root user: %s", err)
return // Stop test
}
if err = overlayMount.Unmount(); err != nil {
t.Errorf("unmount overlayfs: %q", err.Error())
return
}
if err = overlayMount.Unmount(); err != nil {
t.Errorf("second unmount overlayfs: %q", err.Error())
return
}
}