-
Notifications
You must be signed in to change notification settings - Fork 0
/
manifest_test.go
55 lines (51 loc) · 1.2 KB
/
manifest_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
package bago
import (
"strings"
"testing"
)
func TestManifestAppend(t *testing.T) {
m := Manifest{}
p := "afile\nwith\rspecial characters"
encP := EncodePath(p)
if string(encP) != "afile%0Awith%0Dspecial characters" {
t.Errorf(`EncodePath is broken. Got: %s`, encP)
}
m.Append(encP, nil)
entry, exists := m.entries[EncodePath(p).Norm()]
if !exists {
t.Error(`Append failed`)
}
if entry.path != p {
t.Errorf(`Appended path not decoded correctly. Got: %s`, entry.path)
}
}
func TestManifestParse(t *testing.T) {
tests := map[bool][]string{
true: []string{ // valid
"1234 file1\n5678 file2",
"9ABC\tfile3",
"DEF8 afile%0Awith%0Dspecial%25characters\nABC9 another_file",
},
false: []string{ // invalid
``,
"\n1234 afile",
`1234`,
` 1234 afile`,
"1234 file1\n123 file1",
"1234 file1\n567 file1",
},
}
for expectValid, vals := range tests {
for i := range vals {
r := strings.NewReader(vals[i])
m := &Manifest{}
if err := m.parse(r); (err == nil) != expectValid {
if expectValid {
t.Errorf("expected parse to return nil for `%s`: error is %s", vals[i], err)
} else {
t.Errorf("expected parse to return error for `%s`", vals[i])
}
}
}
}
}