-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindexer_test.go
75 lines (73 loc) · 1.61 KB
/
indexer_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
package vfs
import (
"testing"
)
func Test_isHashFile(t *testing.T) {
type args struct {
ns string
path string
}
tests := []struct {
name string
args args
want bool
}{
{
name: "empty ns & path",
args: args{ns: "", path: ""},
want: false,
},
{
name: "empty path",
args: args{ns: "test-namespace", path: ""},
want: false,
},
{
name: "wrong length",
args: args{ns: "test-namespace", path: "test-namespace/test-file.jpeg"},
want: false,
},
{
name: "wrong dir tree",
args: args{ns: "", path: "70/c/70c565ef460af43688b7ee6251028db9.jpg"},
want: false,
},
{
name: "wrong dir tree with namespace",
args: args{ns: "test", path: "test/70/c/70c565ef460af43688b7ee6251028db9.jpg"},
want: false,
},
{
name: "wrong hash prefix",
args: args{ns: "test", path: "test/7/1c/70c565ef460af43688b7ee6251028db9.jpg"},
want: false,
},
{
name: "non-hex path",
args: args{ns: "", path: "7/0q/70q565ef460af43688b7ee6251028db9.jpg"},
want: false,
},
{
name: "ok without extension",
args: args{ns: "test", path: "test/7/0f/70f565ef460af43688b7ee6251028db9"},
want: true,
},
{
name: "ok with 3-chars extension",
args: args{ns: "", path: "7/0c/70c565ef460af43688b7ee6251028db9.gif"},
want: true,
},
{
name: "ok with 4-chars extension",
args: args{ns: "", path: "7/0c/70c565ef460af43688b7ee6251028db9.jpeg"},
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := isHashFile(tt.args.ns, tt.args.path); got != tt.want {
t.Errorf("isHashFile() = %v, want %v", got, tt.want)
}
})
}
}