From d4de923e7e66c4100b8786ad727ce0795838c466 Mon Sep 17 00:00:00 2001 From: Popie52 Date: Sun, 1 Feb 2026 18:31:11 +0530 Subject: [PATCH 1/6] tests(fusesidecar): convert unit test to Ginkgo/Gomega (PoC) Signed-off-by: Popie52 --- .../plugins/fusesidecar/fuse_sidecar_test.go | 101 ++++++++++-------- 1 file changed, 57 insertions(+), 44 deletions(-) diff --git a/pkg/webhook/plugins/fusesidecar/fuse_sidecar_test.go b/pkg/webhook/plugins/fusesidecar/fuse_sidecar_test.go index 4b9c63025fb..87252c862d3 100644 --- a/pkg/webhook/plugins/fusesidecar/fuse_sidecar_test.go +++ b/pkg/webhook/plugins/fusesidecar/fuse_sidecar_test.go @@ -17,56 +17,69 @@ limitations under the License. package fusesidecar import ( - "testing" - "github.com/fluid-cloudnative/fluid/pkg/ddc/base" + "github.com/fluid-cloudnative/fluid/pkg/webhook/plugins/api" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" ) -func TestMutate(t *testing.T) { +var _ = Describe("FuseSidecar Plugin", func() { var ( - client client.Client - pod *corev1.Pod + plugin api.MutatingHandler + err error ) - plugin, err := NewPlugin(client, "") - if err != nil { - t.Error("new plugin occurs error", err) - } - if plugin.GetName() != Name { - t.Errorf("GetName expect %v, got %v", Name, plugin.GetName()) - } - - runtimeInfo, err := base.BuildRuntimeInfo("test", "fluid", "alluxio") - if err != nil { - t.Errorf("fail to create the runtimeInfo with error %v", err) - } - - pod = &corev1.Pod{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test", - Namespace: "test", - }, - } - - shouldStop, err := plugin.Mutate(pod, map[string]base.RuntimeInfoInterface{"test": runtimeInfo}) - if err != nil { - t.Errorf("fail to mutate pod with error %v", err) - } - - if shouldStop { - t.Errorf("expect shouldStop as false, but got %v", shouldStop) - } - - _, err = plugin.Mutate(pod, map[string]base.RuntimeInfoInterface{}) - if err != nil { - t.Errorf("fail to mutate pod with error %v", err) - } - - _, err = plugin.Mutate(pod, map[string]base.RuntimeInfoInterface{"test": nil}) - if err != nil { - t.Errorf("expect error is nil") - } -} + BeforeEach(func() { + var c client.Client + plugin, err = NewPlugin(c, "") + }) + + It("creates plugin successfully", func() { + Expect(err).NotTo(HaveOccurred()) + Expect(plugin.GetName()).To(Equal(Name)) + }) + + Context("when mutating a pod", func() { + var pod *corev1.Pod + + BeforeEach(func() { + pod = &corev1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test", + Namespace: "test", + }, + } + }) + + It("does not stop mutation when runtimeInfo is present", func() { + runtimeInfo, err := base.BuildRuntimeInfo("test", "fluid", "alluxio") + Expect(err).NotTo(HaveOccurred()) + + shouldStop, err := plugin.Mutate( + pod, + map[string]base.RuntimeInfoInterface{"test": runtimeInfo}, + ) + + Expect(err).NotTo(HaveOccurred()) + Expect(shouldStop).To(BeFalse()) + }) + + It("does not error when runtimeInfos is empty", func() { + _, err := plugin.Mutate(pod, map[string]base.RuntimeInfoInterface{}) + Expect(err).NotTo(HaveOccurred()) + }) + + It("does not error when runtimeInfo is nil", func() { + _, err := plugin.Mutate( + pod, + map[string]base.RuntimeInfoInterface{"test": nil}, + ) + Expect(err).NotTo(HaveOccurred()) + }) + }) +}) From d1dd4bb526ac578ef368a717427e89a985829fc3 Mon Sep 17 00:00:00 2001 From: Popie52 Date: Sun, 1 Feb 2026 18:34:33 +0530 Subject: [PATCH 2/6] tests(fusesidecar): add Ginkgo test suite entrypoint Signed-off-by: Popie52 --- pkg/webhook/plugins/fusesidecar/fuse_sidecar_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/webhook/plugins/fusesidecar/fuse_sidecar_test.go b/pkg/webhook/plugins/fusesidecar/fuse_sidecar_test.go index 87252c862d3..d55dc573dfb 100644 --- a/pkg/webhook/plugins/fusesidecar/fuse_sidecar_test.go +++ b/pkg/webhook/plugins/fusesidecar/fuse_sidecar_test.go @@ -17,6 +17,8 @@ limitations under the License. package fusesidecar import ( + "testing" + "github.com/fluid-cloudnative/fluid/pkg/ddc/base" "github.com/fluid-cloudnative/fluid/pkg/webhook/plugins/api" @@ -83,3 +85,8 @@ var _ = Describe("FuseSidecar Plugin", func() { }) }) }) + +func TestFuseSidecar(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "FuseSidecar Plugin Suite") +} \ No newline at end of file From db0722dd881ae1e46d05a7314072ad6a6d51e3b7 Mon Sep 17 00:00:00 2001 From: Popie52 Date: Sun, 1 Feb 2026 18:53:09 +0530 Subject: [PATCH 3/6] test(fusesidecar): initialize fake client in Ginkgo tests Signed-off-by: Popie52 --- .../plugins/fusesidecar/fuse_sidecar_test.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/pkg/webhook/plugins/fusesidecar/fuse_sidecar_test.go b/pkg/webhook/plugins/fusesidecar/fuse_sidecar_test.go index d55dc573dfb..c7f00f5a7fa 100644 --- a/pkg/webhook/plugins/fusesidecar/fuse_sidecar_test.go +++ b/pkg/webhook/plugins/fusesidecar/fuse_sidecar_test.go @@ -21,13 +21,14 @@ import ( "github.com/fluid-cloudnative/fluid/pkg/ddc/base" "github.com/fluid-cloudnative/fluid/pkg/webhook/plugins/api" + "k8s.io/apimachinery/pkg/runtime" + "sigs.k8s.io/controller-runtime/pkg/client/fake" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "sigs.k8s.io/controller-runtime/pkg/client" ) var _ = Describe("FuseSidecar Plugin", func() { @@ -37,7 +38,13 @@ var _ = Describe("FuseSidecar Plugin", func() { ) BeforeEach(func() { - var c client.Client + s := runtime.NewScheme() + Expect(corev1.AddToScheme(s)).To(Succeed()) + + c := fake.NewClientBuilder(). + WithScheme(s). + Build() + plugin, err = NewPlugin(c, "") }) @@ -87,6 +94,6 @@ var _ = Describe("FuseSidecar Plugin", func() { }) func TestFuseSidecar(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "FuseSidecar Plugin Suite") -} \ No newline at end of file + RegisterFailHandler(Fail) + RunSpecs(t, "FuseSidecar Plugin Suite") +} From 8207a189bb60944ae5c75857d580e2bbf8e24cdf Mon Sep 17 00:00:00 2001 From: Popie52 Date: Sun, 1 Feb 2026 19:09:12 +0530 Subject: [PATCH 4/6] test(webhook): add Ginkgo/Gomega tests for MountPropagationInjector Signed-off-by: Popie52 --- .../mount_propagation_injector_suite_test.go | 13 +++ .../mount_propagation_injector_test.go | 109 ++++++++++-------- 2 files changed, 75 insertions(+), 47 deletions(-) create mode 100644 pkg/webhook/plugins/mountpropagationinjector/mount_propagation_injector_suite_test.go diff --git a/pkg/webhook/plugins/mountpropagationinjector/mount_propagation_injector_suite_test.go b/pkg/webhook/plugins/mountpropagationinjector/mount_propagation_injector_suite_test.go new file mode 100644 index 00000000000..8f004416aec --- /dev/null +++ b/pkg/webhook/plugins/mountpropagationinjector/mount_propagation_injector_suite_test.go @@ -0,0 +1,13 @@ +package mountpropagationinjector + +import ( + "testing" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +func TestMountPropagationInjector(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "MountPropagationInjector Suite") +} diff --git a/pkg/webhook/plugins/mountpropagationinjector/mount_propagation_injector_test.go b/pkg/webhook/plugins/mountpropagationinjector/mount_propagation_injector_test.go index 41076762760..a019ee724fb 100644 --- a/pkg/webhook/plugins/mountpropagationinjector/mount_propagation_injector_test.go +++ b/pkg/webhook/plugins/mountpropagationinjector/mount_propagation_injector_test.go @@ -1,10 +1,9 @@ /* - 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 + 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, @@ -12,60 +11,76 @@ 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 mountpropagationinjector import ( - "testing" - "github.com/fluid-cloudnative/fluid/pkg/ddc/base" + "github.com/fluid-cloudnative/fluid/pkg/webhook/plugins/api" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "sigs.k8s.io/controller-runtime/pkg/client" + "k8s.io/apimachinery/pkg/runtime" + "sigs.k8s.io/controller-runtime/pkg/client/fake" ) -func TestMutate(t *testing.T) { +var _ = Describe("MountPropagationInjector Plugin", func() { var ( - client client.Client + plugin api.MutatingHandler pod *corev1.Pod ) - plugin, err := NewPlugin(client, "") - if err != nil { - t.Error("new plugin occurs error", err) - } - if plugin.GetName() != Name { - t.Errorf("GetName expect %v, got %v", Name, plugin.GetName()) - } - - runtimeInfo, err := base.BuildRuntimeInfo("test", "fluid", "alluxio") - if err != nil { - t.Errorf("fail to create the runtimeInfo with error %v", err) - } - - pod = &corev1.Pod{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test", - Namespace: "test", - }, - } - - shouldStop, err := plugin.Mutate(pod, map[string]base.RuntimeInfoInterface{"test": runtimeInfo}) - if err != nil { - t.Errorf("fail to mutate pod with error %v", err) - } - - if shouldStop { - t.Errorf("expect shouldStop as false, but got %v", shouldStop) - } - - _, err = plugin.Mutate(pod, map[string]base.RuntimeInfoInterface{}) - if err != nil { - t.Errorf("fail to mutate pod with error %v", err) - } - - _, err = plugin.Mutate(pod, map[string]base.RuntimeInfoInterface{"test": nil}) - if err == nil { - t.Errorf("expect error is not nil") - } -} + BeforeEach(func() { + scheme := runtime.NewScheme() + Expect(corev1.AddToScheme(scheme)).To(Succeed()) + + c := fake.NewClientBuilder(). + WithScheme(scheme). + Build() + + var err error + plugin, err = NewPlugin(c, "") + Expect(err).NotTo(HaveOccurred()) + + pod = &corev1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test", + Namespace: "test", + }, + } + }) + + It("returns correct plugin name", func() { + Expect(plugin.GetName()).To(Equal(Name)) + }) + + Context("when mutating a pod", func() { + It("does not stop when runtimeInfo exists", func() { + runtimeInfo, err := base.BuildRuntimeInfo("test", "fluid", "alluxio") + Expect(err).NotTo(HaveOccurred()) + + shouldStop, err := plugin.Mutate( + pod, + map[string]base.RuntimeInfoInterface{"test": runtimeInfo}, + ) + + Expect(err).NotTo(HaveOccurred()) + Expect(shouldStop).To(BeFalse()) + }) + + It("does not error when runtimeInfos is empty", func() { + _, err := plugin.Mutate(pod, map[string]base.RuntimeInfoInterface{}) + Expect(err).NotTo(HaveOccurred()) + }) + + It("returns error when runtimeInfo is nil", func() { + _, err := plugin.Mutate( + pod, + map[string]base.RuntimeInfoInterface{"test": nil}, + ) + Expect(err).To(HaveOccurred()) + }) + }) +}) From 587f1c6df590c36e3b9a3bfacf83308a13ad5b80 Mon Sep 17 00:00:00 2001 From: Popie52 Date: Sun, 1 Feb 2026 20:03:10 +0530 Subject: [PATCH 5/6] test(mountpropagationinjector): add Ginkgo test asserting mount propagation injection Signed-off-by: Popie52 --- .../mount_propagation_injector_test.go | 58 ++++++++++--------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/pkg/webhook/plugins/mountpropagationinjector/mount_propagation_injector_test.go b/pkg/webhook/plugins/mountpropagationinjector/mount_propagation_injector_test.go index a019ee724fb..cc55fab28e9 100644 --- a/pkg/webhook/plugins/mountpropagationinjector/mount_propagation_injector_test.go +++ b/pkg/webhook/plugins/mountpropagationinjector/mount_propagation_injector_test.go @@ -56,31 +56,37 @@ var _ = Describe("MountPropagationInjector Plugin", func() { Expect(plugin.GetName()).To(Equal(Name)) }) - Context("when mutating a pod", func() { - It("does not stop when runtimeInfo exists", func() { - runtimeInfo, err := base.BuildRuntimeInfo("test", "fluid", "alluxio") - Expect(err).NotTo(HaveOccurred()) - - shouldStop, err := plugin.Mutate( - pod, - map[string]base.RuntimeInfoInterface{"test": runtimeInfo}, - ) - - Expect(err).NotTo(HaveOccurred()) - Expect(shouldStop).To(BeFalse()) - }) - - It("does not error when runtimeInfos is empty", func() { - _, err := plugin.Mutate(pod, map[string]base.RuntimeInfoInterface{}) - Expect(err).NotTo(HaveOccurred()) - }) - - It("returns error when runtimeInfo is nil", func() { - _, err := plugin.Mutate( - pod, - map[string]base.RuntimeInfoInterface{"test": nil}, - ) - Expect(err).To(HaveOccurred()) - }) + It("injects mount propagation when PVC is mounted", func() { + pod.Spec.Volumes = []corev1.Volume{{ + Name: "data", + VolumeSource: corev1.VolumeSource{ + PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{ + ClaimName: "test", + }, + }, + }} + + pod.Spec.Containers = []corev1.Container{{ + Name: "app", + VolumeMounts: []corev1.VolumeMount{{ + Name: "data", + MountPath: "/data", + }}, + }} + + runtimeInfo, err := base.BuildRuntimeInfo("test", "fluid", "alluxio") + Expect(err).NotTo(HaveOccurred()) + + shouldStop, err := plugin.Mutate( + pod, + map[string]base.RuntimeInfoInterface{"test": runtimeInfo}, + ) + + Expect(err).NotTo(HaveOccurred()) + Expect(shouldStop).To(BeFalse()) + + mp := corev1.MountPropagationHostToContainer + Expect(pod.Spec.Containers[0].VolumeMounts[0].MountPropagation). + To(Equal(&mp)) }) }) From 5d0d5681b941e01e556e5734fcadc942ba75322b Mon Sep 17 00:00:00 2001 From: Popie <86546258+Popie52@users.noreply.github.com> Date: Mon, 2 Feb 2026 08:45:06 +0530 Subject: [PATCH 6/6] Refactor FuseSidecar tests to use standard testing Signed-off-by: Popie52 --- .../plugins/fusesidecar/fuse_sidecar_test.go | 111 +++++++----------- 1 file changed, 42 insertions(+), 69 deletions(-) diff --git a/pkg/webhook/plugins/fusesidecar/fuse_sidecar_test.go b/pkg/webhook/plugins/fusesidecar/fuse_sidecar_test.go index c7f00f5a7fa..4b9c63025fb 100644 --- a/pkg/webhook/plugins/fusesidecar/fuse_sidecar_test.go +++ b/pkg/webhook/plugins/fusesidecar/fuse_sidecar_test.go @@ -20,80 +20,53 @@ import ( "testing" "github.com/fluid-cloudnative/fluid/pkg/ddc/base" - "github.com/fluid-cloudnative/fluid/pkg/webhook/plugins/api" - "k8s.io/apimachinery/pkg/runtime" - "sigs.k8s.io/controller-runtime/pkg/client/fake" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "sigs.k8s.io/controller-runtime/pkg/client" ) -var _ = Describe("FuseSidecar Plugin", func() { +func TestMutate(t *testing.T) { var ( - plugin api.MutatingHandler - err error + client client.Client + pod *corev1.Pod ) - BeforeEach(func() { - s := runtime.NewScheme() - Expect(corev1.AddToScheme(s)).To(Succeed()) - - c := fake.NewClientBuilder(). - WithScheme(s). - Build() - - plugin, err = NewPlugin(c, "") - }) - - It("creates plugin successfully", func() { - Expect(err).NotTo(HaveOccurred()) - Expect(plugin.GetName()).To(Equal(Name)) - }) - - Context("when mutating a pod", func() { - var pod *corev1.Pod - - BeforeEach(func() { - pod = &corev1.Pod{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test", - Namespace: "test", - }, - } - }) - - It("does not stop mutation when runtimeInfo is present", func() { - runtimeInfo, err := base.BuildRuntimeInfo("test", "fluid", "alluxio") - Expect(err).NotTo(HaveOccurred()) - - shouldStop, err := plugin.Mutate( - pod, - map[string]base.RuntimeInfoInterface{"test": runtimeInfo}, - ) - - Expect(err).NotTo(HaveOccurred()) - Expect(shouldStop).To(BeFalse()) - }) - - It("does not error when runtimeInfos is empty", func() { - _, err := plugin.Mutate(pod, map[string]base.RuntimeInfoInterface{}) - Expect(err).NotTo(HaveOccurred()) - }) - - It("does not error when runtimeInfo is nil", func() { - _, err := plugin.Mutate( - pod, - map[string]base.RuntimeInfoInterface{"test": nil}, - ) - Expect(err).NotTo(HaveOccurred()) - }) - }) -}) - -func TestFuseSidecar(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "FuseSidecar Plugin Suite") + plugin, err := NewPlugin(client, "") + if err != nil { + t.Error("new plugin occurs error", err) + } + if plugin.GetName() != Name { + t.Errorf("GetName expect %v, got %v", Name, plugin.GetName()) + } + + runtimeInfo, err := base.BuildRuntimeInfo("test", "fluid", "alluxio") + if err != nil { + t.Errorf("fail to create the runtimeInfo with error %v", err) + } + + pod = &corev1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test", + Namespace: "test", + }, + } + + shouldStop, err := plugin.Mutate(pod, map[string]base.RuntimeInfoInterface{"test": runtimeInfo}) + if err != nil { + t.Errorf("fail to mutate pod with error %v", err) + } + + if shouldStop { + t.Errorf("expect shouldStop as false, but got %v", shouldStop) + } + + _, err = plugin.Mutate(pod, map[string]base.RuntimeInfoInterface{}) + if err != nil { + t.Errorf("fail to mutate pod with error %v", err) + } + + _, err = plugin.Mutate(pod, map[string]base.RuntimeInfoInterface{"test": nil}) + if err != nil { + t.Errorf("expect error is nil") + } }