@@ -1302,7 +1302,7 @@ var _ = Describe("webhook tests for operations on ARM managed resources", Ordere
13021302
13031303 AfterAll (func () {
13041304 By ("deleting the managed namespace" )
1305- ns := createManagedNamespace ()
1305+ ns := managedNamespace ()
13061306 Expect (hubClient .Delete (ctx , & ns )).Should (SatisfyAny (Succeed (), utils.NotFoundMatcher {}), "Failed to delete the managed namespace" )
13071307 Eventually (
13081308 func () error {
@@ -1315,53 +1315,58 @@ var _ = Describe("webhook tests for operations on ARM managed resources", Ordere
13151315
13161316 It ("should deny create a managed resource namespace" , func () {
13171317 Eventually (func (g Gomega ) error {
1318- createNs := createManagedNamespace ()
1319- createNs .Name = fmt . Sprintf ( "test-create-managed-ns-%d" , GinkgoParallelProcess ())
1320- err := impersonateHubClient .Update (ctx , & createNs )
1318+ createNs := managedNamespace ()
1319+ createNs .Name = "this-will-be-denied"
1320+ err := impersonateHubClient .Create (ctx , & createNs )
13211321 if k8sErrors .IsConflict (err ) {
13221322 return err
13231323 }
13241324 var statusErr * k8sErrors.StatusError
13251325 g .Expect (errors .As (err , & statusErr )).To (BeTrue (), fmt .Sprintf ("Create managed namespace call produced error %s. Error type wanted is %s." , reflect .TypeOf (err ), reflect .TypeOf (& k8sErrors.StatusError {})))
1326- Expect (statusErr .ErrStatus .Message ).Should (MatchRegexp ("the operation on the managed resource type * is not allowed" ))
1326+ Expect (statusErr .ErrStatus .Message ).Should (MatchRegexp (".* the operation on the managed resource type . * is not allowed" ))
13271327 return nil
13281328 }, testutils .PollTimeout , testutils .PollInterval ).Should (Succeed ())
13291329 })
13301330
13311331 It ("should deny update a managed resource namespace" , func () {
13321332 Eventually (func (g Gomega ) error {
1333- updateNamespace := createManagedNamespace ()
1333+ updateNamespace := managedNamespace ()
13341334 updateNamespace .Labels ["foo" ] = "NotManaged"
13351335 err := impersonateHubClient .Update (ctx , & updateNamespace )
13361336 if k8sErrors .IsConflict (err ) {
13371337 return err
13381338 }
13391339 var statusErr * k8sErrors.StatusError
13401340 g .Expect (errors .As (err , & statusErr )).To (BeTrue (), fmt .Sprintf ("Update managed namespace call produced error %s. Error type wanted is %s." , reflect .TypeOf (err ), reflect .TypeOf (& k8sErrors.StatusError {})))
1341- Expect (statusErr .ErrStatus .Message ).Should (MatchRegexp ("the operation on the managed resource type * is not allowed" ))
1341+ Expect (statusErr .ErrStatus .Message ).Should (MatchRegexp (".* the operation on the managed resource type . * is not allowed" ))
13421342 return nil
13431343 }, testutils .PollTimeout , testutils .PollInterval ).Should (Succeed ())
13441344 })
13451345
13461346 It ("should deny delete a managed resource namespace" , func () {
13471347 Eventually (func (g Gomega ) error {
1348- created := createManagedNamespace ()
1348+ created := managedNamespace ()
13491349 err := impersonateHubClient .Delete (ctx , & created )
13501350 if k8sErrors .IsConflict (err ) {
13511351 return err
13521352 }
13531353 var statusErr * k8sErrors.StatusError
13541354 g .Expect (errors .As (err , & statusErr )).To (BeTrue (), fmt .Sprintf ("Delete managed namespace call produced error %s. Error type wanted is %s." , reflect .TypeOf (err ), reflect .TypeOf (& k8sErrors.StatusError {})))
1355- Expect (statusErr .ErrStatus .Message ).Should (MatchRegexp ("the operation on the managed resource type * is not allowed" ))
1355+ Expect (statusErr .ErrStatus .Message ).Should (MatchRegexp (".* the operation on the managed resource type . * is not allowed" ))
13561356 return nil
13571357 }, testutils .PollTimeout , testutils .PollInterval ).Should (Succeed ())
13581358 })
13591359
1360- It ("should allow create an unmanaged resource namespace" , func () {
1360+ It ("should allow create/update/delete an unmanaged resource namespace" , func () {
13611361 Eventually (func (g Gomega ) error {
1362- creating := createManagedNamespace ()
1363- delete (creating .Labels , managedresource .ManagedByArmKey )
1364- return impersonateHubClient .Create (ctx , & creating )
1362+ unmanaged := managedNamespace ()
1363+ unmanaged .Name = "this-should-be-allowed"
1364+ delete (unmanaged .Labels , managedresource .ManagedByArmKey )
1365+ g .Expect (impersonateHubClient .Create (ctx , & unmanaged )).Should (SatisfyAny (Succeed (), utils.NotFoundMatcher {}), "Failed to create the unmanaged namespace" )
1366+ unmanaged .Labels ["foo" ] = "NotManaged"
1367+ g .Expect (impersonateHubClient .Update (ctx , & unmanaged )).Should (SatisfyAny (Succeed (), utils.NotFoundMatcher {}), "Failed to update the unmanaged namespace" )
1368+ g .Expect (impersonateHubClient .Delete (ctx , & unmanaged )).Should (SatisfyAny (Succeed (), utils.NotFoundMatcher {}), "Failed to delete the unmanaged namespace" )
1369+ return nil
13651370 }, testutils .PollTimeout , testutils .PollInterval ).Should (Succeed ())
13661371 })
13671372})
0 commit comments