-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvcs_test.go
148 lines (119 loc) · 2.98 KB
/
vcs_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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// Copyright 2019 Nirenjan Krishnan. All rights reserved.
package vanity
import (
"testing"
)
func TestSetRoot(t *testing.T) {
checks := []string{
"/~https://github.com/nirenjan/",
"https://git.nirenjan.com/go/",
"https://git.nirenjan.com/n",
}
for _, v := range checks {
var vcs Vcs
vcs.SetRoot(v)
if vcs.root != v {
t.Errorf("Mismatch in Vcs.root, expected %#v, got %#v", v, vcs.root)
}
}
}
func TestSetProvider(t *testing.T) {
checks := []struct {
provider string
vcsType string
dirFormat string
fileFormat string
}{
{"GitHub", "git", "tree/master{/dir}", "blob/master{/dir}/{file}#L{line}"},
{"GitLab", "git", "tree/master{/dir}", "blob/master{/dir}/{file}#L{line}"},
{"Gitea", "git", "src/master{/dir}", "src/master{/dir}/{file}#L{line}"},
{"Gogs", "git", "src/master{/dir}", "src/master{/dir}/{file}#L{line}"},
{"Bitbucket", "git", "src/master{/dir}", "src/master{/dir}/{file}#L{line}"},
}
for _, p := range checks {
var vcs Vcs
err := vcs.SetProvider(p.provider)
if err != nil {
t.Errorf("Expected nil, got error %v", err)
}
if p.vcsType != vcs.vcsType {
t.Errorf("Mismatch in Vcs.vcsType, expected %#v, got %#v", p.vcsType, vcs.vcsType)
}
if p.dirFormat != vcs.dirFormat {
t.Errorf("Mismatch in Vcs.dirFormat, expected %#v, got %#v", p.dirFormat, vcs.dirFormat)
}
if p.fileFormat != vcs.fileFormat {
t.Errorf("Mismatch in Vcs.fileFormat, expected %#v, got %#v", p.fileFormat, vcs.fileFormat)
}
}
}
func TestSetProviderInvalid(t *testing.T) {
var vcs Vcs
err := vcs.SetProvider("unknown")
if err == nil {
t.Errorf("Expected error, got nil")
}
}
func TestSetType(t *testing.T) {
checks := []struct {
name string
ident string
}{
{"bazaar", "bzr"},
{"Bazaar", "bzr"},
{"baZaar", "bzr"},
{"fossil", "fossil"},
{"git", "git"},
{"mercurial", "hg"},
{"subversion", "svn"},
}
for _, c := range checks {
var v Vcs
err := v.SetType(c.name)
if err != nil {
t.Errorf("Expected nil, got error %v", err)
}
if c.ident != v.vcsType {
t.Errorf("Mismatch in Vcs.vcsType, expected %#v, got %#v", c.ident, v.vcsType)
}
}
}
func TestSetTypeInvalid(t *testing.T) {
var vcs Vcs
err := vcs.SetType("cvs")
if err == nil {
t.Errorf("Expected error, got nil")
}
}
func TestSetTemplates(t *testing.T) {
checks := []struct {
dir string
file string
}{
{"", ""},
{"", "{file}"},
{"{/dir}", "{file}"},
{"{/dir}", "{file}#L{line}"},
{"{dir}", ""},
}
for _, c := range checks {
var v Vcs
err := v.SetTemplates(c.dir, c.file)
if err != nil {
t.Errorf("Expected nil, got error %v", err)
}
if c.dir != v.dirFormat {
t.Errorf("Mismatch in Vcs.dirFormat, expected %#v, got %#v", c.dir, v.dirFormat)
}
if c.file != v.fileFormat {
t.Errorf("Mismatch in Vcs.fileFormat, expected %#v, got %#v", c.file, v.fileFormat)
}
}
}
func TestSetTemplatesInvalid(t *testing.T) {
var vcs Vcs
err := vcs.SetTemplates("", "c")
if err == nil {
t.Errorf("Expected error, got nil")
}
}