-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
56 lines (52 loc) · 1.07 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
package main
import (
"testing"
)
func TestGitURL(t *testing.T) {
if parseGit("[email protected]:jhaals/yopass.git") != "github.com/jhaals/yopass" {
t.Error("failed")
}
}
func TestHTTPURL(t *testing.T) {
if parseHTTP("https://github.com/jhaals/yopass.git") != "github.com/jhaals/yopass" {
t.Error("failed")
}
}
func TestParse(t *testing.T) {
testCases := []struct {
desc string
input string
want string
wantErr bool
}{
{
desc: "git url",
input: "[email protected]:jhaals/yopass.git",
want: "github.com/jhaals/yopass",
wantErr: false,
},
{
desc: "http url",
input: "https://github.com/jhaals/yopass.git",
want: "github.com/jhaals/yopass",
wantErr: false,
},
{
desc: "No input",
input: "",
want: "",
wantErr: true,
},
}
for _, tC := range testCases {
t.Run(tC.desc, func(t *testing.T) {
path, err := ParseRepository(tC.input)
if err != nil && !tC.wantErr {
t.Errorf("Did not expect error")
}
if tC.want != path {
t.Errorf("Wanted %s, got %s", tC.want, path)
}
})
}
}