FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
containerlab/git/gitlab_test.go at main · BSpendlove/containerlab · GitHub
BSpendlove
/
containerlab
Public
forked from
srl-labs/containerlab
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
containerlab
/
git
/
gitlab_test.go
Copy path
More file actions
More file actions
Latest commit
History
History
History
194 lines (183 loc) · 5.15 KB
Breadcrumbs
containerlab
/
git
/
gitlab_test.go
Copy path
File metadata and controls
194 lines (183 loc) · 5.15 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
package
git
import
(
"errors"
"testing"
"github.com/google/go-cmp/cmp"
)
func
TestNewGitLabRepoFromURL
(
t
*
testing.
T
) {
tests
:=
[]
struct
{
name
string
url
string
repo
*
GitLabRepo
wantErr
bool
}{
{
name
:
"valid gitlab url without trailing slash and with https schema"
,
url
:
"https://gitlab.com/rdodin/clab-test-repo"
,
repo
:
&
GitLabRepo
{
GitRepoStruct
{
ProjectOwner
:
"rdodin"
,
RepositoryName
:
"clab-test-repo"
,
},
},
wantErr
:
false
,
},
{
name
:
"valid gitlab url with trailing slash and with https schema"
,
url
:
"https://gitlab.com/rdodin/clab-test-repo/"
,
repo
:
&
GitLabRepo
{
GitRepoStruct
{
URL
:
urlFromStr
(
"https://gitlab.com/rdodin/clab-test-repo/"
),
CloneURL
:
urlFromStr
(
"https://gitlab.com/rdodin/clab-test-repo"
),
ProjectOwner
:
"rdodin"
,
RepositoryName
:
"clab-test-repo"
,
},
},
wantErr
:
false
,
},
{
name
:
"invalid gitlab url with just one path element and https schema and trailing slash"
,
url
:
"https://gitlab.com/rdodin/"
,
wantErr
:
true
,
},
{
name
:
"valid gitlab url with https schema and with .git suffix"
,
url
:
"https://gitlab.com/rdodin/clab-test-repo.git"
,
repo
:
&
GitLabRepo
{
GitRepoStruct
{
ProjectOwner
:
"rdodin"
,
RepositoryName
:
"clab-test-repo"
,
},
},
wantErr
:
false
,
},
{
name
:
"gitlab url with a clab file on the main branch without path args"
,
url
:
"https://gitlab.com/rdodin/clab-test-repo/-/blob/main/lab1.clab.yml"
,
repo
:
&
GitLabRepo
{
GitRepoStruct
{
ProjectOwner
:
"rdodin"
,
RepositoryName
:
"clab-test-repo"
,
CloneURL
:
urlFromStr
(
"https://gitlab.com/rdodin/clab-test-repo"
),
GitBranch
:
"main"
,
FileName
:
"lab1.clab.yml"
,
},
},
wantErr
:
false
,
},
{
name
:
"invalid file in a gitlab url with on the main branch"
,
url
:
"https://gitlab.com/rdodin/clab-test-repo/-/blob/main/lab1.foo"
,
wantErr
:
true
,
},
{
name
:
"gitlab url with a clab file on the main branch in a nested dir without path args"
,
url
:
"https://gitlab.com/rdodin/clab-test-repo/-/blob/main/dir/lab3.clab.yml"
,
repo
:
&
GitLabRepo
{
GitRepoStruct
{
ProjectOwner
:
"rdodin"
,
RepositoryName
:
"clab-test-repo"
,
CloneURL
:
urlFromStr
(
"https://gitlab.com/rdodin/clab-test-repo"
),
GitBranch
:
"main"
,
Path
: []
string
{
"dir"
},
FileName
:
"lab3.clab.yml"
,
},
},
wantErr
:
false
,
},
{
name
:
"gitlab url pointing to a branch with a path arg"
,
url
:
"https://gitlab.com/rdodin/clab-test-repo/-/tree/branch1?ref_type=heads"
,
repo
:
&
GitLabRepo
{
GitRepoStruct
{
ProjectOwner
:
"rdodin"
,
RepositoryName
:
"clab-test-repo"
,
CloneURL
:
urlFromStr
(
"https://gitlab.com/rdodin/clab-test-repo"
),
GitBranch
:
"branch1"
,
},
},
wantErr
:
false
,
},
{
name
:
"gitlab url pointing to a file in a branch"
,
url
:
"https://gitlab.com/rdodin/clab-test-repo/-/blob/branch1/lab2.clab.yml?ref_type=heads"
,
repo
:
&
GitLabRepo
{
GitRepoStruct
{
ProjectOwner
:
"rdodin"
,
RepositoryName
:
"clab-test-repo"
,
CloneURL
:
urlFromStr
(
"https://gitlab.com/rdodin/clab-test-repo"
),
GitBranch
:
"branch1"
,
FileName
:
"lab2.clab.yml"
,
},
},
wantErr
:
false
,
},
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing.
T
) {
repo
,
err
:=
NewGitLabRepoFromURL
(
urlFromStr
(
tt
.
url
))
if
(
err
!=
nil
)
!=
tt
.
wantErr
{
t
.
Errorf
(
"ParseGitURL() error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
return
}
if
(
err
!=
nil
)
&&
errors
.
Is
(
err
,
errInvalidURL
) {
return
}
// when we do not manipulate url path in the ParseGitURL method
// the wantRepo.URL field will be nil, so we need to set it up
// to match the original URL
if
tt
.
repo
.
URL
==
nil
{
tt
.
repo
.
URL
=
urlFromStr
(
tt
.
url
)
}
// when we do not manipulate CloneURL in the ParseGitURL method
// the wantRepo.CloneURL field will be nil, so we need to set it up
// to match the original URL
if
tt
.
repo
.
CloneURL
==
nil
{
tt
.
repo
.
CloneURL
=
urlFromStr
(
tt
.
url
)
}
if
diff
:=
cmp
.
Diff
(
repo
,
tt
.
repo
);
diff
!=
""
{
t
.
Errorf
(
"TestNewGitLabRepoFromURL() mismatch:
\n
%s"
,
diff
)
}
})
}
}
func
TestIsGitLabURL
(
t
*
testing.
T
) {
tests
:=
[]
struct
{
name
string
input
string
want
bool
}{
{
name
:
"gitlab.com"
,
input
:
"http://gitlab.com"
,
want
:
true
,
},
{
name
:
"gitlab.com/containers/containerlab/blob/master/README.md"
,
input
:
"https://gitlab.com/containers/containerlab/blob/master/README.md"
,
want
:
true
,
},
{
name
:
"google.com/containers"
,
input
:
"http://google.com/containers"
,
want
:
false
,
},
{
name
:
"google.com/containers/containerlab/blob/master/README.md"
,
input
:
"https://google.com/containers/containerlab/blob/master/README.md"
,
want
:
false
,
},
{
name
:
"github.com/containers"
,
input
:
"http://github.com/containers"
,
want
:
false
,
},
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing.
T
) {
if
output
:=
IsGitLabURL
(
urlFromStr
(
tt
.
input
));
output
!=
tt
.
want
{
t
.
Errorf
(
"Test %q failed: want %v, but got %v"
,
tt
.
name
,
tt
.
want
,
output
)
}
})
}
}
Back
|
FazBrowse Home
|
New Git URL