forked from linxGnu/goseaweedfs
-
Notifications
You must be signed in to change notification settings - Fork 12
/
filer_test.go
94 lines (79 loc) · 1.92 KB
/
filer_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
90
91
92
93
94
package goseaweedfs
import (
"github.com/stretchr/testify/require"
"net/http"
"path/filepath"
"testing"
"time"
)
func setup() (f *Filer, err error) {
filerUrl := "http://localhost:8888"
httpClient := http.Client{Timeout: 5 * time.Minute}
f, err = NewFiler(filerUrl, &httpClient)
if err != nil {
panic(err)
}
return
}
func TestFiler_UploadDir(t *testing.T) {
f, _ := setup()
localDirPath, _ := filepath.Abs(".")
newDirPath := "test_dir"
collection := "test_collection"
// test UploadDir
_, err := f.UploadDir(localDirPath, newDirPath, collection, "")
require.Nil(t, err)
// test ListDir
files, err := f.ListDir(newDirPath)
require.Nil(t, err)
require.Greater(t, len(files), 0)
// cleanup
_ = f.DeleteDir(newDirPath)
_ = f.Close()
}
func TestFiler_ListDir(t *testing.T) {
f, _ := setup()
localDirPath, _ := filepath.Abs(".")
newDirPath := "test_dir"
collection := "test_collection"
// test UploadDir
_, err := f.UploadDir(localDirPath, newDirPath, collection, "")
require.Nil(t, err)
// test ListDir
files, err := f.ListDir(newDirPath)
require.Nil(t, err)
require.Greater(t, len(files), 0)
// cleanup
_ = f.DeleteDir(newDirPath)
}
func TestFiler_ListDirRecursive(t *testing.T) {
f, _ := setup()
localDirPath, _ := filepath.Abs(".")
newDirPath := "test_dir"
collection := "test_collection"
// test UploadDir
_, err := f.UploadDir(localDirPath, newDirPath, collection, "")
require.Nil(t, err)
// test ListDirRecursive
files, err := f.ListDirRecursive(newDirPath)
require.Nil(t, err)
valid := false
for _, f1 := range files {
if f1.Name == "test" {
require.NotNil(t, f1.Children)
for _, f2 := range f1.Children {
if f2.Name == "nested" {
require.NotNil(t, f2.Children)
for _, f3 := range f2.Children {
if f3.Name == "nested_file.txt" && f3.Extension == "txt" {
valid = true
}
}
}
}
}
}
require.True(t, valid)
// cleanup
_ = f.DeleteDir(newDirPath)
}