2016-02-29 05:34:31 +03:00
|
|
|
package fuse_test
|
|
|
|
|
|
|
|
import (
|
2018-02-07 18:12:44 +03:00
|
|
|
"context"
|
2016-02-29 05:34:31 +03:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2016-02-29 05:36:18 +03:00
|
|
|
"path"
|
|
|
|
"strings"
|
2016-02-29 05:34:31 +03:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/jacobsa/fuse"
|
2016-02-29 05:38:01 +03:00
|
|
|
"github.com/jacobsa/fuse/fuseops"
|
2016-02-29 05:34:31 +03:00
|
|
|
"github.com/jacobsa/fuse/fuseutil"
|
|
|
|
)
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// minimalFS
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// A minimal fuseutil.FileSystem that can successfully mount but do nothing
|
|
|
|
// else.
|
|
|
|
type minimalFS struct {
|
|
|
|
fuseutil.NotImplementedFileSystem
|
|
|
|
}
|
|
|
|
|
2016-02-29 05:38:01 +03:00
|
|
|
func (fs *minimalFS) StatFS(
|
|
|
|
ctx context.Context,
|
2020-01-28 12:10:08 +03:00
|
|
|
op *fuseops.StatFSOp) error {
|
|
|
|
return nil
|
2016-02-29 05:38:01 +03:00
|
|
|
}
|
|
|
|
|
2016-02-29 05:34:31 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Tests
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
func TestSuccessfulMount(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
// Set up a temporary directory.
|
|
|
|
dir, err := ioutil.TempDir("", "mount_test")
|
|
|
|
if err != nil {
|
2019-09-16 19:28:45 +03:00
|
|
|
t.Fatalf("ioutil.TempDir: %v", err)
|
2016-02-29 05:34:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
defer os.RemoveAll(dir)
|
|
|
|
|
|
|
|
// Mount.
|
|
|
|
fs := &minimalFS{}
|
|
|
|
mfs, err := fuse.Mount(
|
|
|
|
dir,
|
|
|
|
fuseutil.NewFileSystemServer(fs),
|
|
|
|
&fuse.MountConfig{})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("fuse.Mount: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
if err := mfs.Join(ctx); err != nil {
|
|
|
|
t.Errorf("Joining: %v", err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
defer fuse.Unmount(mfs.Dir())
|
|
|
|
}
|
|
|
|
|
2016-02-29 05:41:38 +03:00
|
|
|
func TestNonexistentMountPoint(t *testing.T) {
|
2016-02-29 05:40:11 +03:00
|
|
|
ctx := context.Background()
|
|
|
|
|
2016-02-29 05:36:18 +03:00
|
|
|
// Set up a temporary directory.
|
|
|
|
dir, err := ioutil.TempDir("", "mount_test")
|
|
|
|
if err != nil {
|
2019-09-16 19:28:45 +03:00
|
|
|
t.Fatalf("ioutil.TempDir: %v", err)
|
2016-02-29 05:36:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
defer os.RemoveAll(dir)
|
|
|
|
|
2016-02-29 05:41:38 +03:00
|
|
|
// Attempt to mount into a sub-directory that doesn't exist.
|
2016-02-29 05:36:18 +03:00
|
|
|
fs := &minimalFS{}
|
2016-02-29 05:40:11 +03:00
|
|
|
mfs, err := fuse.Mount(
|
2016-02-29 05:41:38 +03:00
|
|
|
path.Join(dir, "foo"),
|
2016-02-29 05:36:18 +03:00
|
|
|
fuseutil.NewFileSystemServer(fs),
|
|
|
|
&fuse.MountConfig{})
|
|
|
|
|
2016-02-29 05:40:11 +03:00
|
|
|
if err == nil {
|
|
|
|
fuse.Unmount(mfs.Dir())
|
|
|
|
mfs.Join(ctx)
|
|
|
|
t.Fatal("fuse.Mount returned nil")
|
|
|
|
}
|
|
|
|
|
2016-02-29 05:41:38 +03:00
|
|
|
const want = "no such file"
|
2016-02-29 05:40:11 +03:00
|
|
|
if got := err.Error(); !strings.Contains(got, want) {
|
|
|
|
t.Errorf("Unexpected error: %v", got)
|
2016-02-29 05:36:18 +03:00
|
|
|
}
|
2016-02-29 05:34:31 +03:00
|
|
|
}
|