-
Notifications
You must be signed in to change notification settings - Fork 3
/
main_test.go
97 lines (92 loc) · 1.79 KB
/
main_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
package main
import (
aw "github.com/deanishe/awgo"
"strings"
"testing"
)
const (
full_repo_path = "/hoge/fuga/github.com/user/repo"
full_repo_bucket = "/hoge/fuga/bitbucket.org/user/repo"
full_repo_other = "/hoge/fuga/other.git/user/repo"
user_repo = "user/repo"
github_user_repo = "github.com/user/repo"
bitbucket_user_repo = "bitbucket.org/user/repo"
)
func TestExcludeDomain(t *testing.T) {
testcases := []struct {
path string
expected string
domain bool
}{
{
full_repo_path,
user_repo,
true,
}, {
full_repo_path,
github_user_repo,
false,
}, {
full_repo_bucket,
user_repo,
true,
}, {
full_repo_bucket,
bitbucket_user_repo,
false,
},
}
for _, tc := range testcases {
repoPath := strings.Split(tc.path, "/")
actual := excludeDomain(repoPath, tc.domain)
if actual != tc.expected {
t.Errorf("%s is expected, but actual %s\n", tc.expected, actual)
}
}
}
func TestGetDomainName(t *testing.T) {
testcases := []struct {
path string
domain string
}{
{
full_repo_path,
"github.com",
}, {
full_repo_bucket,
"bitbucket.org",
}, {
full_repo_other,
"other.git",
},
}
for _, tc := range testcases {
repoPath := strings.Split(tc.path, "/")
if actual := getDomainName(repoPath); actual != tc.domain {
t.Errorf("%s is expected, but actual %s\n", tc.domain, actual)
}
}
}
func TestGetIconPath(t *testing.T) {
testcases := []struct {
path string
icon *aw.Icon
}{
{
full_repo_path,
gitHubIcon,
}, {
full_repo_bucket,
bitBucketIcon,
}, {
full_repo_other,
gitIcon,
},
}
for _, tc := range testcases {
repoPath := strings.Split(tc.path, "/")
if icon := getIcon(repoPath); icon != tc.icon {
t.Errorf("Expect: %s\nResult: %s\n", tc.icon, icon)
}
}
}