@@ -40,16 +40,23 @@ func GetAPIById(t *testing.T, client *apim.Client, username, password, apiId str
40
40
return client .GetAPI (apiId )
41
41
}
42
42
43
- func AddAPI (t * testing.T , client * apim.Client , username string , password string ) * apim.API {
43
+ func AddAPI (t * testing.T , client * apim.Client , username , password string ) * apim.API {
44
44
client .Login (username , password )
45
- api := client .GenerateSampleAPIData (username )
46
- doClean := true
47
- id := client .AddAPI (t , api , username , password , doClean )
45
+ api := client .GenerateSampleAPIData (username , "" , DevFirstDefaultAPIVersion , "" )
46
+ id := client .AddAPI (t , api , username , password , true )
47
+ api = client .GetAPI (id )
48
+ return api
49
+ }
50
+
51
+ func AddCustomAPI (t * testing.T , client * apim.Client , username , password , name , version , context string ) * apim.API {
52
+ client .Login (username , password )
53
+ api := client .GenerateSampleAPIData (username , name , version , context )
54
+ id := client .AddAPI (t , api , username , password , true )
48
55
api = client .GetAPI (id )
49
56
return api
50
57
}
51
58
52
- func UpdateAPI (t * testing.T , client * apim.Client , api * apim.API , username string , password string ) * apim.API {
59
+ func UpdateAPI (t * testing.T , client * apim.Client , api * apim.API , username , password string ) * apim.API {
53
60
client .Login (username , password )
54
61
id := client .UpdateAPI (t , api , username , password )
55
62
api = client .GetAPI (id )
@@ -139,7 +146,7 @@ func GetGatewayEnvironments(apiRevisions *apim.APIRevisionList) []string {
139
146
140
147
func AddAPIWithoutCleaning (t * testing.T , client * apim.Client , username string , password string ) * apim.API {
141
148
client .Login (username , password )
142
- api := client .GenerateSampleAPIData (username )
149
+ api := client .GenerateSampleAPIData (username , "" , DevFirstDefaultAPIVersion , "" )
143
150
doClean := false
144
151
id := client .AddAPI (t , api , username , password , doClean )
145
152
api = client .GetAPI (id )
@@ -148,7 +155,7 @@ func AddAPIWithoutCleaning(t *testing.T, client *apim.Client, username string, p
148
155
149
156
func AddAPIToTwoEnvs (t * testing.T , client1 * apim.Client , client2 * apim.Client , username string , password string ) (* apim.API , * apim.API ) {
150
157
client1 .Login (username , password )
151
- api := client1 .GenerateSampleAPIData (username )
158
+ api := client1 .GenerateSampleAPIData (username , "" , DevFirstDefaultAPIVersion , "" )
152
159
doClean := true
153
160
id1 := client1 .AddAPI (t , api , username , password , doClean )
154
161
api1 := client1 .GetAPI (id1 )
@@ -354,7 +361,7 @@ func ValidateAllApisOfATenantIsExported(t *testing.T, args *ApiImportExportTestA
354
361
})
355
362
}
356
363
357
- func importAPI (t * testing.T , args * ApiImportExportTestArgs ) (string , error ) {
364
+ func importAPI (t * testing.T , args * ApiImportExportTestArgs , doClean bool ) (string , error ) {
358
365
var fileName string
359
366
if args .ImportFilePath == "" {
360
367
fileName = base .GetAPIArchiveFilePath (t , args .SrcAPIM .GetEnvName (), args .Api .Name , args .Api .Version )
@@ -378,7 +385,7 @@ func importAPI(t *testing.T, args *ApiImportExportTestArgs) (string, error) {
378
385
379
386
output , err := base .Execute (t , params ... )
380
387
381
- if ! args .Update {
388
+ if ! args .Update && doClean {
382
389
t .Cleanup (func () {
383
390
if strings .EqualFold ("DEPRECATED" , args .Api .LifeCycleStatus ) {
384
391
args .CtlUser .Username , args .CtlUser .Password =
@@ -470,7 +477,7 @@ func ValidateAPIExportImport(t *testing.T, args *ApiImportExportTestArgs, apiTyp
470
477
// Import api to env 2
471
478
base .Login (t , args .DestAPIM .GetEnvName (), args .CtlUser .Username , args .CtlUser .Password )
472
479
473
- result , err := importAPI (t , args )
480
+ result , err := importAPI (t , args , true )
474
481
assert .Nil (t , err , "Error while importing the API" )
475
482
assert .Contains (t , result , "Successfully imported API" , "Error while importing the API" )
476
483
@@ -503,7 +510,7 @@ func ValidateAPIImportExportForAdvertiseOnlyAPI(t *testing.T, args *ApiImportExp
503
510
// Import api to env 2
504
511
base .Login (t , args .DestAPIM .GetEnvName (), args .CtlUser .Username , args .CtlUser .Password )
505
512
506
- result , err := importAPI (t , args )
513
+ result , err := importAPI (t , args , true )
507
514
assert .Nil (t , err , "Error while importing the API" )
508
515
assert .Contains (t , result , "Successfully imported API" , "Error while importing the API" )
509
516
@@ -533,7 +540,7 @@ func ValidateAPIRevisionExportImport(t *testing.T, args *ApiImportExportTestArgs
533
540
// Import api to env 2
534
541
base .Login (t , args .DestAPIM .GetEnvName (), args .CtlUser .Username , args .CtlUser .Password )
535
542
536
- importAPI (t , args )
543
+ importAPI (t , args , true )
537
544
538
545
// Give time for newly imported API to get indexed, or else GetAPI by name will fail
539
546
base .WaitForIndexing ()
@@ -732,7 +739,7 @@ func GetImportedAPI(t *testing.T, args *ApiImportExportTestArgs) *apim.API {
732
739
// Import api to env 2
733
740
base .Login (t , args .DestAPIM .GetEnvName (), args .CtlUser .Username , args .CtlUser .Password )
734
741
735
- _ , err := importAPI (t , args )
742
+ _ , err := importAPI (t , args , true )
736
743
737
744
if err != nil {
738
745
t .Fatal (err )
@@ -800,7 +807,7 @@ func ValidateAPIImport(t *testing.T, args *ApiImportExportTestArgs) {
800
807
// Import api to env 2
801
808
base .Login (t , args .DestAPIM .GetEnvName (), args .CtlUser .Username , args .CtlUser .Password )
802
809
803
- importAPI (t , args )
810
+ importAPI (t , args , true )
804
811
805
812
// Give time for newly imported API to get indexed, or else GetAPI by name will fail
806
813
base .WaitForIndexing ()
@@ -812,6 +819,40 @@ func ValidateAPIImport(t *testing.T, args *ApiImportExportTestArgs) {
812
819
validateAPIsEqualCrossTenant (t , args .Api , importedAPI )
813
820
}
814
821
822
+ func ValidateAPIImportForMultipleVersions (t * testing.T , args * ApiImportExportTestArgs , firstImportedAPIId string ) * apim.API {
823
+
824
+ t .Helper ()
825
+
826
+ isFirstImport := false
827
+ if strings .EqualFold (firstImportedAPIId , "" ) {
828
+ isFirstImport = true
829
+ }
830
+
831
+ // Add env2
832
+ base .SetupEnv (t , args .DestAPIM .GetEnvName (), args .DestAPIM .GetApimURL (), args .DestAPIM .GetTokenURL ())
833
+
834
+ // Import api to env 2
835
+ base .Login (t , args .DestAPIM .GetEnvName (), args .CtlUser .Username , args .CtlUser .Password )
836
+
837
+ importAPI (t , args , isFirstImport )
838
+
839
+ // Give time for newly imported API to get indexed, or else getAPI by name will fail
840
+ base .WaitForIndexing ()
841
+
842
+ if ! isFirstImport {
843
+ args .DestAPIM .DeleteAPI (firstImportedAPIId )
844
+ base .WaitForIndexing ()
845
+ }
846
+
847
+ // Get App from env 2
848
+ importedAPI := GetAPI (t , args .DestAPIM , args .Api .Name , args .ApiProvider .Username , args .ApiProvider .Password )
849
+
850
+ // Validate env 1 and env 2 API is equal
851
+ validateAPIsEqualCrossTenant (t , args .Api , importedAPI )
852
+
853
+ return importedAPI
854
+ }
855
+
815
856
func ValidateAPIImportFailure (t * testing.T , args * ApiImportExportTestArgs ) {
816
857
t .Helper ()
817
858
0 commit comments