-
Notifications
You must be signed in to change notification settings - Fork 2
/
git_test.go
129 lines (127 loc) · 2.33 KB
/
git_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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package main
import (
"path/filepath"
"testing"
)
func Test_resolvePath(t *testing.T) {
type args struct {
base string
title string
}
tests := []struct {
name string
args args
wantFile string
wantGit string
wantErr bool
}{
{
"basic file",
args{"repo", "title.md"},
filepath.Join("repo", "title.md"),
"title.md",
false,
},
{
"sub directory",
args{"repo", "some/folder/title.md"},
filepath.Join("repo", "some", "folder", "title.md"),
filepath.Join("some", "folder", "title.md"),
false,
},
{
"collapse dirs",
args{"repo", "some/folder/../../title.md"},
filepath.Join("repo", "title.md"),
filepath.Join("title.md"),
false,
},
{
"normalise dots",
args{"repo", "./title.md"},
filepath.Join("repo", "title.md"),
filepath.Join("title.md"),
false,
},
{
"directory escape",
args{"repo", "../title.md"},
"",
"",
true,
},
{
"nested directory escape",
args{"repo", "foo/../../title.md"},
"",
"",
true,
},
{
"relative git directory",
args{"repo", "./.git/title.md"},
"",
"",
true,
},
{
"git subdirectory",
args{"repo", "foo/bar/.git/title.md"},
"",
"",
true,
},
{
"git mixed-case",
args{"repo", "foo/bar/.gIt/title.md"},
"",
"",
true,
},
{
"wiki subdirectory",
args{"repo", "foo/bar/.wiki/title.md"},
"",
"",
true,
},
{
"wiki mixed-case",
args{"repo", "foo/bar/.WIKi/title.md"},
"",
"",
true,
},
{
"mixed case directory",
args{"repo", "Foo/bar.md"},
filepath.Join("repo", "foo", "bar.md"),
filepath.Join("foo", "bar.md"),
false,
},
{
"mixed case file",
args{"repo", "foo/Bar.md"},
filepath.Join("repo", "foo", "bar.md"),
filepath.Join("foo", "bar.md"),
false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotFilePath, gotGitPath, err := (&GitBackend{}).resolvePath(tt.args.base, tt.args.title)
if (err != nil) != tt.wantErr {
t.Errorf("resolvePath() error = %v, wantErr %v", err, tt.wantErr)
return
}
if gotFilePath != tt.wantFile {
t.Errorf("resolvePath() got file path = %v, want %v", gotFilePath, tt.wantFile)
return
}
if gotGitPath != tt.wantGit {
t.Errorf("resolvePath() got git path = %v, want %v", gotGitPath, tt.wantGit)
return
}
})
}
}