@@ -30,6 +30,7 @@ func (f FakeGitManager) GetProjectUrlFromNativeGitCmd(string) (url string, err e
3030
3131type TestCase struct {
3232 desc string
33+ url string
3334 branch string
3435 projectName string
3536 namespace string
@@ -40,116 +41,156 @@ func TestExtractGitInfo_Success(t *testing.T) {
4041 testCases := []TestCase {
4142 {
4243 desc : "Project configured in SSH under a single folder" ,
44+ 4345 remote :
"[email protected] :namespace-1/project-name.git" ,
4446 branch : "feature/abc" ,
4547 projectName : "project-name" ,
4648 namespace : "namespace-1" ,
4749 },
4850 {
4951 desc : "Project configured in SSH under a single folder without .git extension" ,
52+ 5053 remote :
"[email protected] :namespace-1/project-name" ,
5154 branch : "feature/abc" ,
5255 projectName : "project-name" ,
5356 namespace : "namespace-1" ,
5457 },
5558 {
5659 desc : "Project configured in SSH under one nested folder" ,
60+ 5761 remote :
"[email protected] :namespace-1/namespace-2/project-name.git" ,
5862 branch : "feature/abc" ,
5963 projectName : "project-name" ,
6064 namespace : "namespace-1/namespace-2" ,
6165 },
6266 {
6367 desc : "Project configured in SSH under two nested folders" ,
68+ 6469 remote :
"[email protected] :namespace-1/namespace-2/namespace-3/project-name.git" ,
6570 branch : "feature/abc" ,
6671 projectName : "project-name" ,
6772 namespace : "namespace-1/namespace-2/namespace-3" ,
6873 },
6974 {
7075 desc : "Project configured in SSH:// under a single folder" ,
76+ url : "ssh://custom-gitlab.com" ,
7177 remote : "ssh://custom-gitlab.com/namespace-1/project-name.git" ,
7278 branch : "feature/abc" ,
7379 projectName : "project-name" ,
7480 namespace : "namespace-1" ,
7581 },
7682 {
7783 desc : "Project configured in SSH:// under a single folder without .git extension" ,
84+ url : "ssh://custom-gitlab.com" ,
7885 remote : "ssh://custom-gitlab.com/namespace-1/project-name" ,
7986 branch : "feature/abc" ,
8087 projectName : "project-name" ,
8188 namespace : "namespace-1" ,
8289 },
8390 {
8491 desc : "Project configured in SSH:// under two nested folders" ,
92+ url : "ssh://custom-gitlab.com" ,
8593 remote : "ssh://custom-gitlab.com/namespace-1/namespace-2/namespace-3/project-name.git" ,
8694 branch : "feature/abc" ,
8795 projectName : "project-name" ,
8896 namespace : "namespace-1/namespace-2/namespace-3" ,
8997 },
9098 {
9199 desc : "Project configured in SSH:// and have a custom port" ,
100+ url : "ssh://custom-gitlab.com" ,
92101 remote : "ssh://custom-gitlab.com:2222/namespace-1/project-name" ,
93102 branch : "feature/abc" ,
94103 projectName : "project-name" ,
95104 namespace : "namespace-1" ,
96105 },
106+ {
107+ desc : "Project configured in SSH:// and have a custom port (with gitlab url namespace)" ,
108+ url : "ssh://custom-gitlab.com/a" ,
109+ remote : "ssh://custom-gitlab.com:2222/a/namespace-1/project-name" ,
110+ branch : "feature/abc" ,
111+ projectName : "project-name" ,
112+ namespace : "namespace-1" ,
113+ },
97114 {
98115 desc : "Project configured in HTTP and under a single folder without .git extension" ,
116+ url : "http://custom-gitlab.com" ,
99117 remote : "http://custom-gitlab.com/namespace-1/project-name" ,
100118 branch : "feature/abc" ,
101119 projectName : "project-name" ,
102120 namespace : "namespace-1" ,
103121 },
104122 {
105123 desc : "Project configured in HTTP and under a single folder without .git extension (with embedded credentials)" ,
124+ url : "http://custom-gitlab.com" ,
106125 remote :
"http://username:[email protected] /namespace-1/project-name" ,
107126 branch : "feature/abc" ,
108127 projectName : "project-name" ,
109128 namespace : "namespace-1" ,
110129 },
111130 {
112131 desc : "Project configured in HTTPS and under a single folder" ,
132+ url : "https://custom-gitlab.com" ,
113133 remote : "https://custom-gitlab.com/namespace-1/project-name.git" ,
114134 branch : "feature/abc" ,
115135 projectName : "project-name" ,
116136 namespace : "namespace-1" ,
117137 },
118138 {
119139 desc : "Project configured in HTTPS and under a single folder (with embedded credentials)" ,
140+ url : "https://custom-gitlab.com" ,
120141 remote :
"https://username:[email protected] /namespace-1/project-name.git" ,
121142 branch : "feature/abc" ,
122143 projectName : "project-name" ,
123144 namespace : "namespace-1" ,
124145 },
125146 {
126147 desc : "Project configured in HTTPS and under a nested folder" ,
148+ url : "https://custom-gitlab.com" ,
127149 remote : "https://custom-gitlab.com/namespace-1/namespace-2/project-name.git" ,
128150 branch : "feature/abc" ,
129151 projectName : "project-name" ,
130152 namespace : "namespace-1/namespace-2" ,
131153 },
132154 {
133155 desc : "Project configured in HTTPS and under a nested folder (with embedded credentials)" ,
156+ url : "https://custom-gitlab.com" ,
134157 remote :
"https://username:[email protected] /namespace-1/namespace-2/project-name.git" ,
135158 branch : "feature/abc" ,
136159 projectName : "project-name" ,
137160 namespace : "namespace-1/namespace-2" ,
138161 },
139162 {
140163 desc : "Project configured in HTTPS and under two nested folders" ,
164+ url : "https://custom-gitlab.com" ,
141165 remote : "https://custom-gitlab.com/namespace-1/namespace-2/namespace-3/project-name.git" ,
142166 branch : "feature/abc" ,
143167 projectName : "project-name" ,
144168 namespace : "namespace-1/namespace-2/namespace-3" ,
145169 },
146170 {
147171 desc : "Project configured in HTTPS and under two nested folders (with embedded credentials)" ,
172+ url : "https://custom-gitlab.com" ,
148173 remote :
"https://username:[email protected] /namespace-1/namespace-2/namespace-3/project-name.git" ,
149174 branch : "feature/abc" ,
150175 projectName : "project-name" ,
151176 namespace : "namespace-1/namespace-2/namespace-3" ,
152177 },
178+ {
179+ desc : "Project configured in HTTPS and under one nested folders (with gitlab url namespace)" ,
180+ url : "https://custom-gitlab.com/gitlab" ,
181+ remote :
"https://username:[email protected] /gitlab/namespace-2/namespace-3/project-name.git" ,
182+ branch : "feature/abc" ,
183+ projectName : "project-name" ,
184+ namespace : "namespace-2/namespace-3" ,
185+ },
186+ {
187+ desc : "Project configured in HTTPS and under one nested folders (with gitlab url namespace + extra slash)" ,
188+ url : "https://custom-gitlab.com/gitlab/" ,
189+ remote :
"https://username:[email protected] /gitlab/namespace-2/namespace-3/project-name.git" ,
190+ branch : "feature/abc" ,
191+ projectName : "project-name" ,
192+ namespace : "namespace-2/namespace-3" ,
193+ },
153194 }
154195 for _ , tC := range testCases {
155196 t .Run (tC .desc , func (t * testing.T ) {
@@ -159,7 +200,7 @@ func TestExtractGitInfo_Success(t *testing.T) {
159200 BranchName : tC .branch ,
160201 RemoteUrl : tC .remote ,
161202 }
162- data , err := NewGitData (tC .remote , g )
203+ data , err := NewGitData (tC .remote , tC . url , g )
163204 if err != nil {
164205 t .Errorf ("No error was expected, got %s" , err )
165206 }
@@ -204,7 +245,7 @@ func TestExtractGitInfo_FailToGetProjectRemoteUrl(t *testing.T) {
204245 g := failingUrlManager {
205246 errMsg : tC .errMsg ,
206247 }
207- _ , err := NewGitData ("" , g )
248+ _ , err := NewGitData ("" , "" , g )
208249 if err == nil {
209250 t .Errorf ("Expected an error, got none" )
210251 }
@@ -236,7 +277,7 @@ func TestExtractGitInfo_FailToGetCurrentBranchName(t *testing.T) {
236277 },
237278 errMsg : tC .errMsg ,
238279 }
239- _ , err := NewGitData ("" , g )
280+ _ , err := NewGitData ("" , "" , g )
240281 if err == nil {
241282 t .Errorf ("Expected an error, got none" )
242283 }
0 commit comments