-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
ev3dev_test.go
89 lines (75 loc) · 1.54 KB
/
ev3dev_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
89
// Copyright ©2016 The ev3go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package ev3dev_test
import (
"fmt"
"io"
"testing"
"time"
"bazil.org/fuse"
"github.com/ev3go/ev3dev"
"github.com/ev3go/sisyphus"
)
var (
epoch time.Time
clock func() time.Time
)
func init() {
loc, err := time.LoadLocation("Europe/Copenhagen")
if err != nil {
panic(err)
}
epoch = time.Date(2013, time.September, 1, 0, 0, 0, 0, loc)
clock = func() time.Time { return epoch }
}
var (
d = sisyphus.MustNewDir
ro = sisyphus.MustNewRO
rw = sisyphus.MustNewRW
wo = sisyphus.MustNewWO
)
func readAt(b []byte, offset int64, val interface{}) (int, error) {
if len(b) == 0 {
return 0, nil
}
s := fmt.Sprintln(val)
if offset >= int64(len(s)) {
return 0, io.EOF
}
n := copy(b, s[offset:])
if n < len(b) {
return n, io.EOF
}
return n, nil
}
func abs(i int) int {
if i < 0 {
return -i
}
return i
}
func size(val interface{}) int64 {
return int64(len(fmt.Sprintln(val)))
}
func chomp(b []byte) []byte {
if b[len(b)-1] == '\n' {
return b[:len(b)-1]
}
return b
}
func serve(fs *sisyphus.FileSystem, t *testing.T) (unmount func()) {
c, err := sisyphus.Serve(ev3dev.Prefix, fs, nil, fuse.AllowNonEmptyMount())
if err != nil {
t.Fatalf("failed to open server: %v", err)
}
return func() {
// Allow some time for the
// server to be ready to close.
time.Sleep(time.Second)
err = c.Close()
if err != nil {
t.Errorf("failed to close server: %v", err)
}
}
}