diff --git a/common/pkg/testutils/capitest/patches.go b/common/pkg/testutils/capitest/patches.go index 62c7b2aaf..a7998ba18 100644 --- a/common/pkg/testutils/capitest/patches.go +++ b/common/pkg/testutils/capitest/patches.go @@ -38,62 +38,6 @@ type JSONPatchMatcher struct { ValueMatcher gomegatypes.GomegaMatcher } -func ValidateGeneratePatches[T mutation.GeneratePatches]( - t GinkgoTInterface, - handlerCreator func() T, - testDefs ...PatchTestDef, -) { - t.Helper() - testFunc := func(tt *PatchTestDef) { - g := gomega.NewWithT(t) - h := handlerCreator() - req := &runtimehooksv1.GeneratePatchesRequest{ - Variables: tt.Vars, - Items: []runtimehooksv1.GeneratePatchesRequestItem{ - tt.RequestItem, - { - HolderReference: runtimehooksv1.HolderReference{ - APIVersion: clusterv1.GroupVersion.String(), - Kind: "Cluster", - Namespace: request.Namespace, - Name: request.ClusterName, - }, - }, - }, - } - resp := &runtimehooksv1.GeneratePatchesResponse{} - h.GeneratePatches(context.Background(), req, resp) - expectedStatus := runtimehooksv1.ResponseStatusSuccess - if tt.ExpectedFailure { - expectedStatus = runtimehooksv1.ResponseStatusFailure - } - g.Expect(resp.Status). - To(gomega.Equal(expectedStatus), fmt.Sprintf("Message: %s", resp.Message)) - - if len(tt.ExpectedPatchMatchers) == 0 { - g.Expect(resp.Items).To(gomega.BeEmpty()) - return - } - g.Expect(resp.Items).To(containPatches(&tt.RequestItem, tt.ExpectedPatchMatchers...)) - - if len(tt.UnexpectedPatchMatchers) > 0 { - g.Expect(resp.Items). - ToNot(containPatches(&tt.RequestItem, tt.UnexpectedPatchMatchers...)) - } - } - - // compose Ginkgo table arguments - // https://onsi.github.io/ginkgo/#table-specs for more details - testArgs := make([]TableEntry, 0, len(testDefs)) - for testIdx := range testDefs { - tt := testDefs[testIdx] - testArgs = append(testArgs, Entry(tt.Name, &tt)) - } - DescribeTable("Patches", testFunc, testArgs) -} - -// TODO(shalinpatel): AssertGeneratePatches is a replacement of ValidateGeneratePatches function. -// remove ValidateGeneratePatches once all the shared test cases are moved to their own patch package. func AssertGeneratePatches[T mutation.GeneratePatches]( t GinkgoTInterface, handlerCreator func() T,