This repository has been archived by the owner on Apr 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
/
repo_test.go
132 lines (125 loc) · 2.55 KB
/
repo_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
package main
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestParseRepo(t *testing.T) {
var tests = []struct {
defSchema string
defHost string
defOrganization string
fullPath string
expPath string
expHost string
expUser string
expSchema string
expCloneURL string
}{
// ensure default schema works as expected
{
"ssh",
"github.com",
"",
"cdr/sail",
"cdr/sail",
"github.com",
"git",
"ssh",
"ssh://[email protected]/cdr/sail.git",
},
// ensure default schemas works as expected
{
"http",
"github.com",
"",
"cdr/sail",
"cdr/sail",
"github.com",
"",
"http",
"http://github.com/cdr/sail.git",
},
// ensure default schemas works as expected
{
"https",
"github.com",
"",
"cdr/sail",
"cdr/sail",
"github.com",
"",
"https",
"https://github.com/cdr/sail.git",
},
// http url parses correctly
{
"https",
"github.com",
"",
"https://github.com/cdr/sail",
"cdr/sail",
"github.com",
"",
"https",
"https://github.com/cdr/sail.git",
},
// git url with username and without schema parses correctly
{
"ssh",
"github.com",
"",
"[email protected]/cdr/sail.git",
"cdr/sail",
"github.com",
"git",
"ssh",
"ssh://[email protected]/cdr/sail.git",
},
// different default schema doesn't override given schema
{
"http",
"github.com",
"",
"ssh://[email protected]/cdr/sail",
"cdr/sail",
"github.com",
"git",
"ssh",
"ssh://[email protected]/cdr/sail.git",
},
// ensure custom host works
{
"https",
"my.private-git.com",
"",
"private/repo",
"private/repo",
"my.private-git.com",
"",
"https",
"https://my.private-git.com/private/repo.git",
},
// ensure default organization works as expected
{
"ssh",
"github.com",
"cdr",
"sail",
"cdr/sail",
"github.com",
"git",
"ssh",
"ssh://[email protected]/cdr/sail.git",
},
}
for _, test := range tests {
repo, err := parseRepo(test.defSchema, test.defHost, test.defOrganization, test.fullPath)
require.NoError(t, err)
assert.Equal(t, test.expPath, repo.Path, "expected path to be the same")
assert.Equal(t, test.expHost, repo.Host, "expected host to be the same")
assert.Equal(t, test.expUser, repo.User.Username(), "expected user to be the same")
assert.Equal(t, test.expSchema, repo.Scheme, "expected scheme to be the same")
assert.Equal(t, test.expCloneURL, repo.CloneURI(), "expected clone uri to be the same")
}
}