-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
git_test.go
80 lines (74 loc) · 1.79 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
package main
import "testing"
func Test_parseGithubRemote(t *testing.T) {
tests := []struct {
name string
remoteURL string
wantOwner string
wantRepo string
wantOk bool
}{
{
name: "GitHub_HTTPS",
remoteURL: "https://github.com/mroth/bump.git",
wantOwner: "mroth",
wantRepo: "bump",
wantOk: true,
},
{
name: "GitHub_HTTPS_noExtension",
remoteURL: "https://github.com/mroth/bump",
wantOwner: "mroth",
wantRepo: "bump",
wantOk: true,
},
{
name: "GitHub_SSH",
remoteURL: "[email protected]:mroth/bump.git",
wantOwner: "mroth",
wantRepo: "bump",
wantOk: true,
},
}
for _, tt := range tests {
tt := tt // pin to avoid scope issues (see scopelint)
t.Run(tt.name, func(t *testing.T) {
gotOwner, gotRepo, gotOk := parseGithubRemote(tt.remoteURL)
if gotOwner != tt.wantOwner {
t.Errorf("parseGithubRemote() gotOwner = %v, want %v", gotOwner, tt.wantOwner)
}
if gotRepo != tt.wantRepo {
t.Errorf("parseGithubRemote() gotRepo = %v, want %v", gotRepo, tt.wantRepo)
}
if gotOk != tt.wantOk {
t.Errorf("parseGithubRemote() gotOk = %v, want %v", gotOk, tt.wantOk)
}
})
}
}
func Test_githubRepoDetect(t *testing.T) {
owner, repo, err := githubRepoDetect(".")
if err != nil {
t.Fatal(err)
}
expect := "mroth/bump"
actual := owner + "/" + repo
if expect != actual {
t.Errorf("want %v got %v", expect, actual)
}
}
func Benchmark_detectRemoteURL_GoGit(b *testing.B) {
for i := 0; i < b.N; i++ {
_detectRemoteURL_GoGit(".")
}
}
func Benchmark_detectRemoteURL_LocalGit(b *testing.B) {
for i := 0; i < b.N; i++ {
_detectRemoteURL_LocalGit(".")
}
}
func Benchmark_parseGithubRemote(b *testing.B) {
for i := 0; i < b.N; i++ {
parseGithubRemote("https://github.com/mroth/bump.git")
}
}