-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathraw_test.go
More file actions
102 lines (85 loc) · 1.82 KB
/
raw_test.go
File metadata and controls
102 lines (85 loc) · 1.82 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package fuse
import (
"context"
"fmt"
"os"
"os/signal"
"testing"
"time"
)
type loggy struct {
prefix string
}
func (l loggy) Printf(format string, args ...interface{}) {
_, _ = fmt.Printf(l.prefix+format+"\n", args...)
}
func setup(fs Filesystem, target string) (func() <-chan error, error) {
srv := &Server{
Options: Options{
ErrorLog: loggy{prefix: "== error: ",},
DebugLog: loggy{prefix: " - debug: ",},
},
}
if err := srv.Serve(fs, target); err != nil {
return nil, err
}
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt)
done := make(chan struct{}, 1)
errc := make(chan error, 1)
go func() {
ctx := context.Background()
var cancel func()
select {
case <-sig:
ctx, cancel = context.WithCancel(ctx)
cancel()
case <-done:
ctx, cancel = context.WithTimeout(ctx, time.Second)
defer cancel()
}
errc <- srv.Shutdown(ctx)
}()
shutdown := func() <-chan error {
close(done)
return errc
}
return shutdown, nil
}
func LoggingMiddleware(h HandlerFunc) HandlerFunc {
return func(ctx *Context, req Request, resp Response) error {
return h(ctx, req, resp)
}
}
func TestBasic(t *testing.T) {
handler := func(ctx *Context, req Request, resp Response) error {
switch req.(type) {
case *InitIn:
return nil
// case *LookupIn:
// return ENOENT
default:
fmt.Println("RESPONDING ENOSYS to", ctx)
return ENOSYS
}
}
// attach logger
handler = LoggingMiddleware(handler)
shutdown, err := setup(HandlerFunc(handler), "/tmp/mount")
assert(t, err)
defer func() { _ = <-shutdown() }()
/*
f, err := os.Open("/tmp/mount/")
assert(t, err)
names, err := f.Readdirnames(0)
assert(t, err)
fmt.Println("READDIR NAMES: ", names)
*/
time.Sleep(10 * time.Second)
t.Fail()
}
func assert(t *testing.T, err error) {
if err != nil {
t.Errorf("%v", err)
}
}