diff --git a/api/handlers/handlers_suite_test.go b/api/handlers/handlers_suite_test.go index 1f6f45c6d..ee899f456 100644 --- a/api/handlers/handlers_suite_test.go +++ b/api/handlers/handlers_suite_test.go @@ -52,9 +52,11 @@ var _ = BeforeEach(func() { }) func expectErrorResponse(status int, title, detail string, code int) { - ExpectWithOffset(2, rr).To(HaveHTTPStatus(status)) - ExpectWithOffset(2, rr).To(HaveHTTPHeaderWithValue("Content-Type", "application/json")) - ExpectWithOffset(2, rr).To(HaveHTTPBody(SatisfyAll( + GinkgoHelper() + + Expect(rr).To(HaveHTTPStatus(status)) + Expect(rr).To(HaveHTTPHeaderWithValue("Content-Type", "application/json")) + Expect(rr).To(HaveHTTPBody(SatisfyAll( MatchJSONPath("$.errors[0].title", MatchRegexp(title)), MatchJSONPath("$.errors[0].detail", MatchRegexp(detail)), MatchJSONPath("$.errors[0].code", BeEquivalentTo(code)), @@ -62,30 +64,44 @@ func expectErrorResponse(status int, title, detail string, code int) { } func expectUnknownError() { + GinkgoHelper() + expectErrorResponse(http.StatusInternalServerError, "UnknownError", "An unknown error occurred.", 10001) } func expectNotAuthorizedError() { + GinkgoHelper() + expectErrorResponse(http.StatusForbidden, "CF-NotAuthorized", "You are not authorized to perform the requested action", 10003) } func expectNotFoundError(resourceType string) { + GinkgoHelper() + expectErrorResponse(http.StatusNotFound, "CF-ResourceNotFound", resourceType+" not found. Ensure it exists and you have access to it.", 10010) } func expectUnprocessableEntityError(detail string) { + GinkgoHelper() + expectErrorResponse(http.StatusUnprocessableEntity, "CF-UnprocessableEntity", detail, 10008) } func expectBadRequestError() { + GinkgoHelper() + expectErrorResponse(http.StatusBadRequest, "CF-MessageParseError", "Request invalid due to parse error: invalid request body", 1001) } func expectBlobstoreUnavailableError() { + GinkgoHelper() + expectErrorResponse(http.StatusBadGateway, "CF-BlobstoreUnavailable", "Error uploading source package to the container registry", 150006) } func expectUnknownKeyError(detail string) { + GinkgoHelper() + expectErrorResponse(http.StatusBadRequest, "CF-BadQueryParameter", detail, 10005) } @@ -97,6 +113,8 @@ func generateGUID(prefix string) string { func decodeAndValidateJSONPayloadStub[T any](desiredPayload *T) func(_ *http.Request, decodedPayload any) error { return func(_ *http.Request, decodedPayload any) error { + GinkgoHelper() + decodedPayloadPtr, ok := decodedPayload.(*T) Expect(ok).To(BeTrue()) @@ -113,6 +131,8 @@ type keyedPayloadImpl[P any] interface { func decodeAndValidateURLValuesStub[P any, I keyedPayloadImpl[P]](desiredPayload I) func(*http.Request, handlers.KeyedPayload) error { return func(_ *http.Request, output handlers.KeyedPayload) error { + GinkgoHelper() + outputPtr, ok := output.(I) Expect(ok).To(BeTrue()) diff --git a/api/payloads/payloads_suite_test.go b/api/payloads/payloads_suite_test.go index 643e16580..468eb964c 100644 --- a/api/payloads/payloads_suite_test.go +++ b/api/payloads/payloads_suite_test.go @@ -8,6 +8,7 @@ import ( apierrors "code.cloudfoundry.org/korifi/api/errors" "code.cloudfoundry.org/korifi/api/handlers" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) @@ -26,12 +27,16 @@ func TestPayloads(t *testing.T) { } func expectUnprocessableEntityError(err error, detail string) { - ExpectWithOffset(1, err).To(HaveOccurred()) - ExpectWithOffset(1, err).To(BeAssignableToTypeOf(apierrors.UnprocessableEntityError{})) - ExpectWithOffset(1, err.(apierrors.UnprocessableEntityError).Detail()).To(ContainSubstring(detail)) + GinkgoHelper() + + Expect(err).To(HaveOccurred()) + Expect(err).To(BeAssignableToTypeOf(apierrors.UnprocessableEntityError{})) + Expect(err.(apierrors.UnprocessableEntityError).Detail()).To(ContainSubstring(detail)) } func createRequest(payload any) *http.Request { + GinkgoHelper() + body, err := json.Marshal(payload) Expect(err).NotTo(HaveOccurred()) diff --git a/api/repositories/role_repository_test.go b/api/repositories/role_repository_test.go index 8d4a036e9..1cf9769af 100644 --- a/api/repositories/role_repository_test.go +++ b/api/repositories/role_repository_test.go @@ -11,7 +11,6 @@ import ( "code.cloudfoundry.org/korifi/api/repositories/fake" korifiv1alpha1 "code.cloudfoundry.org/korifi/controllers/api/v1alpha1" "code.cloudfoundry.org/korifi/tests/matchers" - "sigs.k8s.io/controller-runtime/pkg/client" "github.com/google/uuid" . "github.com/onsi/ginkgo/v2" @@ -20,6 +19,7 @@ import ( rbacv1 "k8s.io/api/rbac/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" + "sigs.k8s.io/controller-runtime/pkg/client" ) var _ = Describe("RoleRepository", func() { @@ -58,8 +58,10 @@ var _ = Describe("RoleRepository", func() { }) getTheRoleBinding := func(name, namespace string) rbacv1.RoleBinding { + GinkgoHelper() + roleBinding := rbacv1.RoleBinding{} - ExpectWithOffset(1, k8sClient.Get(ctx, types.NamespacedName{Name: name, Namespace: namespace}, &roleBinding)).To(Succeed()) + Expect(k8sClient.Get(ctx, types.NamespacedName{Name: name, Namespace: namespace}, &roleBinding)).To(Succeed()) return roleBinding } diff --git a/api/repositories/task_repository_test.go b/api/repositories/task_repository_test.go index b26f062c9..f4203fa26 100644 --- a/api/repositories/task_repository_test.go +++ b/api/repositories/task_repository_test.go @@ -7,13 +7,13 @@ import ( "time" "code.cloudfoundry.org/korifi/tools/k8s" - "code.cloudfoundry.org/korifi/api/authorization" apierrors "code.cloudfoundry.org/korifi/api/errors" "code.cloudfoundry.org/korifi/api/repositories" "code.cloudfoundry.org/korifi/api/repositories/conditions" korifiv1alpha1 "code.cloudfoundry.org/korifi/controllers/api/v1alpha1" "code.cloudfoundry.org/korifi/tests/matchers" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" @@ -33,6 +33,8 @@ var _ = Describe("TaskRepository", func() { ) setStatusAndUpdate := func(task *korifiv1alpha1.CFTask, conditionTypes ...string) { + GinkgoHelper() + if task.Status.Conditions == nil { task.Status.Conditions = []metav1.Condition{} } @@ -46,7 +48,7 @@ var _ = Describe("TaskRepository", func() { }) } - ExpectWithOffset(1, k8sClient.Status().Update(ctx, task)).To(Succeed()) + Expect(k8sClient.Status().Update(ctx, task)).To(Succeed()) } defaultStatusValues := func(task *korifiv1alpha1.CFTask, seqId int64, dropletId string) *korifiv1alpha1.CFTask { diff --git a/controllers/controllers/workloads/cfbuild_controller_test.go b/controllers/controllers/workloads/cfbuild_controller_test.go index 8cba8922d..c0da57101 100644 --- a/controllers/controllers/workloads/cfbuild_controller_test.go +++ b/controllers/controllers/workloads/cfbuild_controller_test.go @@ -38,7 +38,9 @@ var _ = Describe("CFBuildReconciler Integration Tests", func() { ) eventuallyBuildWorkloadShould := func(assertion func(*korifiv1alpha1.BuildWorkload, Gomega)) { - EventuallyWithOffset(1, func(g Gomega) { + GinkgoHelper() + + Eventually(func(g Gomega) { workload := new(korifiv1alpha1.BuildWorkload) lookupKey := types.NamespacedName{Name: cfBuildGUID, Namespace: cfSpace.Status.GUID} g.Expect(k8sClient.Get(context.Background(), lookupKey, workload)).To(Succeed()) diff --git a/controllers/controllers/workloads/cfprocess_controller_test.go b/controllers/controllers/workloads/cfprocess_controller_test.go index fb6e85300..cc5840c2e 100644 --- a/controllers/controllers/workloads/cfprocess_controller_test.go +++ b/controllers/controllers/workloads/cfprocess_controller_test.go @@ -574,7 +574,9 @@ var _ = Describe("CFProcessReconciler Integration Tests", func() { }) func eventuallyCreatedAppWorkloadShould(processGUID, namespace string, shouldFn func(Gomega, korifiv1alpha1.AppWorkload)) { - EventuallyWithOffset(1, func(g Gomega) { + GinkgoHelper() + + Eventually(func(g Gomega) { var appWorkloads korifiv1alpha1.AppWorkloadList err := k8sClient.List(context.Background(), &appWorkloads, client.InNamespace(namespace), client.MatchingLabels{ korifiv1alpha1.CFProcessGUIDLabelKey: processGUID, diff --git a/kpack-image-builder/controllers/buildworkload_controller_test.go b/kpack-image-builder/controllers/buildworkload_controller_test.go index 559df2a93..b345ff6e2 100644 --- a/kpack-image-builder/controllers/buildworkload_controller_test.go +++ b/kpack-image-builder/controllers/buildworkload_controller_test.go @@ -1014,8 +1014,10 @@ func buildWorkloadObject(buildWorkloadGUID string, namespace string, source kori } func mustHaveCondition(g Gomega, conditions []metav1.Condition, conditionType string) *metav1.Condition { + GinkgoHelper() + foundCondition := meta.FindStatusCondition(conditions, conditionType) - g.ExpectWithOffset(1, foundCondition).NotTo(BeNil()) + g.Expect(foundCondition).NotTo(BeNil()) return foundCondition } diff --git a/tests/e2e/e2e_suite_test.go b/tests/e2e/e2e_suite_test.go index b021aa689..35b689cf1 100644 --- a/tests/e2e/e2e_suite_test.go +++ b/tests/e2e/e2e_suite_test.go @@ -22,9 +22,8 @@ import ( "github.com/google/uuid" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - _ "k8s.io/client-go/plugin/pkg/client/auth" - "gopkg.in/yaml.v3" + _ "k8s.io/client-go/plugin/pkg/client/auth" logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/log/zap" ) @@ -342,8 +341,10 @@ var _ = BeforeEach(func() { }) func mustHaveEnv(key string) string { + GinkgoHelper() + val, ok := os.LookupEnv(key) - ExpectWithOffset(1, ok).To(BeTrue(), "must set env var %q", key) + Expect(ok).To(BeTrue(), "must set env var %q", key) return val } @@ -358,6 +359,8 @@ func getEnv(key, defaultValue string) string { } func makeClient(certEnvVar, tokenEnvVar string) *helpers.CorrelatedRestyClient { + GinkgoHelper() + cert := os.Getenv(certEnvVar) if cert != "" { return helpers.NewCorrelatedRestyClient(apiServerRoot, getCorrelationId).SetAuthScheme("ClientCert").SetAuthToken(cert).SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true}) @@ -373,7 +376,9 @@ func makeClient(certEnvVar, tokenEnvVar string) *helpers.CorrelatedRestyClient { } func ensureServerIsUp() { - EventuallyWithOffset(1, func() (int, error) { + GinkgoHelper() + + Eventually(func() (int, error) { http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true} resp, err := http.Get(apiServerRoot) if err != nil { @@ -393,14 +398,16 @@ func generateGUID(prefix string) string { } func deleteOrg(guid string) { + GinkgoHelper() + if guid == "" { return } resp, err := adminClient.R(). Delete("/v3/organizations/" + guid) - ExpectWithOffset(1, err).NotTo(HaveOccurred()) - ExpectWithOffset(1, resp).To(HaveRestyStatusCode(http.StatusAccepted)) + Expect(err).NotTo(HaveOccurred()) + Expect(resp).To(HaveRestyStatusCode(http.StatusAccepted)) } func createOrgRaw(orgName string) (string, error) { @@ -420,8 +427,10 @@ func createOrgRaw(orgName string) (string, error) { } func createOrg(orgName string) string { + GinkgoHelper() + orgGUID, err := createOrgRaw(orgName) - ExpectWithOffset(1, err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred()) return orgGUID } @@ -463,24 +472,30 @@ func createSpaceRaw(spaceName, orgGUID string) (string, error) { } func deleteSpace(guid string) { + GinkgoHelper() + if guid == "" { return } resp, err := adminClient.R(). Delete("/v3/spaces/" + guid) - ExpectWithOffset(1, err).NotTo(HaveOccurred()) - ExpectWithOffset(1, resp).To(HaveRestyStatusCode(http.StatusAccepted)) + Expect(err).NotTo(HaveOccurred()) + Expect(resp).To(HaveRestyStatusCode(http.StatusAccepted)) } func createSpace(spaceName, orgGUID string) string { + GinkgoHelper() + spaceGUID, err := createSpaceRaw(spaceName, orgGUID) - ExpectWithOffset(1, err).NotTo(HaveOccurred(), `create space "`+spaceName+`" in orgGUID "`+orgGUID+`" should have succeeded`) + Expect(err).NotTo(HaveOccurred(), `create space "`+spaceName+`" in orgGUID "`+orgGUID+`" should have succeeded`) return spaceGUID } func applySpaceManifest(manifest manifestResource, spaceGUID string) { + GinkgoHelper() + manifestBytes, err := yaml.Marshal(manifest) Expect(err).NotTo(HaveOccurred()) resp, err := adminClient.R(). @@ -508,6 +523,8 @@ func asyncCreateSpace(spaceName, orgGUID string, createdSpaceGUID *string, wg *s // createRole creates an org or space role // You should probably invoke this via createOrgRole or createSpaceRole func createRole(roleName, orgSpaceType, userName, orgSpaceGUID string) string { + GinkgoHelper() + rolesURL := apiServerRoot + "/v3/roles" payload := typedResource{ @@ -535,14 +552,20 @@ func createRole(roleName, orgSpaceType, userName, orgSpaceGUID string) string { } func createOrgRole(roleName, userName, orgGUID string) string { + GinkgoHelper() + return createRole(roleName, "organization", userName, orgGUID) } func createSpaceRole(roleName, userName, spaceGUID string) string { + GinkgoHelper() + return createRole(roleName, "space", userName, spaceGUID) } func createApp(spaceGUID, name string) string { + GinkgoHelper() + var app resource resp, err := adminClient.R(). @@ -555,8 +578,8 @@ func createApp(spaceGUID, name string) string { SetResult(&app). Post("/v3/apps") - ExpectWithOffset(1, err).NotTo(HaveOccurred()) - ExpectWithOffset(1, resp).To(HaveRestyStatusCode(http.StatusCreated)) + Expect(err).NotTo(HaveOccurred()) + Expect(resp).To(HaveRestyStatusCode(http.StatusCreated)) Expect(app.GUID).NotTo(BeEmpty()) Expect(app.Name).To(Equal(name)) Expect(app.CreatedAt).NotTo(BeEmpty()) @@ -568,6 +591,8 @@ func createApp(spaceGUID, name string) string { } func setEnv(appName string, envVars map[string]interface{}) { + GinkgoHelper() + resp, err := adminClient.R(). SetBody( struct { @@ -578,26 +603,30 @@ func setEnv(appName string, envVars map[string]interface{}) { ). SetPathParam("appName", appName). Patch("/v3/apps/{appName}/environment_variables") - ExpectWithOffset(1, err).NotTo(HaveOccurred()) - ExpectWithOffset(1, resp).To(HaveRestyStatusCode(http.StatusOK)) + Expect(err).NotTo(HaveOccurred()) + Expect(resp).To(HaveRestyStatusCode(http.StatusOK)) } func getAppEnv(appName string) map[string]interface{} { + GinkgoHelper() + var env map[string]interface{} resp, err := adminClient.R(). SetResult(&env). SetPathParam("appName", appName). Get("/v3/apps/{appName}/env") - ExpectWithOffset(1, err).NotTo(HaveOccurred()) - ExpectWithOffset(1, resp).To(HaveRestyStatusCode(http.StatusOK)) + Expect(err).NotTo(HaveOccurred()) + Expect(resp).To(HaveRestyStatusCode(http.StatusOK)) return env } func getApp(appGUID string) appResource { + GinkgoHelper() + var app appResource - EventuallyWithOffset(1, func(g Gomega) { + Eventually(func(g Gomega) { resp, err := adminClient.R(). SetResult(&app). Get("/v3/apps/" + appGUID) @@ -610,8 +639,10 @@ func getApp(appGUID string) appResource { } func getProcess(appGUID, processType string) processResource { + GinkgoHelper() + var process processResource - EventuallyWithOffset(1, func(g Gomega) { + Eventually(func(g Gomega) { resp, err := adminClient.R(). SetResult(&process). Get("/v3/apps/" + appGUID + "/processes/" + processType) @@ -624,6 +655,8 @@ func getProcess(appGUID, processType string) processResource { } func createServiceInstance(spaceGUID, name string, credentials map[string]string) string { + GinkgoHelper() + var serviceInstance typedResource resp, err := adminClient.R(). @@ -638,13 +671,15 @@ func createServiceInstance(spaceGUID, name string, credentials map[string]string SetResult(&serviceInstance). Post("/v3/service_instances") - ExpectWithOffset(1, err).NotTo(HaveOccurred()) - ExpectWithOffset(1, resp.StatusCode()).To(Equal(http.StatusCreated)) + Expect(err).NotTo(HaveOccurred()) + Expect(resp.StatusCode()).To(Equal(http.StatusCreated)) return serviceInstance.GUID } func listServiceInstances(names ...string) resourceList[serviceInstanceResource] { + GinkgoHelper() + var namesQuery string if len(names) > 0 { namesQuery = "?names=" + strings.Join(names, ",") @@ -655,13 +690,15 @@ func listServiceInstances(names ...string) resourceList[serviceInstanceResource] SetResult(&serviceInstances). Get("/v3/service_instances" + namesQuery) - ExpectWithOffset(1, err).NotTo(HaveOccurred()) - ExpectWithOffset(1, resp.StatusCode()).To(Equal(http.StatusOK)) + Expect(err).NotTo(HaveOccurred()) + Expect(resp.StatusCode()).To(Equal(http.StatusOK)) return serviceInstances } func createServiceBinding(appGUID, instanceGUID, bindingName string) string { + GinkgoHelper() + var serviceCredentialBinding resource resp, err := adminClient.R(). @@ -675,13 +712,15 @@ func createServiceBinding(appGUID, instanceGUID, bindingName string) string { SetResult(&serviceCredentialBinding). Post("/v3/service_credential_bindings") - ExpectWithOffset(1, err).NotTo(HaveOccurred()) - ExpectWithOffset(1, resp.StatusCode()).To(Equal(http.StatusCreated), string(resp.Body())) + Expect(err).NotTo(HaveOccurred()) + Expect(resp.StatusCode()).To(Equal(http.StatusCreated), string(resp.Body())) return serviceCredentialBinding.GUID } func createPackage(appGUID string) string { + GinkgoHelper() + var pkg resource resp, err := adminClient.R(). SetBody(typedResource{ @@ -695,13 +734,15 @@ func createPackage(appGUID string) string { SetResult(&pkg). Post("/v3/packages") - ExpectWithOffset(1, err).NotTo(HaveOccurred()) - ExpectWithOffset(1, resp).To(HaveRestyStatusCode(http.StatusCreated)) + Expect(err).NotTo(HaveOccurred()) + Expect(resp).To(HaveRestyStatusCode(http.StatusCreated)) return pkg.GUID } func createBuild(packageGUID string) string { + GinkgoHelper() + var build resource resp, err := adminClient.R(). @@ -709,13 +750,15 @@ func createBuild(packageGUID string) string { SetResult(&build). Post("/v3/builds") - ExpectWithOffset(1, err).NotTo(HaveOccurred()) - ExpectWithOffset(1, resp).To(HaveRestyStatusCode(http.StatusCreated)) + Expect(err).NotTo(HaveOccurred()) + Expect(resp).To(HaveRestyStatusCode(http.StatusCreated)) return build.GUID } func createDeployment(appGUID string) string { + GinkgoHelper() + var deployment resource resp, err := adminClient.R(). @@ -731,14 +774,16 @@ func createDeployment(appGUID string) string { SetResult(&deployment). Post("/v3/deployments") - ExpectWithOffset(1, err).NotTo(HaveOccurred()) - ExpectWithOffset(1, resp).To(HaveRestyStatusCode(http.StatusCreated)) + Expect(err).NotTo(HaveOccurred()) + Expect(resp).To(HaveRestyStatusCode(http.StatusCreated)) return deployment.GUID } func waitForDroplet(buildGUID string) { - EventuallyWithOffset(1, func() (*resty.Response, error) { + GinkgoHelper() + + Eventually(func() (*resty.Response, error) { resp, err := adminClient.R(). Get("/v3/droplets/" + buildGUID) return resp, err @@ -746,32 +791,40 @@ func waitForDroplet(buildGUID string) { } func setCurrentDroplet(appGUID, dropletGUID string) { + GinkgoHelper() + resp, err := adminClient.R(). SetBody(dropletResource{Data: resource{GUID: dropletGUID}}). Patch("/v3/apps/" + appGUID + "/relationships/current_droplet") - ExpectWithOffset(1, err).NotTo(HaveOccurred()) - ExpectWithOffset(1, resp).To(HaveRestyStatusCode(http.StatusOK)) + Expect(err).NotTo(HaveOccurred()) + Expect(resp).To(HaveRestyStatusCode(http.StatusOK)) } func startApp(appGUID string) { + GinkgoHelper() + resp, err := adminClient.R(). Post("/v3/apps/" + appGUID + "/actions/start") - ExpectWithOffset(1, err).NotTo(HaveOccurred()) - ExpectWithOffset(1, resp).To(HaveRestyStatusCode(http.StatusOK)) + Expect(err).NotTo(HaveOccurred()) + Expect(resp).To(HaveRestyStatusCode(http.StatusOK)) } func uploadTestApp(pkgGUID, appBitsFile string) { + GinkgoHelper() + resp, err := adminClient.R(). SetFiles(map[string]string{ "bits": appBitsFile, }).Post("/v3/packages/" + pkgGUID + "/upload") - ExpectWithOffset(1, err).NotTo(HaveOccurred()) - ExpectWithOffset(1, resp).To(HaveRestyStatusCode(http.StatusOK)) + Expect(err).NotTo(HaveOccurred()) + Expect(resp).To(HaveRestyStatusCode(http.StatusOK)) } func getAppGUIDFromName(appName string) string { + GinkgoHelper() + var appGUID string Eventually(func(g Gomega) { var result resourceList[resource] @@ -786,6 +839,8 @@ func getAppGUIDFromName(appName string) string { } func createAppViaManifest(spaceGUID, appName string) string { + GinkgoHelper() + manifest := manifestResource{ Version: 1, Applications: []applicationResource{{ @@ -800,11 +855,15 @@ func createAppViaManifest(spaceGUID, appName string) string { } func pushTestApp(spaceGUID, appBitsFile string) (string, string) { + GinkgoHelper() + appName := generateGUID("app") return pushTestAppWithName(spaceGUID, appBitsFile, appName), appName } func pushTestAppWithName(spaceGUID, appBitsFile string, appName string) string { + GinkgoHelper() + appGUID := createAppViaManifest(spaceGUID, appName) pkgGUID := createPackage(appGUID) uploadTestApp(pkgGUID, appBitsFile) @@ -817,6 +876,8 @@ func pushTestAppWithName(spaceGUID, appBitsFile string, appName string) string { } func getAppRoute(appGUID string) string { + GinkgoHelper() + var routes resourceList[routeResource] resp, err := adminClient.R(). SetResult(&routes). @@ -836,6 +897,8 @@ var skipSSLClient = http.Client{ } func curlApp(appGUID, path string) []byte { + GinkgoHelper() + url := getAppRoute(appGUID) var body []byte Eventually(func(g Gomega) { @@ -851,13 +914,15 @@ func curlApp(appGUID, path string) []byte { } func getDomainGUID(domainName string) string { + GinkgoHelper() + res := resourceList[bareResource]{} resp, err := adminClient.R(). SetResult(&res). Get("/v3/domains") - ExpectWithOffset(1, err).NotTo(HaveOccurred()) - ExpectWithOffset(1, resp).To(HaveRestyStatusCode(http.StatusOK)) + Expect(err).NotTo(HaveOccurred()) + Expect(resp).To(HaveRestyStatusCode(http.StatusOK)) for _, d := range res.Resources { if d.Name == domainName { @@ -871,6 +936,8 @@ func getDomainGUID(domainName string) string { } func createRoute(host, path string, spaceGUID, domainGUID string) string { + GinkgoHelper() + var route resource resp, err := adminClient.R(). @@ -887,13 +954,15 @@ func createRoute(host, path string, spaceGUID, domainGUID string) string { SetResult(&route). Post("/v3/routes") - ExpectWithOffset(1, err).NotTo(HaveOccurred()) - ExpectWithOffset(1, resp).To(HaveRestyStatusCode(http.StatusCreated)) + Expect(err).NotTo(HaveOccurred()) + Expect(resp).To(HaveRestyStatusCode(http.StatusCreated)) return route.GUID } func addDestinationForRoute(appGUID, routeGUID string) []string { + GinkgoHelper() + var destinations destinationsResource resp, err := adminClient.R(). @@ -905,8 +974,8 @@ func addDestinationForRoute(appGUID, routeGUID string) []string { SetResult(&destinations). Post("/v3/routes/" + routeGUID + "/destinations") - ExpectWithOffset(1, err).NotTo(HaveOccurred()) - ExpectWithOffset(1, resp).To(HaveRestyStatusCode(http.StatusOK)) + Expect(err).NotTo(HaveOccurred()) + Expect(resp).To(HaveRestyStatusCode(http.StatusOK)) var destinationGUIDs []string for _, destination := range destinations.Destinations { @@ -917,8 +986,10 @@ func addDestinationForRoute(appGUID, routeGUID string) []string { } func expectNotFoundError(resp *resty.Response, errResp cfErrs, resource string) { - ExpectWithOffset(1, resp.StatusCode()).To(Equal(http.StatusNotFound)) - ExpectWithOffset(1, errResp.Errors).To(ConsistOf( + GinkgoHelper() + + Expect(resp.StatusCode()).To(Equal(http.StatusNotFound)) + Expect(errResp.Errors).To(ConsistOf( cfErr{ Detail: resource + " not found. Ensure it exists and you have access to it.", Title: "CF-ResourceNotFound", @@ -928,8 +999,10 @@ func expectNotFoundError(resp *resty.Response, errResp cfErrs, resource string) } func expectForbiddenError(resp *resty.Response, errResp cfErrs) { - ExpectWithOffset(1, resp.StatusCode()).To(Equal(http.StatusForbidden)) - ExpectWithOffset(1, errResp.Errors).To(ConsistOf( + GinkgoHelper() + + Expect(resp.StatusCode()).To(Equal(http.StatusForbidden)) + Expect(errResp.Errors).To(ConsistOf( cfErr{ Detail: "You are not authorized to perform the requested action", Title: "CF-NotAuthorized", @@ -939,8 +1012,10 @@ func expectForbiddenError(resp *resty.Response, errResp cfErrs) { } func expectUnprocessableEntityError(resp *resty.Response, errResp cfErrs, detail string) { - ExpectWithOffset(1, resp).To(HaveRestyStatusCode(http.StatusUnprocessableEntity)) - ExpectWithOffset(1, errResp.Errors).To(ConsistOf( + GinkgoHelper() + + Expect(resp).To(HaveRestyStatusCode(http.StatusUnprocessableEntity)) + Expect(errResp.Errors).To(ConsistOf( cfErr{ Detail: detail, Title: "CF-UnprocessableEntity", @@ -978,6 +1053,8 @@ func commonTestSetup() { } func zipAsset(src string) string { + GinkgoHelper() + file, err := os.CreateTemp("", "*.zip") if err != nil { Expect(err).NotTo(HaveOccurred()) diff --git a/tests/helpers/cache_syncing_client.go b/tests/helpers/cache_syncing_client.go index 02eb8fd42..f69ffff46 100644 --- a/tests/helpers/cache_syncing_client.go +++ b/tests/helpers/cache_syncing_client.go @@ -3,6 +3,7 @@ package helpers import ( "context" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "k8s.io/apimachinery/pkg/runtime" "sigs.k8s.io/controller-runtime/pkg/client" @@ -19,17 +20,21 @@ func NewCacheSyncingClient(client client.Client) *CacheSyncingClient { } func (c *CacheSyncingClient) Create(ctx context.Context, obj client.Object, opts ...client.CreateOption) error { + GinkgoHelper() + if err := c.Client.Create(ctx, obj, opts...); err != nil { return err } - EventuallyWithOffset(1, func(g Gomega) { + Eventually(func(g Gomega) { g.Expect(c.Client.Get(ctx, client.ObjectKeyFromObject(obj), obj)).To(Succeed()) }).Should(Succeed()) return nil } func (c *CacheSyncingClient) Patch(ctx context.Context, obj client.Object, patch client.Patch, _ ...client.PatchOption) error { + GinkgoHelper() + err := c.Client.Patch(ctx, obj, patch) if err != nil { return err @@ -37,7 +42,7 @@ func (c *CacheSyncingClient) Patch(ctx context.Context, obj client.Object, patch generation := obj.GetGeneration() - EventuallyWithOffset(1, func(g Gomega) { + Eventually(func(g Gomega) { g.Expect(c.Client.Get(ctx, client.ObjectKeyFromObject(obj), obj)).To(Succeed()) g.Expect(obj.GetGeneration()).To(BeNumerically(">=", generation)) }).Should(Succeed()) @@ -46,6 +51,8 @@ func (c *CacheSyncingClient) Patch(ctx context.Context, obj client.Object, patch } func (c *CacheSyncingClient) Status() client.SubResourceWriter { + GinkgoHelper() + return &syncStatusWriter{ SubResourceWriter: c.Client.Status(), client: c, @@ -58,13 +65,15 @@ type syncStatusWriter struct { } func (w *syncStatusWriter) Patch(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.SubResourcePatchOption) error { + GinkgoHelper() + err := w.SubResourceWriter.Patch(ctx, obj, patch, opts...) if err != nil { return err } dryRunClient := client.NewDryRunClient(w.client) - EventuallyWithOffset(1, func(g Gomega) { + Eventually(func(g Gomega) { g.Expect(w.client.Get(ctx, client.ObjectKeyFromObject(obj), obj)).To(Succeed()) currentStatus, err := getStatus(obj) g.Expect(err).NotTo(HaveOccurred()) @@ -83,6 +92,8 @@ func (w *syncStatusWriter) Patch(ctx context.Context, obj client.Object, patch c } func getStatus(obj runtime.Object) (any, error) { + GinkgoHelper() + unstructuredObj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(obj) if err != nil { return nil, err