-
-
Notifications
You must be signed in to change notification settings - Fork 184
/
getter_test.go
69 lines (66 loc) · 1.82 KB
/
getter_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
package main
import "testing"
func TestDetectLocalRepoRoot(t *testing.T) {
testCases := []struct {
name, remotePath, repoPath, expect string
}{{
name: "same",
remotePath: "/motemen/ghq",
repoPath: "/motemen/ghq",
expect: "/motemen/ghq",
}, {
name: "deep remote repo path",
remotePath: "/path/to/repo/repo",
repoPath: "/path/to/repo",
expect: "/path/to/repo",
}, {
name: "different remote root",
remotePath: "/src/path/to/repo/repo",
repoPath: "/path/to/repo",
expect: "/src/path/to/repo",
}, {
name: "different repo root",
remotePath: "/path/to/repo/repo",
repoPath: "/git/path/to/repo",
expect: "/path/to/repo",
}, {
name: "different roots",
remotePath: "/src/path/to/repo/repo",
repoPath: "/git/path/to/repo",
expect: "/src/path/to/repo",
}, {
name: "different roots with multibyte",
remotePath: "/そーすこーど/path/to/repo/repo",
repoPath: "/ぎっと/path/to/repo",
expect: "/そーすこーど/path/to/repo",
}, {
name: "shallow path",
remotePath: "/zap/buffer",
repoPath: "/uber-go/zap",
expect: "/zap",
}, {
name: ".git at the end",
remotePath: "/path/to/repo.git",
repoPath: "/path/to/repo.git",
expect: "/path/to/repo",
}, {
name: "trailing slash",
remotePath: "/path/to/repo/",
repoPath: "/path/to/repo/",
expect: "/path/to/repo",
}, {
name: ".git/ at the end",
remotePath: "/path/to/repo.git/",
repoPath: "/path/to/repo.git/",
expect: "/path/to/repo",
}}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
out := detectLocalRepoRoot(tc.remotePath, tc.repoPath)
if tc.expect != out {
t.Errorf("detectLocalRepoRoot(%q, %q) = %q, expect: %q",
tc.remotePath, tc.repoPath, out, tc.expect)
}
})
}
}