Files
cgofuse/fuse/host_test.go
T
Sirherobrine23 a1a726eb4d
Fuse test / go-test (push) Successful in 22s
Implement Lseek operation, and enhance error handling
- Update the FileSystemHost to remove functions SetCapCaseInsensitive, SetCapReaddirPlus, SetCapDeleteAccess, SetCapOpenTrunc, SetDirectIO, SetUseIno and expose CapCaseInsensitive, CapReaddirPlus, CapDeleteAccess, CapOpenTrunc, DirectIO, UseIno
- Added `FileSystemLseek` interface to support Lseek operation in FUSE.
- Implemented Lseek functionality in the host layer.
- Refactored error handling in `ErrorToStatus` to improve clarity and coverage.
- Enhanced `BasicStat` and `AppendDirEntry` functions to populate additional fields in the FUSE stat structure.
- Created utility functions for managing FUSE flags and permissions.
- fs:
  - Remove `Fd() uintptr` from base of File interface
  - Now fs use internal File Descriptor
  - Removed `FS() F` from `FileSystemMount[T, FileSystem[T]]`
- Unix fs:
  - Merge `_fuse` to `_FileSystemMount` and rename to FuseFs
  - Add new `FileSystemStatFst` to use direct fuse Statfs struct
  - Utimens don't return -ENOSYS if FileSystemUtimens not implemented
  - Add `Lseek` function

Signed-off-by: Matheus Sampaio Queiroga <srherobrine20@gmail.com>
2025-08-10 17:27:52 -03:00

113 lines
2.1 KiB
Go

//go:build cgo && (linux || darwin || freebsd || netbsd || openbsd)
package fuse
import (
"context"
"os"
"os/signal"
"path/filepath"
"syscall"
"testing"
)
type testfs struct {
FileSystemBase
t *testing.T
init, dstr int
}
func (selffs *testfs) Init() {
if selffs.t != nil {
selffs.t.Log("Init() called more than once")
}
selffs.init++
}
func (selffs *testfs) Destroy() {
if selffs.t != nil {
selffs.t.Log("Destroy() called more than once")
}
selffs.dstr++
}
func (selffs *testfs) Getattr(path string, stat *Stat_t, fh uint64) (errc int) {
if selffs.t != nil {
selffs.t.Logf("Getattr(%s)", path)
}
switch path {
case "/":
stat.Mode = uint32(S_IFDIR) | 0555
return 0
default:
return -ENOENT
}
}
func (selffs *testfs) Readdir(path string, fill StatFill, ofst int64, fh uint64) (errc int) {
if selffs.t != nil {
selffs.t.Logf("Readdir(%s)", path)
}
fill(".", nil, 0)
fill("..", nil, 0)
return 0
}
func (selffs *testfs) Readlink(path string) (int, string) {
if selffs.t != nil {
selffs.t.Logf("Readlink(%s)", path)
}
return 0, "/"
}
func testHost(t *testing.T, unmount bool) {
mntp := filepath.Join(t.TempDir(), "m")
if err := os.Mkdir(mntp, os.FileMode(0755)); err != nil {
panic(err)
}
ctx, done := context.WithCancel(t.Context())
defer done()
if !unmount {
var stop context.CancelFunc
ctx, stop = signal.NotifyContext(ctx, os.Interrupt, syscall.SIGTERM)
defer stop()
}
tstf := &testfs{t: t}
host := NewFileSystemHost(tstf)
mres := host.Mount(ctx, mntp)
_, _ = os.ReadDir(mntp)
_, _ = os.Stat(mntp)
_, _ = os.Readlink(mntp)
if unmount {
done()
} else {
syscall.Kill(syscall.Getpid(), syscall.SIGINT)
}
ures := host.Done()
if mres != nil {
t.Errorf("Mount failed: %s", mres)
}
if ures != nil {
t.Errorf("Unmount failed: %s", ures)
}
if tstf.init != 1 {
t.Errorf("Init() called %v times; expected 1", tstf.init)
}
if tstf.dstr != 1 {
t.Errorf("Destroy() called %v times; expected 1", tstf.dstr)
}
}
func TestUnmount(t *testing.T) {
testHost(t, true)
}
func TestSignal(t *testing.T) {
testHost(t, false)
}