-
Notifications
You must be signed in to change notification settings - Fork 0
/
dir_test.go
42 lines (39 loc) · 874 Bytes
/
dir_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
package main
import (
"bytes"
"testing"
)
func mustDirFromZip(m map[string][]byte) dir {
b := makeZipFileBytes(m)
r := bytes.NewReader(b)
d, err := newDirFromZip(r, int64(len(b)))
if err != nil {
panic(err)
}
return d
}
func TestDirApi(t *testing.T) {
root := mustDirFromZip(multiLevelWithZip)
dirs := root.dirs()
expectedDirs := map[string]struct{}{
"a": {},
}
if len(expectedDirs) != len(dirs) {
t.Fatalf("Expected '%v', got '%v'", expectedDirs, dirs)
}
d := recursiveFindDir(root, "a/d")
if d == nil {
t.Fatalf("Failed to get 'a/d' dir")
}
f := recursiveFindFile(root, "a/d/g/h/i/j")
if f == nil {
t.Fatalf("Failed to get 'a/d/g/h/i/j' file")
}
b, err := allBytes(f)
if err != nil {
t.Fatalf("Failed to open '%v': %v", f.name(), err)
}
if string(b) != "k" {
t.Fatalf("Incorrect content, expected \"k\", got '%v'", string(b))
}
}