-
Notifications
You must be signed in to change notification settings - Fork 179
/
repopath_test.go
104 lines (96 loc) 路 2.87 KB
/
repopath_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
package common_test
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/dlvhdr/gh-dash/ui/common"
)
var configPaths = map[string]string{
"user/repo": "/path/to/user/repo",
"user_2/*": "/path/to/user_2/*",
}
var configPathsWithOwnerRepoTemplateIgnoringOwner = map[string]string{
"user/repo": "/path/to/user/repo",
"user_2/*": "/path/to/user_2/*",
":owner/:repo": "/path/to/user/dev/:repo",
}
var configPathsWithOwnerRepoTemplate = map[string]string{
"user/repo": "/path/to/the_repo",
"org/*": "/path/to/the_org/*",
":owner/:repo": "/path/to/github.com/:owner/:repo",
}
func TestGetRepoLocalPath(t *testing.T) {
testCases := map[string]struct {
repo string
want string
found bool
configPaths map[string]string
}{
"exact match": {
repo: "user/repo",
want: "/path/to/user/repo",
found: true,
configPaths: configPaths,
},
"exact no match": {
repo: "user/other_repo",
want: "",
found: false,
configPaths: configPaths,
},
"wildcard match": {
repo: "user_2/repo123",
want: "/path/to/user_2/repo123",
found: true,
configPaths: configPaths,
},
"bad path": {
repo: "invalid-lookup",
want: "",
found: false,
configPaths: configPaths,
},
"with :owner/:repo template: ignoring owner substitution": {
repo: "user3/repo",
want: "/path/to/user/dev/repo",
found: true,
configPaths: configPathsWithOwnerRepoTemplateIgnoringOwner,
},
"with :owner/:repo template: exact match": {
repo: "user/repo",
want: "/path/to/the_repo",
found: true,
configPaths: configPathsWithOwnerRepoTemplate,
},
"with :owner/:repo template: no match for this sibling repo": {
repo: "user/another_repo",
want: "/path/to/github.com/user/another_repo",
found: true,
configPaths: configPathsWithOwnerRepoTemplate,
},
"with :owner/:repo template: wildcard repo match": {
repo: "org/some_repo",
want: "/path/to/the_org/some_repo",
found: true,
configPaths: configPathsWithOwnerRepoTemplate,
},
"with :owner/:repo template: general fallback": {
repo: "any-owner/any-repo",
want: "/path/to/github.com/any-owner/any-repo",
found: true,
configPaths: configPathsWithOwnerRepoTemplate,
},
"with :owner/:repo template: repeated :repo substitution": {
repo: "any-owner/any-repo",
want: "src/github.com/any-owner/any-repo/any-repo",
found: true,
configPaths: map[string]string{":owner/:repo": "src/github.com/:owner/:repo/:repo"},
},
}
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
got, found := common.GetRepoLocalPath(tc.repo, tc.configPaths)
require.Equal(t, tc.want, got)
require.Equal(t, tc.found, found)
})
}
}