@@ -115,7 +115,7 @@ func CheckIfUserExist(username, projecID string) func() bool {
115115 }
116116}
117117
118- func CompareClustersSpec (requested model.ClusterSpec , created mongodbatlas.Cluster ) { // TODO
118+ func CompareClustersSpec (requested model.ClusterSpec , created mongodbatlas.Cluster ) {
119119 ExpectWithOffset (1 , created ).To (MatchFields (IgnoreExtras , Fields {
120120 "MongoURI" : Not (BeEmpty ()),
121121 "MongoURIWithOptions" : Not (BeEmpty ()),
@@ -350,12 +350,12 @@ func CreateConnectionAtlasKey(data *model.TestDataProvider) {
350350 })
351351}
352352
353- func createConnectionAtlasKeyFrom (data * model.TestDataProvider , public , private string ) {
353+ func createConnectionAtlasKeyFrom (data * model.TestDataProvider , key * mongodbatlas. APIKey ) {
354354 By ("Change resources depends on AtlasKey and create key" , func () {
355355 if data .Resources .AtlasKeyAccessType .GlobalLevelKey {
356- kubecli .CreateApiKeySecretFrom (config .DefaultOperatorGlobalKey , data .Resources .Namespace , os .Getenv ("MCLI_ORG_ID" ), public , private )
356+ kubecli .CreateApiKeySecretFrom (config .DefaultOperatorGlobalKey , data .Resources .Namespace , os .Getenv ("MCLI_ORG_ID" ), key . PublicKey , key . PrivateKey )
357357 } else {
358- kubecli .CreateApiKeySecretFrom (data .Resources .KeyName , data .Resources .Namespace , os .Getenv ("MCLI_ORG_ID" ), public , private )
358+ kubecli .CreateApiKeySecretFrom (data .Resources .KeyName , data .Resources .Namespace , os .Getenv ("MCLI_ORG_ID" ), key . PublicKey , key . PrivateKey )
359359 }
360360 })
361361}
@@ -364,13 +364,14 @@ func recreateAtlasKeyIfNeed(data *model.TestDataProvider) {
364364 if ! data .Resources .AtlasKeyAccessType .IsFullAccess () {
365365 aClient , err := atlas .AClient ()
366366 Expect (err ).ShouldNot (HaveOccurred ())
367- public , private , err := aClient .AddKeyWithAccessList (data .Resources .ProjectID , data .Resources .AtlasKeyAccessType .Roles , data .Resources .AtlasKeyAccessType .Whitelist )
367+ globalKey , err := aClient .AddKeyWithAccessList (data .Resources .ProjectID , data .Resources .AtlasKeyAccessType .Roles , data .Resources .AtlasKeyAccessType .Whitelist )
368368 Expect (err ).ShouldNot (HaveOccurred ())
369- Expect (public ).ShouldNot (BeEmpty ())
370- Expect (private ).ShouldNot (BeEmpty ())
369+ Expect (globalKey .PublicKey ).ShouldNot (BeEmpty ())
370+ Expect (globalKey .PrivateKey ).ShouldNot (BeEmpty ())
371+ data .Resources .AtlasKeyAccessType .GlobalKeyAttached = globalKey
371372
372373 kubecli .DeleteApiKeySecret (data .Resources .KeyName , data .Resources .Namespace )
373- createConnectionAtlasKeyFrom (data , public , private )
374+ createConnectionAtlasKeyFrom (data , globalKey )
374375 }
375376}
376377
@@ -436,7 +437,7 @@ func DeployUserResourcesAction(data *model.TestDataProvider) {
436437 DeployUsers (data )
437438}
438439
439- func DeleteDBUsersApps (data * model.TestDataProvider ) {
440+ func DeleteDBUsersApps (data model.TestDataProvider ) {
440441 By ("Delete dbusers applications" , func () {
441442 for _ , user := range data .Resources .Users {
442443 helm .Uninstall ("test-app-" + user .Spec .Username , data .Resources .Namespace )
@@ -471,11 +472,23 @@ func DeleteUserResourcesProject(data *model.TestDataProvider) {
471472 })
472473}
473474
475+ func DeleteGlobalKeyIfExist (data model.TestDataProvider ) {
476+ if data .Resources .AtlasKeyAccessType .GlobalLevelKey {
477+ By ("Delete Global API key for test" , func () {
478+ client , err := atlas .AClient ()
479+ Expect (err ).ShouldNot (HaveOccurred ())
480+ err = client .DeleteGlobalKey (* data .Resources .AtlasKeyAccessType .GlobalKeyAttached )
481+ Expect (err ).ShouldNot (HaveOccurred ())
482+ })
483+ }
484+ }
485+
474486func AfterEachFinalCleanup (datas []model.TestDataProvider ) {
475- for i := range datas {
487+ for _ , data := range datas {
476488 GinkgoWriter .Write ([]byte ("AfterEach. Final cleanup...\n " ))
477- DeleteDBUsersApps (& datas [i ])
478- Expect (kubecli .DeleteNamespace (datas [i ].Resources .Namespace )).Should (Say ("deleted" ), "Cant delete namespace after testing" )
489+ DeleteDBUsersApps (data )
490+ Expect (kubecli .DeleteNamespace (data .Resources .Namespace )).Should (Say ("deleted" ), "Cant delete namespace after testing" )
491+ DeleteGlobalKeyIfExist (data )
479492 GinkgoWriter .Write ([]byte ("AfterEach. Cleanup finished\n " ))
480493 }
481494}
0 commit comments