rclone/cmd/nfsmount/nfsmount_test.go
Nick Craig-Wood 205667143c
Some checks failed
build / linux_386 (push) Has been cancelled
Build & Push Docker Images / Build Docker Image for linux/386 (push) Has been cancelled
Build & Push Docker Images / Build Docker Image for linux/amd64 (push) Has been cancelled
Build & Push Docker Images / Build Docker Image for linux/arm/v6 (push) Has been cancelled
Build & Push Docker Images / Build Docker Image for linux/arm/v7 (push) Has been cancelled
build / windows (push) Has been cancelled
build / other_os (push) Has been cancelled
build / mac_amd64 (push) Has been cancelled
build / mac_arm64 (push) Has been cancelled
build / linux (push) Has been cancelled
build / go1.23 (push) Has been cancelled
build / lint (push) Has been cancelled
build / android-all (push) Has been cancelled
Build & Push Docker Images / Build Docker Image for linux/arm64 (push) Has been cancelled
Build & Push Docker Images / Merge & Push Final Docker Image (push) Has been cancelled
serve nfs: make metadata files have special file handles
Metadata files have the file handle of their source file with
0x00000001 suffixed in big endian so we can look them up directly from
their file handles.
2025-04-07 13:41:29 +01:00

59 lines
1.8 KiB
Go

//go:build unix
package nfsmount
import (
"context"
"errors"
"os"
"os/exec"
"runtime"
"testing"
"github.com/rclone/rclone/cmd/serve/nfs"
"github.com/rclone/rclone/fs/object"
"github.com/rclone/rclone/vfs"
"github.com/rclone/rclone/vfs/vfscommon"
"github.com/rclone/rclone/vfs/vfstest"
"github.com/stretchr/testify/require"
)
// Return true if the command ran without error
func commandOK(name string, arg ...string) bool {
cmd := exec.Command(name, arg...)
_, err := cmd.CombinedOutput()
return err == nil
}
func TestMount(t *testing.T) {
if runtime.GOOS != "darwin" {
if !commandOK("sudo", "-n", "mount", "--help") {
t.Skip("Can't run sudo mount without a password")
}
if !commandOK("sudo", "-n", "umount", "--help") {
t.Skip("Can't run sudo umount without a password")
}
sudo = true
}
for _, cacheType := range []string{"memory", "disk", "symlink"} {
t.Run(cacheType, func(t *testing.T) {
nfs.Opt.HandleCacheDir = t.TempDir()
require.NoError(t, nfs.Opt.HandleCache.Set(cacheType))
// Check we can create a handler
_, err := nfs.NewHandler(context.Background(), vfs.New(object.MemoryFs, nil), &nfs.Opt)
if errors.Is(err, nfs.ErrorSymlinkCacheNotSupported) || errors.Is(err, nfs.ErrorSymlinkCacheNoPermission) {
t.Skip(err.Error() + ": run with: go test -c && sudo setcap cap_dac_read_search+ep ./nfsmount.test && ./nfsmount.test -test.v")
}
require.NoError(t, err)
// Configure rclone via environment var since the mount gets run in a subprocess
_ = os.Setenv("RCLONE_NFS_CACHE_DIR", nfs.Opt.HandleCacheDir)
_ = os.Setenv("RCLONE_NFS_CACHE_TYPE", cacheType)
t.Cleanup(func() {
_ = os.Unsetenv("RCLONE_NFS_CACHE_DIR")
_ = os.Unsetenv("RCLONE_NFS_CACHE_TYPE")
})
vfstest.RunTests(t, false, vfscommon.CacheModeWrites, false, mount)
})
}
}