-
Notifications
You must be signed in to change notification settings - Fork 0
/
virtualFileSystem_test.go
71 lines (59 loc) · 1.55 KB
/
virtualFileSystem_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
package mapreduce
import "testing"
type expected map[string]bool
func expect(items ...string) expected {
r := expected{}
for _, item := range items {
r[item] = false
}
return r
}
func (e expected) Check(t *testing.T, entries []string) {
if len(entries) != len(e) {
t.Error("Wrong number of items in entries:", entries)
}
for _, entry := range entries {
if _, found := e[entry]; found {
e[entry] = true
} else {
t.Error("Unexpected entry:", entry)
}
}
for entry, found := range e {
if !found {
t.Error("Missing entry:", entry)
}
}
}
func TestVFSFolderList(t *testing.T) {
fs := StaticVirtualFileSystem{
"folder/folder/file.txt": "content",
"folder/folder/file2.txt": "more content",
"folder/other/something/file.txt": "content2",
}
folders, _, _ := fs.List("folder")
expect("folder", "other").Check(t, folders)
}
func TestVFSFileList(t *testing.T) {
fs := StaticVirtualFileSystem{
"folder/folder/file.txt": "content",
"folder/folder/file2.txt": "more content",
"folder/other/something/file.txt": "content2",
}
_, files, _ := fs.List("folder/folder")
expect("file.txt", "file2.txt").Check(t, files)
}
func TestVFSFileOpen(t *testing.T) {
fs := StaticVirtualFileSystem{
"folder/folder/file.txt": "content",
"folder/folder/file2.txt": "more content",
"folder/other/something/file.txt": "content2",
}
content, err := fs.Open("folder/folder/file.txt")
if err != nil {
t.Error(err)
}
if content != "content" {
t.Errorf("Content of file unexpected: %v", content)
}
}