mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-10-24 06:50:40 +02:00
* fuse integration: add POSIX compliance test suite Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * ci: add posix-compliance workflow Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fuse integration: skip non-executable weed path candidates * fuse integration: size readv buffer to the written segment * fuse integration: reference posix_Makefile explicitly in recursive make calls GNU make does not propagate -f through MAKEFLAGS, so bare $(MAKE) re-read the default Makefile in this directory. * fuse integration: fail posix test targets when go test fails Every suite pipes go test through tee under /bin/sh, so the recipe status was tee's and test failures stayed green. Run recipes under bash -o pipefail and emit the color escapes with printf since bash echo does not expand them. * fuse integration: run only benchmarks in benchmark-posix go test -bench=. without -run also executes the whole suite, mixing compliance output into the benchmark log. * fuse integration: emit single-number test counts in reports grep -c prints 0 and exits nonzero when nothing matches, so '|| echo 0' produced two lines that broke the expr arithmetic and JSON fields. awk prints exactly one count either way. * fuse integration: skip the sendfile test on macOS macOS sendfile(2) only accepts a socket destination; the test copies into a regular file and always gets ENOTSOCK. * fuse integration: honor TestConfig and own only self-started resources NewFuseTestFramework dropped its config argument and Cleanup read a fresh DefaultTestConfig, so SkipCleanup never did anything. Cleanup also skipped teardown whenever TEST_SKIP_CLUSTER_SETUP was set, even when TEST_MOUNT_POINT was empty and Setup had started the cluster itself. The framework now keeps the config it was built with, runs external-mount tests inside a per-run work dir under the mount, and only skips teardown when an external mount was actually used. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fuse integration: pass the debug flag before the subcommand -v is a weed global flag; appended after master/volume/filer/mount it lands on the subcommand flagset, which rejects it and the process dies at flag parsing whenever EnableDebug is on. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fuse integration: require a real mount before running tests Setup creates the mount point before weed mount starts, so statting and listing it succeeded on the plain directory and tests ran against local disk whenever the mount was slow or died. waitForMount now waits until the mount point's device id differs from its parent's. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fuse integration: resolve the weed binary to an absolute path The started processes run with cmd.Dir at the framework's temp dir, so a relative candidate like ../weed no longer resolves. Prefer PATH, then probe the usual build outputs and return absolute paths only. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fuse integration: build the external test work dir with MkdirTemp The suite staged cloned tools and generated scripts under a predictable /tmp path another user could pre-create and swap mid-run. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fuse integration: use the pjdfstest tree setup-pjdfstest installs The test gated on a pjdfstest binary in PATH but then proved a suite it cloned itself, so a tree installed by make setup-pjdfstest was never found. Look for the built suite under external_tools first, then clone into the work dir as before. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * ci: require a real mount before posix tests The wait loop fell back to listing the mount point, which passes on the directory created before weed mount runs — a dead or slow mount meant the suite exercised local disk. Only mountpoint counts now, and a dead mount process fails fast instead of timing out. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * ci: collect failure logs before cleanup deletes them The always-on cleanup step removed /tmp/seaweedfs before the failure-only debug step could copy the service logs, so failed runs uploaded nothing. Run cleanup after log collection. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fuse integration: point MOUNT_POINT at TEST_MOUNT_POINT Targets that work against MOUNT_POINT (pjdfstest, nfstest, fio configs) ignored TEST_MOUNT_POINT and ran against the local-disk default while the go tests used the external mount. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fuse integration: skip the permission-denied check as root Root bypasses mode-bit checks, so writing the read-only file succeeded and the assertion failed in root-run environments like containers. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fuse integration: align the posix docs with the suite The doc listed a docker-test-posix target and make variables that do not exist, and ran go test against single files that cannot compile alone. The roadmap also still claimed the platform-specific tests this suite now implements were all skipped. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fuse integration: honor SkipCleanup in the mini-based framework too Same gap as the fuse-package framework: Cleanup read a fresh DefaultTestConfig, so a test's SkipCleanup setting was ignored. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fuse integration: normalize config in Setup and clean the work dir too Setup(nil) panicked on config.EnableDebug and external-mount Cleanup left the temp dir behind; use the stored config for the start* calls and remove tempDir alongside the external work dir. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * ci: point external posix suites at the workflow FUSE mount * fuse integration: create the fio target directory before running * fuse integration: use unix.O_DIRECT instead of a hard-coded x86 value 0x4000 is O_DIRECT only on x86 and amd64; on arm64 it is O_DIRECTORY. The test module already depends on golang.org/x/sys. * fuse integration: run autoreconf and configure before building pjdfstest A fresh pjdfstest clone is autotools-based and has no Makefile, so the Go-side setup fallback always failed and the suite silently skipped. * ci: require external posix tools only when setup installed them setup-external-tools always exits 0 because each sub-target tolerates failure, so POSIX_REQUIRE_EXTERNAL_TOOLS was set even with no tools installed and the suite then hard-failed on the missing suites. * ci: fail the posix workflow when the mount point is not a FUSE mount The file write/read check passes on the plain directory created before weed mount, so a dead mount let the whole suite grade the local disk. * fuse integration: skip when the host has no FUSE device node Setup failed the test outright on machines without /dev/fuse instead of skipping; cover every suite entry point by skipping inside Setup. * fuse integration: drop the chmod 666 /dev/fuse troubleshooting tip World-writable device access is a security risk; the fuse group membership on the line below is the safe fix. * fuse integration: require go 1.21+ in check-go, not 1.20+ * fuse integration: refuse external suites on an unmounted path * fuse integration: verify TEST_MOUNT_POINT is a real mount * fuse integration: clean TEST_MOUNT_POINT before the parent-device check filepath.Dir of a trailing-slash path returns the mount itself, so a mounted TEST_MOUNT_POINT ending in / was refused. * fuse integration: detect WinFsp mounts on Windows in mountedAt A directory mount is a reparse point and a drive mount is a volume root; a plain directory is now refused instead of accepted. * fuse integration: strip a trailing slash off MOUNT_POINT in require-mounted The mount-table grep fallback on hosts without mountpoint(8) would not match a slash-suffixed entry. * fuse integration: require an external mount to be a FUSE filesystem A device-ID boundary alone does not prove FUSE: a tmpfs mount would pass mountedAt and report its results as FUSE compliance. Check the filesystem type (statfs magic on linux, fstypename on the BSDs); platforms without a check keep the mount and write verification. --------- Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
497 lines
14 KiB
Go
497 lines
14 KiB
Go
package fuse
|
|
|
|
import (
|
|
"fmt"
|
|
"io/fs"
|
|
"net"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"syscall"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// FuseTestFramework provides utilities for FUSE integration testing
|
|
type FuseTestFramework struct {
|
|
t *testing.T
|
|
tempDir string
|
|
mountPoint string
|
|
dataDir string
|
|
masterProcess *os.Process
|
|
volumeProcess *os.Process
|
|
filerProcess *os.Process
|
|
mountProcess *os.Process
|
|
masterAddr string
|
|
volumeAddr string
|
|
filerAddr string
|
|
weedBinary string
|
|
isSetup bool
|
|
config *TestConfig
|
|
externalMount bool
|
|
}
|
|
|
|
// TestConfig holds configuration for FUSE tests
|
|
type TestConfig struct {
|
|
Collection string
|
|
Replication string
|
|
ChunkSizeMB int
|
|
CacheSizeMB int
|
|
NumVolumes int
|
|
EnableDebug bool
|
|
MountOptions []string
|
|
SkipCleanup bool // for debugging failed tests
|
|
}
|
|
|
|
// DefaultTestConfig returns a default configuration for FUSE tests
|
|
func DefaultTestConfig() *TestConfig {
|
|
return &TestConfig{
|
|
Collection: "",
|
|
Replication: "000",
|
|
ChunkSizeMB: 4,
|
|
CacheSizeMB: 100,
|
|
NumVolumes: 3,
|
|
EnableDebug: false,
|
|
MountOptions: []string{},
|
|
SkipCleanup: false,
|
|
}
|
|
}
|
|
|
|
// NewFuseTestFramework creates a new FUSE testing framework
|
|
func NewFuseTestFramework(t *testing.T, config *TestConfig) *FuseTestFramework {
|
|
if config == nil {
|
|
config = DefaultTestConfig()
|
|
}
|
|
|
|
tempDir, err := os.MkdirTemp("", "seaweedfs_fuse_test_")
|
|
require.NoError(t, err)
|
|
|
|
return &FuseTestFramework{
|
|
t: t,
|
|
tempDir: tempDir,
|
|
mountPoint: filepath.Join(tempDir, "mount"),
|
|
dataDir: filepath.Join(tempDir, "data"),
|
|
masterAddr: "127.0.0.1:19333",
|
|
volumeAddr: "127.0.0.1:18080",
|
|
filerAddr: "127.0.0.1:18888",
|
|
weedBinary: findWeedBinary(),
|
|
isSetup: false,
|
|
config: config,
|
|
}
|
|
}
|
|
|
|
// Setup starts SeaweedFS cluster and mounts FUSE filesystem
|
|
func (f *FuseTestFramework) Setup(config *TestConfig) error {
|
|
if f.isSetup {
|
|
return fmt.Errorf("framework already setup")
|
|
}
|
|
if config != nil {
|
|
f.config = config
|
|
}
|
|
config = f.config
|
|
|
|
// Check if we should skip cluster setup and use existing mount
|
|
if os.Getenv("TEST_SKIP_CLUSTER_SETUP") == "true" {
|
|
// Use existing mount point from environment
|
|
if existingMount := os.Getenv("TEST_MOUNT_POINT"); existingMount != "" {
|
|
f.externalMount = true
|
|
|
|
// Verify mount point is accessible
|
|
if _, err := os.Stat(existingMount); err != nil {
|
|
return fmt.Errorf("existing mount point not accessible: %v", err)
|
|
}
|
|
|
|
// A plain directory passes every check below; refuse to run the suite
|
|
// against the local disk
|
|
if !mountedAt(existingMount) {
|
|
return fmt.Errorf("mount point %s is not a mounted filesystem", existingMount)
|
|
}
|
|
// So can a non-FUSE mount like tmpfs: a device boundary alone does
|
|
// not make the results FUSE compliance
|
|
if !fuseFilesystem(existingMount) {
|
|
return fmt.Errorf("mount point %s is not a FUSE filesystem", existingMount)
|
|
}
|
|
|
|
// Run inside a private work dir so test files do not pile up in
|
|
// the shared mount root and cleanup can remove only what it made
|
|
workDir, err := os.MkdirTemp(existingMount, ".fuse_test_")
|
|
if err != nil {
|
|
return fmt.Errorf("creating work dir under existing mount: %v", err)
|
|
}
|
|
f.mountPoint = workDir
|
|
f.t.Logf("Using existing mount point: %s (work dir %s)", existingMount, f.mountPoint)
|
|
|
|
// Test basic functionality
|
|
testFile := filepath.Join(f.mountPoint, ".framework_test")
|
|
if err := os.WriteFile(testFile, []byte("test"), 0644); err != nil {
|
|
return fmt.Errorf("mount point not writable: %v", err)
|
|
}
|
|
if err := os.Remove(testFile); err != nil {
|
|
f.t.Logf("Warning: failed to cleanup test file: %v", err)
|
|
}
|
|
|
|
// Verify this is actually a SeaweedFS mount by checking for SeaweedFS-specific behavior
|
|
// Create a test file and verify it appears in the filer
|
|
verifyFile := filepath.Join(f.mountPoint, ".seaweedfs_mount_verification")
|
|
if err := os.WriteFile(verifyFile, []byte("SeaweedFS mount verification"), 0644); err != nil {
|
|
return fmt.Errorf("mount point verification failed - cannot write: %v", err)
|
|
}
|
|
|
|
// Read it back to ensure it's working
|
|
if data, err := os.ReadFile(verifyFile); err != nil {
|
|
return fmt.Errorf("mount point verification failed - cannot read: %v", err)
|
|
} else if string(data) != "SeaweedFS mount verification" {
|
|
return fmt.Errorf("mount point verification failed - data mismatch")
|
|
}
|
|
|
|
// Clean up verification file
|
|
if err := os.Remove(verifyFile); err != nil {
|
|
f.t.Logf("Warning: failed to cleanup verification file: %v", err)
|
|
}
|
|
|
|
f.t.Logf("✅ SeaweedFS mount point verified and working: %s", f.mountPoint)
|
|
|
|
f.isSetup = true
|
|
return nil
|
|
}
|
|
}
|
|
|
|
// Create directories for full cluster setup
|
|
dirs := []string{f.mountPoint, f.dataDir}
|
|
for _, dir := range dirs {
|
|
if err := os.MkdirAll(dir, 0755); err != nil {
|
|
return fmt.Errorf("failed to create directory %s: %v", dir, err)
|
|
}
|
|
}
|
|
|
|
// Start master
|
|
if err := f.startMaster(config); err != nil {
|
|
return fmt.Errorf("failed to start master: %v", err)
|
|
}
|
|
|
|
// Wait for master to be ready
|
|
if err := f.waitForService(f.masterAddr, 30*time.Second); err != nil {
|
|
return fmt.Errorf("master not ready: %v", err)
|
|
}
|
|
|
|
// Start volume servers
|
|
if err := f.startVolumeServers(config); err != nil {
|
|
return fmt.Errorf("failed to start volume servers: %v", err)
|
|
}
|
|
|
|
// Wait for volume server to be ready
|
|
if err := f.waitForService(f.volumeAddr, 30*time.Second); err != nil {
|
|
return fmt.Errorf("volume server not ready: %v", err)
|
|
}
|
|
|
|
// Start filer
|
|
if err := f.startFiler(config); err != nil {
|
|
return fmt.Errorf("failed to start filer: %v", err)
|
|
}
|
|
|
|
// Wait for filer to be ready
|
|
if err := f.waitForService(f.filerAddr, 30*time.Second); err != nil {
|
|
return fmt.Errorf("filer not ready: %v", err)
|
|
}
|
|
|
|
// Skip rather than fail on a host with no FUSE device to mount through
|
|
if !fuseAvailable() {
|
|
f.t.Skip("no FUSE device node (/dev/fuse, /dev/macfuse0, /dev/osxfuse0)")
|
|
}
|
|
|
|
// Mount FUSE filesystem
|
|
if err := f.mountFuse(config); err != nil {
|
|
return fmt.Errorf("failed to mount FUSE: %v", err)
|
|
}
|
|
|
|
// Wait for mount to be ready
|
|
if err := f.waitForMount(30 * time.Second); err != nil {
|
|
return fmt.Errorf("FUSE mount not ready: %v", err)
|
|
}
|
|
|
|
f.isSetup = true
|
|
return nil
|
|
}
|
|
|
|
// Cleanup stops all processes and removes temporary files
|
|
func (f *FuseTestFramework) Cleanup() {
|
|
// An external mount needs no teardown; only this run's work dir is ours.
|
|
// A TEST_SKIP_CLUSTER_SETUP that fell through to a self-started cluster
|
|
// still owns its processes and must not skip stopping them.
|
|
if f.externalMount {
|
|
if !f.config.SkipCleanup {
|
|
os.RemoveAll(f.mountPoint)
|
|
os.RemoveAll(f.tempDir)
|
|
}
|
|
return
|
|
}
|
|
|
|
if f.mountProcess != nil {
|
|
f.unmountFuse()
|
|
}
|
|
|
|
// Stop processes in reverse order
|
|
processes := []*os.Process{f.mountProcess, f.filerProcess, f.volumeProcess, f.masterProcess}
|
|
for _, proc := range processes {
|
|
if proc != nil {
|
|
proc.Signal(syscall.SIGTERM)
|
|
proc.Wait()
|
|
}
|
|
}
|
|
|
|
// Remove temp directory
|
|
if !f.config.SkipCleanup {
|
|
os.RemoveAll(f.tempDir)
|
|
}
|
|
}
|
|
|
|
// GetMountPoint returns the FUSE mount point path
|
|
func (f *FuseTestFramework) GetMountPoint() string {
|
|
return f.mountPoint
|
|
}
|
|
|
|
// GetFilerAddr returns the filer address
|
|
func (f *FuseTestFramework) GetFilerAddr() string {
|
|
return f.filerAddr
|
|
}
|
|
|
|
// startMaster starts the SeaweedFS master server
|
|
func (f *FuseTestFramework) startMaster(config *TestConfig) error {
|
|
var args []string
|
|
if config.EnableDebug {
|
|
// -v is a global flag; before the subcommand or flag parsing dies
|
|
args = append(args, "-v=4")
|
|
}
|
|
args = append(args,
|
|
"master",
|
|
"-ip=127.0.0.1",
|
|
"-port=19333",
|
|
"-mdir=" + filepath.Join(f.dataDir, "master"),
|
|
"-raftBootstrap",
|
|
)
|
|
|
|
cmd := exec.Command(f.weedBinary, args...)
|
|
cmd.Dir = f.tempDir
|
|
if err := cmd.Start(); err != nil {
|
|
return err
|
|
}
|
|
f.masterProcess = cmd.Process
|
|
return nil
|
|
}
|
|
|
|
// startVolumeServers starts SeaweedFS volume servers
|
|
func (f *FuseTestFramework) startVolumeServers(config *TestConfig) error {
|
|
var args []string
|
|
if config.EnableDebug {
|
|
args = append(args, "-v=4")
|
|
}
|
|
args = append(args,
|
|
"volume",
|
|
"-mserver=" + f.masterAddr,
|
|
"-ip=127.0.0.1",
|
|
"-port=18080",
|
|
"-dir=" + filepath.Join(f.dataDir, "volume"),
|
|
fmt.Sprintf("-max=%d", config.NumVolumes),
|
|
)
|
|
|
|
cmd := exec.Command(f.weedBinary, args...)
|
|
cmd.Dir = f.tempDir
|
|
if err := cmd.Start(); err != nil {
|
|
return err
|
|
}
|
|
f.volumeProcess = cmd.Process
|
|
return nil
|
|
}
|
|
|
|
// startFiler starts the SeaweedFS filer server
|
|
func (f *FuseTestFramework) startFiler(config *TestConfig) error {
|
|
var args []string
|
|
if config.EnableDebug {
|
|
args = append(args, "-v=4")
|
|
}
|
|
args = append(args,
|
|
"filer",
|
|
"-master=" + f.masterAddr,
|
|
"-ip=127.0.0.1",
|
|
"-port=18888",
|
|
)
|
|
|
|
cmd := exec.Command(f.weedBinary, args...)
|
|
cmd.Dir = f.tempDir
|
|
if err := cmd.Start(); err != nil {
|
|
return err
|
|
}
|
|
f.filerProcess = cmd.Process
|
|
return nil
|
|
}
|
|
|
|
// mountFuse mounts the SeaweedFS FUSE filesystem
|
|
func (f *FuseTestFramework) mountFuse(config *TestConfig) error {
|
|
var args []string
|
|
if config.EnableDebug {
|
|
args = append(args, "-v=4")
|
|
}
|
|
args = append(args,
|
|
"mount",
|
|
"-filer=" + f.filerAddr,
|
|
"-dir=" + f.mountPoint,
|
|
"-filer.path=/",
|
|
"-dirAutoCreate",
|
|
)
|
|
|
|
if config.Collection != "" {
|
|
args = append(args, "-collection="+config.Collection)
|
|
}
|
|
if config.Replication != "" {
|
|
args = append(args, "-replication="+config.Replication)
|
|
}
|
|
if config.ChunkSizeMB > 0 {
|
|
args = append(args, fmt.Sprintf("-chunkSizeLimitMB=%d", config.ChunkSizeMB))
|
|
}
|
|
if config.CacheSizeMB > 0 {
|
|
args = append(args, fmt.Sprintf("-cacheSizeMB=%d", config.CacheSizeMB))
|
|
}
|
|
|
|
args = append(args, config.MountOptions...)
|
|
|
|
cmd := exec.Command(f.weedBinary, args...)
|
|
cmd.Dir = f.tempDir
|
|
if err := cmd.Start(); err != nil {
|
|
return err
|
|
}
|
|
f.mountProcess = cmd.Process
|
|
return nil
|
|
}
|
|
|
|
// unmountFuse unmounts the FUSE filesystem
|
|
func (f *FuseTestFramework) unmountFuse() error {
|
|
if f.mountProcess != nil {
|
|
f.mountProcess.Signal(syscall.SIGTERM)
|
|
f.mountProcess.Wait()
|
|
f.mountProcess = nil
|
|
}
|
|
|
|
// Also try system unmount as backup
|
|
exec.Command("umount", f.mountPoint).Run()
|
|
return nil
|
|
}
|
|
|
|
// waitForService waits for a service to be available
|
|
func (f *FuseTestFramework) waitForService(addr string, timeout time.Duration) error {
|
|
deadline := time.Now().Add(timeout)
|
|
for time.Now().Before(deadline) {
|
|
conn, err := net.DialTimeout("tcp", addr, 1*time.Second)
|
|
if err == nil {
|
|
conn.Close()
|
|
return nil
|
|
}
|
|
time.Sleep(100 * time.Millisecond)
|
|
}
|
|
return fmt.Errorf("service at %s not ready within timeout", addr)
|
|
}
|
|
|
|
// waitForMount waits for the FUSE mount to be ready
|
|
func (f *FuseTestFramework) waitForMount(timeout time.Duration) error {
|
|
// The mount point is created before weed mount starts, so Stat/ReadDir
|
|
// alone succeed on the plain directory. The device id only differs from
|
|
// its parent's once a filesystem is actually mounted on it.
|
|
parentDev, err := deviceID(filepath.Dir(f.mountPoint))
|
|
if err != nil {
|
|
return fmt.Errorf("stat mount parent: %w", err)
|
|
}
|
|
deadline := time.Now().Add(timeout)
|
|
for time.Now().Before(deadline) {
|
|
if dev, err := deviceID(f.mountPoint); err == nil && dev != parentDev {
|
|
if _, err := os.ReadDir(f.mountPoint); err == nil {
|
|
return nil
|
|
}
|
|
}
|
|
time.Sleep(100 * time.Millisecond)
|
|
}
|
|
return fmt.Errorf("mount point not ready within timeout")
|
|
}
|
|
|
|
// fuseAvailable reports whether the host has a FUSE device node to mount
|
|
// through: /dev/fuse on Linux, /dev/macfuse* or /dev/osxfuse* on macOS.
|
|
func fuseAvailable() bool {
|
|
for _, dev := range []string{"/dev/fuse", "/dev/macfuse0", "/dev/osxfuse0"} {
|
|
if _, err := os.Stat(dev); err == nil {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// findWeedBinary locates the weed binary. Candidates are resolved to
|
|
// absolute paths because the started processes run with cmd.Dir set to the
|
|
// framework's temp dir, where a relative path would not resolve.
|
|
func findWeedBinary() string {
|
|
if p, err := exec.LookPath("weed"); err == nil {
|
|
return p
|
|
}
|
|
|
|
candidates := []string{
|
|
"../../weed/weed",
|
|
"./weed",
|
|
"../weed",
|
|
}
|
|
for _, candidate := range candidates {
|
|
if info, err := os.Stat(candidate); err == nil && !info.IsDir() && info.Mode()&0111 != 0 {
|
|
if abs, err := filepath.Abs(candidate); err == nil {
|
|
return abs
|
|
}
|
|
}
|
|
}
|
|
|
|
// Default fallback
|
|
return "weed"
|
|
}
|
|
|
|
// Helper functions for test assertions
|
|
|
|
// AssertFileExists checks if a file exists in the mount point
|
|
func (f *FuseTestFramework) AssertFileExists(relativePath string) {
|
|
fullPath := filepath.Join(f.mountPoint, relativePath)
|
|
_, err := os.Stat(fullPath)
|
|
require.NoError(f.t, err, "file should exist: %s", relativePath)
|
|
}
|
|
|
|
// AssertFileNotExists checks if a file does not exist in the mount point
|
|
func (f *FuseTestFramework) AssertFileNotExists(relativePath string) {
|
|
fullPath := filepath.Join(f.mountPoint, relativePath)
|
|
_, err := os.Stat(fullPath)
|
|
require.True(f.t, os.IsNotExist(err), "file should not exist: %s", relativePath)
|
|
}
|
|
|
|
// AssertFileContent checks if a file has expected content
|
|
func (f *FuseTestFramework) AssertFileContent(relativePath string, expectedContent []byte) {
|
|
fullPath := filepath.Join(f.mountPoint, relativePath)
|
|
actualContent, err := os.ReadFile(fullPath)
|
|
require.NoError(f.t, err, "failed to read file: %s", relativePath)
|
|
require.Equal(f.t, expectedContent, actualContent, "file content mismatch: %s", relativePath)
|
|
}
|
|
|
|
// AssertFileMode checks if a file has expected permissions
|
|
func (f *FuseTestFramework) AssertFileMode(relativePath string, expectedMode fs.FileMode) {
|
|
fullPath := filepath.Join(f.mountPoint, relativePath)
|
|
info, err := os.Stat(fullPath)
|
|
require.NoError(f.t, err, "failed to stat file: %s", relativePath)
|
|
require.Equal(f.t, expectedMode, info.Mode(), "file mode mismatch: %s", relativePath)
|
|
}
|
|
|
|
// CreateTestFile creates a test file with specified content
|
|
func (f *FuseTestFramework) CreateTestFile(relativePath string, content []byte) {
|
|
fullPath := filepath.Join(f.mountPoint, relativePath)
|
|
dir := filepath.Dir(fullPath)
|
|
require.NoError(f.t, os.MkdirAll(dir, 0755), "failed to create directory: %s", dir)
|
|
require.NoError(f.t, os.WriteFile(fullPath, content, 0644), "failed to create file: %s", relativePath)
|
|
}
|
|
|
|
// CreateTestDir creates a test directory
|
|
func (f *FuseTestFramework) CreateTestDir(relativePath string) {
|
|
fullPath := filepath.Join(f.mountPoint, relativePath)
|
|
require.NoError(f.t, os.MkdirAll(fullPath, 0755), "failed to create directory: %s", relativePath)
|
|
}
|