Skip to content

Commit c35147c

Browse files
author
Nont
committed
Remove Eventually and conflict check for Create and Delete
Signed-off-by: Nont <[email protected]>
1 parent c197f14 commit c35147c

File tree

1 file changed

+25
-37
lines changed

1 file changed

+25
-37
lines changed

test/e2e/webhook_test.go

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,33 +1304,27 @@ var _ = Describe("webhook tests for operations on ARM managed resources", Ordere
13041304
By("deleting the managed namespace")
13051305
ns := managedNamespace()
13061306
Expect(hubClient.Delete(ctx, &ns)).Should(SatisfyAny(Succeed(), utils.NotFoundMatcher{}), "Failed to delete the managed namespace")
1307-
Eventually(
1308-
func() error {
1309-
if err := hubClient.Get(ctx, types.NamespacedName{Name: ns.Name}, &corev1.Namespace{}); !k8sErrors.IsNotFound(err) {
1310-
return fmt.Errorf("The managed namespace still exists or an unexpected error occurred: %w", err)
1311-
}
1312-
return nil
1313-
}, workloadEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to remove the managed namespace %s", ns.Name)
1307+
Eventually(func() error {
1308+
if err := hubClient.Get(ctx, types.NamespacedName{Name: ns.Name}, &corev1.Namespace{}); !k8sErrors.IsNotFound(err) {
1309+
return fmt.Errorf("The managed namespace still exists or an unexpected error occurred: %w", err)
1310+
}
1311+
return nil
1312+
}, workloadEventuallyDuration, eventuallyInterval).Should(Succeed(), "Failed to remove the managed namespace %s", ns.Name)
13141313
})
13151314

13161315
It("should deny create a managed resource namespace", func() {
1317-
Eventually(func(g Gomega) error {
1318-
createNs := managedNamespace()
1319-
createNs.Name = "this-will-be-denied"
1320-
err := impersonateHubClient.Create(ctx, &createNs)
1321-
if k8sErrors.IsConflict(err) {
1322-
return err
1323-
}
1324-
var statusErr *k8sErrors.StatusError
1325-
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"))
1327-
return nil
1328-
}, testutils.PollTimeout, testutils.PollInterval).Should(Succeed())
1316+
createNs := managedNamespace()
1317+
createNs.Name = "this-will-be-denied"
1318+
err := impersonateHubClient.Create(ctx, &createNs)
1319+
var statusErr *k8sErrors.StatusError
1320+
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{})))
1321+
Expect(statusErr.ErrStatus.Message).Should(MatchRegexp(".*the operation on the managed resource type .* is not allowed"))
13291322
})
13301323

13311324
It("should deny update a managed resource namespace", func() {
13321325
Eventually(func(g Gomega) error {
13331326
updateNamespace := managedNamespace()
1327+
g.Expect(impersonateHubClient.Get(ctx, types.NamespacedName{Name: updateNamespace.Name}, &updateNamespace)).To(BeNil(), "Failed to get the created unmanaged namespace")
13341328
updateNamespace.Labels["foo"] = "NotManaged"
13351329
err := impersonateHubClient.Update(ctx, &updateNamespace)
13361330
if k8sErrors.IsConflict(err) {
@@ -1344,29 +1338,23 @@ var _ = Describe("webhook tests for operations on ARM managed resources", Ordere
13441338
})
13451339

13461340
It("should deny delete a managed resource namespace", func() {
1347-
Eventually(func(g Gomega) error {
1348-
created := managedNamespace()
1349-
err := impersonateHubClient.Delete(ctx, &created)
1350-
if k8sErrors.IsConflict(err) {
1351-
return err
1352-
}
1353-
var statusErr *k8sErrors.StatusError
1354-
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"))
1356-
return nil
1357-
}, testutils.PollTimeout, testutils.PollInterval).Should(Succeed())
1341+
created := managedNamespace()
1342+
err := impersonateHubClient.Delete(ctx, &created)
1343+
var statusErr *k8sErrors.StatusError
1344+
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{})))
1345+
Expect(statusErr.ErrStatus.Message).Should(MatchRegexp(".*the operation on the managed resource type .* is not allowed"))
13581346
})
13591347

13601348
It("should allow create/update/delete an unmanaged resource namespace", func() {
1349+
unmanaged := managedNamespace()
1350+
unmanaged.Name = "this-should-be-allowed"
1351+
delete(unmanaged.Labels, managedresource.ManagedByArmKey)
1352+
Expect(impersonateHubClient.Create(ctx, &unmanaged)).Should(SatisfyAny(Succeed(), utils.NotFoundMatcher{}), "Failed to create the unmanaged namespace")
13611353
Eventually(func(g Gomega) error {
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")
1354+
g.Expect(impersonateHubClient.Get(ctx, types.NamespacedName{Name: unmanaged.Name}, &unmanaged)).To(BeNil(), "Failed to get the created unmanaged namespace")
13661355
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
1356+
return impersonateHubClient.Update(ctx, &unmanaged)
13701357
}, testutils.PollTimeout, testutils.PollInterval).Should(Succeed())
1358+
Expect(impersonateHubClient.Delete(ctx, &unmanaged)).Should(SatisfyAny(Succeed(), utils.NotFoundMatcher{}), "Failed to delete the unmanaged namespace")
13711359
})
13721360
})

0 commit comments

Comments
 (0)