@@ -3,8 +3,9 @@ package azure
33import (
44 "testing"
55
6- "github.com/akuity/kargo/internal/gitprovider"
76 "github.com/stretchr/testify/require"
7+
8+ "github.com/akuity/kargo/internal/gitprovider"
89)
910
1011func TestParseRepoURL (t * testing.T ) {
@@ -162,7 +163,7 @@ func TestNewProvider(t *testing.T) {
162163 testCases := []struct {
163164 name string
164165 args args
165- wantErr bool
166+ errExpected bool
166167 errContains string
167168 wantBaseUrl string
168169 wantProject string
@@ -171,68 +172,80 @@ func TestNewProvider(t *testing.T) {
171172 {
172173 name : "nil options" ,
173174 args : args {repoURL : "https://dev.azure.com/org/proj/_git/repo" , opts : nil },
174- wantErr : true ,
175+ errExpected : true ,
175176 errContains : "token is required" ,
176177 },
177178 {
178179 name : "empty token" ,
179180 args : args {repoURL : "https://dev.azure.com/org/proj/_git/repo" , opts : & gitprovider.Options {Token : "" }},
180- wantErr : true ,
181+ errExpected : true ,
181182 errContains : "token is required" ,
182183 },
183184 {
184- name : "invalid repo url" ,
185- args : args {repoURL : "not-a-url " , opts : & gitprovider.Options {Token : "token" }},
186- wantErr : true ,
187- errContains : "invalid Azure DevOps Server URL" ,
185+ name : "invalid repo url missing protocol " ,
186+ args : args {repoURL : ":dev.azure.com " , opts : & gitprovider.Options {Token : "token" }},
187+ errExpected : true ,
188+ errContains : "error parsing Azure DevOps repository URL" ,
188189 },
189190 {
190- name : "valid modern url" ,
191- args : args {repoURL : "https://dev.azure.com/org/proj/_git/repo" , opts : & gitprovider.Options {Token : "token" }},
192- wantErr : false ,
191+ name : "valid modern url" ,
192+ args : args {
193+ repoURL : "https://dev.azure.com/org/proj/_git/repo" ,
194+ opts : & gitprovider.Options {Token : "token" },
195+ },
196+ errExpected : false ,
193197 wantBaseUrl : "dev.azure.com" ,
194198 wantProject : "proj" ,
195199 wantRepo : "repo" ,
196200 },
197201 {
198- name : "valid legacy url" ,
199- args : args {repoURL : "https://org.visualstudio.com/proj/_git/repo" , opts : & gitprovider.Options {Token : "token" }},
200- wantErr : false ,
202+ name : "valid legacy url" ,
203+ args : args {
204+ repoURL : "https://org.visualstudio.com/proj/_git/repo" ,
205+ opts : & gitprovider.Options {Token : "token" },
206+ },
207+ errExpected : false ,
201208 wantBaseUrl : "dev.azure.com" ,
202209 wantProject : "proj" ,
203210 wantRepo : "repo" ,
204211 },
205212 {
206- name : "valid self-hosted url" ,
207- args : args {repoURL : "https://azure.mycompany.org/mycollection/myproject/_git/myrepo" , opts : & gitprovider.Options {Token : "token" }},
208- wantErr : false ,
213+ name : "valid self-hosted url" ,
214+ args : args {
215+ repoURL : "https://azure.mycompany.org/mycollection/myproject/_git/myrepo" ,
216+ opts : & gitprovider.Options {Token : "token" },
217+ },
218+ errExpected : false ,
209219 wantBaseUrl : "azure.mycompany.org" ,
210220 wantProject : "myproject" ,
211221 wantRepo : "myrepo" ,
212222 },
213223 {
214- name : "valid self-hosted url" ,
215- args : args {repoURL : "https://azure.mycompany.org/tfs/mycollection/myproject/_git/myrepo" , opts : & gitprovider.Options {Token : "token" }},
216- wantErr : false ,
224+ name : "valid self-hosted url" ,
225+ args : args {
226+ repoURL : "https://azure.mycompany.org/tfs/mycollection/myproject/_git/myrepo" ,
227+ opts : & gitprovider.Options {Token : "token" },
228+ },
229+ errExpected : false ,
217230 wantBaseUrl : "azure.mycompany.org/tfs" ,
218231 wantProject : "myproject" ,
219232 wantRepo : "myrepo" ,
220233 },
221234 {
222235 name : "invalid self-hosted url" ,
223236 args : args {repoURL : "https://azure.mycompany.org/foo/bar" , opts : & gitprovider.Options {Token : "token" }},
224- wantErr : true ,
237+ errExpected : true ,
225238 errContains : "invalid Azure DevOps Server URL" ,
226239 },
227240 }
228241
229- for _ , tt := range testCases {
230- t .Run (tt .name , func (t * testing.T ) {
231- got , err := NewProvider (tt .args .repoURL , tt .args .opts )
232- if tt . wantErr {
242+ for _ , tc := range testCases {
243+ t .Run (tc .name , func (t * testing.T ) {
244+ got , err := NewProvider (tc .args .repoURL , tc .args .opts )
245+ if tc . errExpected {
233246 require .Error (t , err )
234- if tt .errContains != "" {
235- require .Contains (t , err .Error (), tt .errContains )
247+ if tc .errContains != "" {
248+ require .Contains (t , err .Error (), tc .errContains )
236249 }
237250 require .Nil (t , got )
238251 } else {
@@ -241,10 +254,10 @@ func TestNewProvider(t *testing.T) {
241254 // Use type assertion to access internal fields for further validation
242255 p , ok := got .(* provider )
243256 require .True (t , ok )
244- require .Equal (t , tt .wantProject , p .project )
245- require .Equal (t , tt .wantRepo , p .repo )
257+ require .Equal (t , tc .wantProject , p .project )
258+ require .Equal (t , tc .wantRepo , p .repo )
246259 require .NotNil (t , p .connection )
247- require .NotNil (t , tt .wantBaseUrl , p .connection .BaseUrl )
260+ require .NotNil (t , tc .wantBaseUrl , p .connection .BaseUrl )
248261 }
249262 })
250263 }
0 commit comments