diff --git a/pkg/webhook/handler/mutating/mutating_handler_test.go b/pkg/webhook/handler/mutating/mutating_handler_test.go index 4a46b021e74..44247333ab2 100644 --- a/pkg/webhook/handler/mutating/mutating_handler_test.go +++ b/pkg/webhook/handler/mutating/mutating_handler_test.go @@ -23,7 +23,6 @@ import ( "github.com/agiledragon/gomonkey/v2" datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1" "github.com/fluid-cloudnative/fluid/pkg/common" - "github.com/fluid-cloudnative/fluid/pkg/utils" "github.com/fluid-cloudnative/fluid/pkg/utils/fake" "github.com/fluid-cloudnative/fluid/pkg/webhook/plugins" . "github.com/onsi/ginkgo/v2" @@ -1465,7 +1464,6 @@ var _ = Describe("Handle - Global Injection Disabled", func() { var ( decoder *admission.Decoder s *runtime.Scheme - patch *gomonkey.Patches ) BeforeEach(func() { @@ -1474,19 +1472,8 @@ var _ = Describe("Handle - Global Injection Disabled", func() { Expect(corev1.AddToScheme(s)).To(Succeed()) }) - AfterEach(func() { - if patch != nil { - patch.Reset() - } - }) - It("should skip mutation when global injection is disabled", func() { - patch = gomonkey.ApplyFunc(utils.GetBoolValueFromEnv, func(key string, defaultValue bool) bool { - if key == common.EnvDisableInjection { - return true - } - return defaultValue - }) + GinkgoT().Setenv(common.EnvDisableInjection, "true") req := admission.Request{ AdmissionRequest: admissionv1.AdmissionRequest{ diff --git a/pkg/webhook/handler/mutating/mutating_suite_test.go b/pkg/webhook/handler/mutating/mutating_suite_test.go index 0d91c0b5fe8..69d58f244c7 100644 --- a/pkg/webhook/handler/mutating/mutating_suite_test.go +++ b/pkg/webhook/handler/mutating/mutating_suite_test.go @@ -1,4 +1,20 @@ -package mutating_test +/* +Copyright 2026 The Fluid Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package mutating import ( "testing" diff --git a/pkg/webhook/handler/mutating/webhook_test.go b/pkg/webhook/handler/mutating/webhook_test.go new file mode 100644 index 00000000000..69917035bfb --- /dev/null +++ b/pkg/webhook/handler/mutating/webhook_test.go @@ -0,0 +1,36 @@ +/* +Copyright 2026 The Fluid Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package mutating + +import ( + "github.com/fluid-cloudnative/fluid/pkg/common" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +var _ = Describe("HandlerMap", func() { + It("should register a handler under WebhookSchedulePodPath", func() { + Expect(HandlerMap).To(HaveKey(common.WebhookSchedulePodPath)) + }) + + It("should map WebhookSchedulePodPath to a *FluidMutatingHandler", func() { + handler, ok := HandlerMap[common.WebhookSchedulePodPath] + Expect(ok).To(BeTrue()) + Expect(handler).NotTo(BeNil()) + Expect(handler).To(BeAssignableToTypeOf(&FluidMutatingHandler{})) + }) +})