-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_test.go
47 lines (41 loc) · 1.33 KB
/
add_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
package main
import "testing"
func TestParseGitUrl(t *testing.T) {
testCases := []struct {
gitUrl string
wantUsername string
wantRepoName string
wantErr bool
}{
{"[email protected]:user/repo.git", "user", "repo", false},
{"https://github.com/user/repo.git", "user", "repo", false},
{"invalid-url", "", "", true},
}
for _, tc := range testCases {
gotUsername, gotRepoName, err := parseGitUrl(tc.gitUrl)
if (err != nil) != tc.wantErr {
t.Errorf("parseGitUrl(%s): expected error: %v, got: %v", tc.gitUrl, tc.wantErr, err)
}
if gotUsername != tc.wantUsername || gotRepoName != tc.wantRepoName {
t.Errorf("parseGitUrl(%s): expected: %s/%s, got: %s/%s", tc.gitUrl, tc.wantUsername, tc.wantRepoName, gotUsername, gotRepoName)
}
}
}
func TestGetClonePath(t *testing.T) {
testCases := []struct {
gitUrl string
wantCloneDir string
wantError bool
}{
{"[email protected]:user/repo.git", "/home/user/repos/user/repo", false},
{"https://github.com/user/repo.git", "/home/user/repos/user/repo", false},
{"invalid-url", "", true},
}
config := Config{ReposBasePath: "/home/user/repos"}
for _, tc := range testCases {
gotCloneDir := getClonePath(tc.gitUrl, config)
if gotCloneDir != tc.wantCloneDir {
t.Errorf("getClonePath(%s): expected: %s, got: %s", tc.gitUrl, tc.wantCloneDir, gotCloneDir)
}
}
}