diff --git a/api/handlers/service_plan_test.go b/api/handlers/service_plan_test.go index 4d9eccb26..9d9091efd 100644 --- a/api/handlers/service_plan_test.go +++ b/api/handlers/service_plan_test.go @@ -5,6 +5,7 @@ import ( "net/http" "strings" + apierrors "code.cloudfoundry.org/korifi/api/errors" . "code.cloudfoundry.org/korifi/api/handlers" "code.cloudfoundry.org/korifi/api/handlers/fake" "code.cloudfoundry.org/korifi/api/payloads" diff --git a/api/repositories/service_plan_repository_test.go b/api/repositories/service_plan_repository_test.go index 6dc8bb316..d263400a6 100644 --- a/api/repositories/service_plan_repository_test.go +++ b/api/repositories/service_plan_repository_test.go @@ -608,6 +608,8 @@ var _ = Describe("ServicePlanRepo", func() { }) Describe("DeletePlanVisibility", func() { + var deleteMessage repositories.DeleteServicePlanVisibilityMessage + BeforeEach(func() { cfServicePlan := &korifiv1alpha1.CFServicePlan{ ObjectMeta: metav1.ObjectMeta{ @@ -619,13 +621,15 @@ var _ = Describe("ServicePlanRepo", func() { cfServicePlan.Spec.Visibility.Type = visibilityType cfServicePlan.Spec.Visibility.Organizations = []string{cfOrg.Name, anotherOrg.Name} })).To(Succeed()) - }) - JustBeforeEach(func() { - visibilityErr = repo.DeletePlanVisibility(ctx, authInfo, repositories.DeleteServicePlanVisibilityMessage{ + deleteMessage = repositories.DeleteServicePlanVisibilityMessage{ PlanGUID: planGUID, OrgGUID: anotherOrg.Name, - }) + } + }) + + JustBeforeEach(func() { + visibilityErr = repo.DeletePlanVisibility(ctx, authInfo, deleteMessage) }) When("the user is not authorized", func() { @@ -655,11 +659,8 @@ var _ = Describe("ServicePlanRepo", func() { }) When("the plan does not exist", func() { - JustBeforeEach(func() { - visibilityErr = repo.DeletePlanVisibility(ctx, authInfo, repositories.DeleteServicePlanVisibilityMessage{ - PlanGUID: "does-not-exist", - OrgGUID: anotherOrg.Name, - }) + BeforeEach(func() { + deleteMessage.PlanGUID = "does-not-exist" }) It("returns an NotFoundError", func() { @@ -668,11 +669,8 @@ var _ = Describe("ServicePlanRepo", func() { }) When("the org does not exist", func() { - JustBeforeEach(func() { - visibilityErr = repo.DeletePlanVisibility(ctx, authInfo, repositories.DeleteServicePlanVisibilityMessage{ - PlanGUID: planGUID, - OrgGUID: "does-not-exist", - }) + BeforeEach(func() { + deleteMessage.OrgGUID = "does-not-exist" }) It("does not change the visibility orgs", func() { @@ -685,7 +683,7 @@ var _ = Describe("ServicePlanRepo", func() { }, } Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(servicePlan), servicePlan)).To(Succeed()) - Expect(servicePlan.Spec.Visibility.Organizations).To(ConsistOf(cfOrg.Name)) + Expect(servicePlan.Spec.Visibility.Organizations).To(ConsistOf(cfOrg.Name, anotherOrg.Name)) }) }) }) diff --git a/tests/e2e/service_plans_test.go b/tests/e2e/service_plans_test.go index 45e282aca..d514926f0 100644 --- a/tests/e2e/service_plans_test.go +++ b/tests/e2e/service_plans_test.go @@ -124,9 +124,7 @@ var _ = Describe("Service Plans", func() { }) Describe("Delete Visibility", func() { - JustBeforeEach(func() { - var err error - + BeforeEach(func() { resp, err = adminClient.R(). SetBody(planVisibilityResource{ Type: "organization", @@ -139,7 +137,9 @@ var _ = Describe("Service Plans", func() { Expect(resp).To(SatisfyAll( HaveRestyStatusCode(http.StatusOK), )) + }) + JustBeforeEach(func() { resp, err = adminClient.R(). SetResult(&result). Delete(fmt.Sprintf("/v3/service_plans/%s/visibility/%s", planGUID, "org-guid"))