mirror of
https://github.com/rclone/rclone.git
synced 2026-07-09 23:35:06 -04:00
vfs/vfstest: add Mknod test exercising all three mount backends
Mknod is now implemented by mount, mount2 and cmount, so exercise it from the shared vfstest suite: create a regular file (S_IFREG) through the mounted path and check it reads back as a 0-byte regular file. This is the path the kernel NFS server drives when a client creates a file over an exported mount. Before this there was no shared coverage for Mknod; it now runs against each backend via RunTests. Suggested in #9548. Signed-off-by: Sandy Luppino <s.luppino@opendrives.com>
This commit is contained in:
committed by
Nick Craig-Wood
parent
22aba81074
commit
c1b5756eec
@@ -107,6 +107,7 @@ func RunTests(t *testing.T, useVFS bool, minimumRequiredCacheMode vfscommon.Cach
|
||||
t.Run("TestWriteFileDup", TestWriteFileDup)
|
||||
t.Run("TestWriteFileAppend", TestWriteFileAppend)
|
||||
t.Run("TestSymlinks", TestSymlinks)
|
||||
t.Run("TestMknod", TestMknod)
|
||||
})
|
||||
fs.Logf(nil, "Finished test run with %s (ok=%v)", what, ok)
|
||||
run.Finalise()
|
||||
|
||||
13
vfs/vfstest/mknod_other.go
Normal file
13
vfs/vfstest/mknod_other.go
Normal file
@@ -0,0 +1,13 @@
|
||||
//go:build !linux && !darwin && !freebsd && !openbsd
|
||||
|
||||
package vfstest
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestMknod is not supported on this platform.
|
||||
func TestMknod(t *testing.T) {
|
||||
t.Skip("not supported on " + runtime.GOOS)
|
||||
}
|
||||
42
vfs/vfstest/mknod_unix.go
Normal file
42
vfs/vfstest/mknod_unix.go
Normal file
@@ -0,0 +1,42 @@
|
||||
//go:build linux || darwin || freebsd || openbsd
|
||||
|
||||
package vfstest
|
||||
|
||||
import (
|
||||
"os"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// TestMknod checks that Mknod creates a regular file through the mount.
|
||||
//
|
||||
// The VFS only supports regular files (S_IFREG) - this is the path the
|
||||
// kernel NFS server drives when a client creates a file over an exported
|
||||
// mount (device nodes are rejected). All three mount backends (mount,
|
||||
// mount2, cmount) implement Mknod, so this runs against each via RunTests.
|
||||
func TestMknod(t *testing.T) {
|
||||
run.skipIfVFS(t) // Mknod is a mount syscall; no Mknod on the direct-VFS pass
|
||||
run.skipIfNoFUSE(t)
|
||||
if runtime.GOOS == "darwin" {
|
||||
t.Skip("Skipping test on OSX") // macFUSE Mknod support is unreliable
|
||||
}
|
||||
|
||||
const name = "testmknod"
|
||||
path := run.path(name)
|
||||
|
||||
// S_IFREG => regular file; dev 0 since it is not a device node.
|
||||
err := unix.Mknod(path, unix.S_IFREG|0640, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
fi, err := os.Stat(path)
|
||||
require.NoError(t, err)
|
||||
assert.Truef(t, fi.Mode().IsRegular(), "expected a regular file, got mode %v", fi.Mode())
|
||||
assert.Equal(t, int64(0), fi.Size())
|
||||
|
||||
run.waitForWriters()
|
||||
run.rm(t, name)
|
||||
}
|
||||
Reference in New Issue
Block a user