-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit_test.go
70 lines (61 loc) · 1.39 KB
/
init_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
package tests
import (
"os"
"path/filepath"
"testing"
"time"
"github.com/ckeyer/tarofs/pkgs/fs"
"github.com/ckeyer/tarofs/pkgs/storage/levelfs"
"github.com/stretchr/testify/suite"
)
func TestSuite(t *testing.T) {
batch := time.Now().Format("0102T150405")
as := &AppSuite{
Suite: new(suite.Suite),
leveldir: filepath.Join(os.TempDir(), batch, "leveldb"),
rootDir: filepath.Join(os.TempDir(), batch, "taro"),
}
suite.Run(t, as)
}
// SetupSuite setup
func (a *AppSuite) SetupSuite() {
for _, path := range []string{a.leveldir, a.rootDir} {
if err := os.MkdirAll(path, 0755); err != nil {
a.Failf("SetupSuite Failed", "mkdir %s failed, %s", path, err)
return
}
}
stgr, err := levelfs.NewLevelStorage(a.leveldir)
if err != nil {
a.Fail("new levelfs storage failed, %s", err)
return
}
a.fs, err = fs.NewFS(a.rootDir, stgr, stgr)
if err != nil {
a.Fail("new mount falied, %s", err)
return
}
go func() {
if err := a.fs.Serve(); err != nil {
a.Fail("start file system serve failed, ", err)
}
}()
time.Sleep(time.Second)
go func() {
select {
case <-time.Tick(time.Second * 30):
a.FailNow("timeout. TearDownSuite")
os.Exit(1)
}
}()
a.T().Logf("root dir: %s", a.rootDir)
a.T().Log("start testing.")
}
// TearDownSuite tear down
func (a *AppSuite) TearDownSuite() {
if a.fs != nil {
a.fs.Close()
}
// os.RemoveAll(rootDir)
// os.RemoveAll(leveldir)
}