@@ -20,11 +20,7 @@ import (
2020func TestRegisterCFCluster (t * testing.T ) {
2121 t .Parallel ()
2222
23- mockV2Info := setupMockServer (t ,
24- msRoute ("/v2/info" ),
25- msMethod ("GET" ),
26- msStatus (http .StatusOK ),
27- msBody (jsonMust (mockV2InfoResponse )))
23+ mockV2Info := setupMockEndpointServer (t )
2824
2925 defer mockV2Info .Close ()
3026
@@ -64,11 +60,7 @@ func TestRegisterCFCluster(t *testing.T) {
6460func TestRegisterCFClusterWithMissingName (t * testing.T ) {
6561 t .Parallel ()
6662
67- mockV2Info := setupMockServer (t ,
68- msRoute ("/v2/info" ),
69- msMethod ("GET" ),
70- msStatus (http .StatusOK ),
71- msBody (jsonMust (mockV2InfoResponse )))
63+ mockV2Info := setupMockEndpointServer (t )
7264
7365 defer mockV2Info .Close ()
7466
@@ -104,11 +96,7 @@ func getCFPlugin(p *portalProxy, endpointType string) api.EndpointPlugin {
10496func TestRegisterCFClusterWithMissingAPIEndpoint (t * testing.T ) {
10597 t .Parallel ()
10698
107- mockV2Info := setupMockServer (t ,
108- msRoute ("/v2/info" ),
109- msMethod ("GET" ),
110- msStatus (http .StatusOK ),
111- msBody (jsonMust (mockV2InfoResponse )))
99+ mockV2Info := setupMockEndpointServer (t )
112100
113101 defer mockV2Info .Close ()
114102
@@ -128,11 +116,7 @@ func TestRegisterCFClusterWithMissingAPIEndpoint(t *testing.T) {
128116func TestRegisterCFClusterWithInvalidAPIEndpoint (t * testing.T ) {
129117 t .Parallel ()
130118
131- mockV2Info := setupMockServer (t ,
132- msRoute ("/v2/info" ),
133- msMethod ("GET" ),
134- msStatus (http .StatusOK ),
135- msBody (jsonMust (mockV2InfoResponse )))
119+ mockV2Info := setupMockEndpointServer (t )
136120
137121 defer mockV2Info .Close ()
138122
@@ -180,11 +164,7 @@ func TestRegisterCFClusterWithBadV2Request(t *testing.T) {
180164func TestRegisterCFClusterButCantSaveCNSIRecord (t * testing.T ) {
181165 t .Parallel ()
182166
183- mockV2Info := setupMockServer (t ,
184- msRoute ("/v2/info" ),
185- msMethod ("GET" ),
186- msStatus (http .StatusOK ),
187- msBody (jsonMust (mockV2InfoResponse )))
167+ mockV2Info := setupMockEndpointServer (t )
188168
189169 defer mockV2Info .Close ()
190170
@@ -287,16 +267,8 @@ func TestRegisterWithUserEndpointsEnabled(t *testing.T) {
287267 defer db .Close ()
288268
289269 // mock individual APIEndpoints
290- mockV2Info := []* httptest.Server {}
291- for i := 0 ; i < 1 ; i ++ {
292- server := setupMockServer (t ,
293- msRoute ("/v2/info" ),
294- msMethod ("GET" ),
295- msStatus (http .StatusOK ),
296- msBody (jsonMust (mockV2InfoResponse )))
297- defer server .Close ()
298- mockV2Info = append (mockV2Info , server )
299- }
270+ mockV2Info := setupMockEndpointServer (t )
271+ defer mockV2Info .Close ()
300272
301273 // mock different users
302274 mockAdmin := setupMockUser (mockAdminGUID , true , []string {})
@@ -310,7 +282,7 @@ func TestRegisterWithUserEndpointsEnabled(t *testing.T) {
310282 Convey ("as admin" , func () {
311283 Convey ("with createSystemEndpoint enabled" , func () {
312284 // setup
313- adminEndpoint := setupMockEndpointRegisterRequest (t , mockAdmin .ConnectedUser , mockV2Info [ 0 ] , "CF Cluster 1" , true , true )
285+ adminEndpoint := setupMockEndpointRegisterRequest (t , mockAdmin .ConnectedUser , mockV2Info , "CF Cluster 1" , true , true )
314286
315287 if errSession := pp .setSessionValues (adminEndpoint .EchoContext , mockAdmin .SessionValues ); errSession != nil {
316288 t .Error (errors .New ("unable to mock/stub user in session object" ))
@@ -324,7 +296,7 @@ func TestRegisterWithUserEndpointsEnabled(t *testing.T) {
324296
325297 // return no already saved endpoints
326298 rows := testutils .GetEmptyCNSIRows ()
327- mock .ExpectQuery (selectAnyFromCNSIs ).WithArgs (mockV2Info [ 0 ] .URL ).WillReturnRows (rows )
299+ mock .ExpectQuery (selectAnyFromCNSIs ).WithArgs (mockV2Info .URL ).WillReturnRows (rows )
328300
329301 mock .ExpectExec (insertIntoCNSIs ).
330302 WithArgs (adminEndpoint .InsertArgs ... ).
@@ -344,7 +316,7 @@ func TestRegisterWithUserEndpointsEnabled(t *testing.T) {
344316 })
345317 Convey ("create system endpoint over existing user endpoints" , func () {
346318 // setup
347- userEndpoint := setupMockEndpointRegisterRequest (t , mockUser1 .ConnectedUser , mockV2Info [ 0 ] , "CF Cluster 1 User" , false , false )
319+ userEndpoint := setupMockEndpointRegisterRequest (t , mockUser1 .ConnectedUser , mockV2Info , "CF Cluster 1 User" , false , false )
348320
349321 // mock executions
350322 mockStratosAuth .
@@ -354,7 +326,7 @@ func TestRegisterWithUserEndpointsEnabled(t *testing.T) {
354326
355327 // return a user endpoint with same apiurl
356328 rows := testutils .GetEmptyCNSIRows ().AddRow (userEndpoint .QueryArgs ... )
357- mock .ExpectQuery (selectAnyFromCNSIs ).WithArgs (mockV2Info [ 0 ] .URL ).WillReturnRows (rows )
329+ mock .ExpectQuery (selectAnyFromCNSIs ).WithArgs (mockV2Info .URL ).WillReturnRows (rows )
358330
359331 // save cnsi
360332 mock .ExpectExec (insertIntoCNSIs ).
@@ -382,7 +354,7 @@ func TestRegisterWithUserEndpointsEnabled(t *testing.T) {
382354
383355 // return a admin endpoint with same apiurl
384356 rows := testutils .GetEmptyCNSIRows ().AddRow (adminEndpoint .QueryArgs ... )
385- mock .ExpectQuery (selectAnyFromCNSIs ).WithArgs (mockV2Info [ 0 ] .URL ).WillReturnRows (rows )
357+ mock .ExpectQuery (selectAnyFromCNSIs ).WithArgs (mockV2Info .URL ).WillReturnRows (rows )
386358
387359 // test
388360 err := pp .RegisterEndpoint (adminEndpoint .EchoContext , getCFPlugin (pp , "cf" ).Info )
@@ -404,8 +376,8 @@ func TestRegisterWithUserEndpointsEnabled(t *testing.T) {
404376 Convey ("with createSystemEndpoint disabled" , func () {
405377
406378 // setup
407- adminEndpoint := setupMockEndpointRegisterRequest (t , mockAdmin .ConnectedUser , mockV2Info [ 0 ] , "CF Cluster 1" , false , false )
408- systemEndpoint := setupMockEndpointRegisterRequest (t , mockAdmin .ConnectedUser , mockV2Info [ 0 ] , "CF Cluster 1" , false , true )
379+ adminEndpoint := setupMockEndpointRegisterRequest (t , mockAdmin .ConnectedUser , mockV2Info , "CF Cluster 1" , false , false )
380+ systemEndpoint := setupMockEndpointRegisterRequest (t , mockAdmin .ConnectedUser , mockV2Info , "CF Cluster 1" , false , true )
409381
410382 if errSession := pp .setSessionValues (adminEndpoint .EchoContext , mockAdmin .SessionValues ); errSession != nil {
411383 t .Error (errors .New ("unable to mock/stub user in session object" ))
@@ -420,7 +392,7 @@ func TestRegisterWithUserEndpointsEnabled(t *testing.T) {
420392
421393 // return a admin endpoint with same apiurl
422394 rows := testutils .GetEmptyCNSIRows ().AddRow (systemEndpoint .QueryArgs ... )
423- mock .ExpectQuery (selectAnyFromCNSIs ).WithArgs (mockV2Info [ 0 ] .URL ).WillReturnRows (rows )
395+ mock .ExpectQuery (selectAnyFromCNSIs ).WithArgs (mockV2Info .URL ).WillReturnRows (rows )
424396
425397 // save cnsi
426398 mock .ExpectExec (insertIntoCNSIs ).
@@ -448,7 +420,7 @@ func TestRegisterWithUserEndpointsEnabled(t *testing.T) {
448420
449421 // return a user endpoint with same apiurl
450422 rows := testutils .GetEmptyCNSIRows ().AddRow (adminEndpoint .QueryArgs ... )
451- mock .ExpectQuery (selectAnyFromCNSIs ).WithArgs (mockV2Info [ 0 ] .URL ).WillReturnRows (rows )
423+ mock .ExpectQuery (selectAnyFromCNSIs ).WithArgs (mockV2Info .URL ).WillReturnRows (rows )
452424
453425 // test
454426 err := pp .RegisterEndpoint (adminEndpoint .EchoContext , getCFPlugin (pp , "cf" ).Info )
@@ -472,7 +444,7 @@ func TestRegisterWithUserEndpointsEnabled(t *testing.T) {
472444 Convey ("as user" , func () {
473445 Convey ("with createSystemEndpoint enabled" , func () {
474446 // setup
475- userEndpoint := setupMockEndpointRegisterRequest (t , mockUser1 .ConnectedUser , mockV2Info [ 0 ] , "CF Cluster 1" , true , false )
447+ userEndpoint := setupMockEndpointRegisterRequest (t , mockUser1 .ConnectedUser , mockV2Info , "CF Cluster 1" , true , false )
476448
477449 if errSession := pp .setSessionValues (userEndpoint .EchoContext , mockUser1 .SessionValues ); errSession != nil {
478450 t .Error (errors .New ("unable to mock/stub user in session object" ))
@@ -486,7 +458,7 @@ func TestRegisterWithUserEndpointsEnabled(t *testing.T) {
486458 Return (mockUser1 .ConnectedUser , nil )
487459
488460 rows := testutils .GetEmptyCNSIRows ()
489- mock .ExpectQuery (selectAnyFromCNSIs ).WithArgs (mockV2Info [ 0 ] .URL ).WillReturnRows (rows )
461+ mock .ExpectQuery (selectAnyFromCNSIs ).WithArgs (mockV2Info .URL ).WillReturnRows (rows )
490462
491463 mock .ExpectExec (insertIntoCNSIs ).
492464 WithArgs (userEndpoint .InsertArgs ... ).
@@ -504,7 +476,7 @@ func TestRegisterWithUserEndpointsEnabled(t *testing.T) {
504476 })
505477 })
506478 Convey ("register existing endpoint from different user" , func () {
507- userEndpoint2 := setupMockEndpointRegisterRequest (t , mockUser2 .ConnectedUser , mockV2Info [ 0 ] , "CF Cluster 2" , false , false )
479+ userEndpoint2 := setupMockEndpointRegisterRequest (t , mockUser2 .ConnectedUser , mockV2Info , "CF Cluster 2" , false , false )
508480
509481 // mock executions
510482 mockStratosAuth .
@@ -513,7 +485,7 @@ func TestRegisterWithUserEndpointsEnabled(t *testing.T) {
513485 Return (mockUser1 .ConnectedUser , nil )
514486
515487 rows := testutils .GetEmptyCNSIRows ().AddRow (userEndpoint2 .QueryArgs ... )
516- mock .ExpectQuery (selectAnyFromCNSIs ).WithArgs (mockV2Info [ 0 ] .URL ).WillReturnRows (rows )
488+ mock .ExpectQuery (selectAnyFromCNSIs ).WithArgs (mockV2Info .URL ).WillReturnRows (rows )
517489
518490 mock .ExpectExec (insertIntoCNSIs ).
519491 WithArgs (userEndpoint .InsertArgs ... ).
@@ -538,7 +510,7 @@ func TestRegisterWithUserEndpointsEnabled(t *testing.T) {
538510 Return (mockUser1 .ConnectedUser , nil )
539511
540512 rows := testutils .GetEmptyCNSIRows ().AddRow (userEndpoint .QueryArgs ... )
541- mock .ExpectQuery (selectAnyFromCNSIs ).WithArgs (mockV2Info [ 0 ] .URL ).WillReturnRows (rows )
513+ mock .ExpectQuery (selectAnyFromCNSIs ).WithArgs (mockV2Info .URL ).WillReturnRows (rows )
542514
543515 err := pp .RegisterEndpoint (userEndpoint .EchoContext , getCFPlugin (pp , "cf" ).Info )
544516 dberr := mock .ExpectationsWereMet ()
@@ -557,7 +529,7 @@ func TestRegisterWithUserEndpointsEnabled(t *testing.T) {
557529 })
558530 })
559531 Convey ("with createSystemEndpoint disabled" , func () {
560- userEndpoint := setupMockEndpointRegisterRequest (t , mockUser1 .ConnectedUser , mockV2Info [ 0 ] , "CF Cluster 1" , false , false )
532+ userEndpoint := setupMockEndpointRegisterRequest (t , mockUser1 .ConnectedUser , mockV2Info , "CF Cluster 1" , false , false )
561533
562534 if errSession := pp .setSessionValues (userEndpoint .EchoContext , mockUser1 .SessionValues ); errSession != nil {
563535 t .Error (errors .New ("unable to mock/stub user in session object" ))
@@ -570,7 +542,7 @@ func TestRegisterWithUserEndpointsEnabled(t *testing.T) {
570542 Return (mockUser1 .ConnectedUser , nil )
571543
572544 rows := testutils .GetEmptyCNSIRows ().AddRow (userEndpoint .QueryArgs ... )
573- mock .ExpectQuery (selectAnyFromCNSIs ).WithArgs (mockV2Info [ 0 ] .URL ).WillReturnRows (rows )
545+ mock .ExpectQuery (selectAnyFromCNSIs ).WithArgs (mockV2Info .URL ).WillReturnRows (rows )
574546
575547 err := pp .RegisterEndpoint (userEndpoint .EchoContext , getCFPlugin (pp , "cf" ).Info )
576548 dberr := mock .ExpectationsWereMet ()
0 commit comments