forked from keybase/kbfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_fuse_test.go
88 lines (76 loc) · 2.2 KB
/
run_fuse_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright 2016 Keybase Inc. All rights reserved.
// Use of this source code is governed by a BSD
// license that can be found in the LICENSE file.
// +build fuse
package test
import (
"testing"
"time"
"bazil.org/fuse"
"bazil.org/fuse/fs"
"bazil.org/fuse/fs/fstestutil"
"github.com/keybase/client/go/logger"
"github.com/keybase/kbfs/libfuse"
"github.com/keybase/kbfs/libkbfs"
"golang.org/x/net/context"
)
type fuseEngine struct {
fsEngine
}
func createEngine(tb testing.TB) Engine {
log := logger.NewTestLogger(tb)
debugLog := log.CloneWithAddedDepth(1)
fuse.Debug = libfuse.MakeFuseDebugFn(debugLog, false /* superVerbose */)
return &fuseEngine{
fsEngine: fsEngine{
name: "fuse",
tb: tb,
createUser: createUserFuse,
},
}
}
func createUserFuse(tb testing.TB, ith int, config *libkbfs.ConfigLocal,
opTimeout time.Duration) *fsUser {
filesys := libfuse.NewFS(config, nil, false, libfuse.PlatformParams{})
fn := func(mnt *fstestutil.Mount) fs.FS {
filesys.SetFuseConn(mnt.Server, mnt.Conn)
return filesys
}
options := libfuse.GetPlatformSpecificMountOptionsForTest()
mnt, err := fstestutil.MountedFuncT(tb, fn, &fs.Config{
WithContext: func(ctx context.Context, req fuse.Request) context.Context {
if int(opTimeout) > 0 {
// Safe to ignore cancel since fuse should clean up the parent
ctx, _ = context.WithTimeout(ctx, opTimeout)
}
ctx = filesys.WithContext(ctx)
return ctx
},
}, options...)
if err != nil {
tb.Fatal(err)
}
tb.Logf("FUSE HasInvalidate=%v", mnt.Conn.Protocol().HasInvalidate())
ctx := context.Background()
session, err := config.KBPKI().GetCurrentSession(ctx)
if err != nil {
tb.Fatal(err)
}
ctx, cancelFn := context.WithCancel(ctx)
ctx = filesys.WithContext(ctx)
logTags := logger.CtxLogTags{
CtxUserKey: CtxOpUser,
}
ctx = logger.NewContextWithLogTags(ctx, logTags)
ctx = context.WithValue(ctx, CtxUserKey, session.Name)
// the fsUser.cancel will cancel notification processing; the FUSE
// serve loop is terminated by unmounting the filesystem
filesys.LaunchNotificationProcessor(ctx)
return &fsUser{
mntDir: mnt.Dir,
username: session.Name,
config: config,
cancel: cancelFn,
close: mnt.Close,
}
}