From dec125125d9a5df6a94bc6206d3d29ea37e12bca Mon Sep 17 00:00:00 2001 From: user297370852 <221870222@smail.nju.edu.cn> Date: Tue, 11 Mar 2025 21:18:18 +0800 Subject: [PATCH 1/3] Add Notation to TestJindoEngine_DeleteFusePersistentVolumeClaim(t *testing.T) in pkg\ddc\jindo\delete_volume_test.go Signed-off-by: user297370852 <221870222@smail.nju.edu.cn> --- pkg/ddc/jindo/delete_volume_test.go | 85 +++++++++++++++++------------ 1 file changed, 50 insertions(+), 35 deletions(-) diff --git a/pkg/ddc/jindo/delete_volume_test.go b/pkg/ddc/jindo/delete_volume_test.go index 6204b76bf15..0f3261450b4 100644 --- a/pkg/ddc/jindo/delete_volume_test.go +++ b/pkg/ddc/jindo/delete_volume_test.go @@ -182,38 +182,53 @@ func TestJindoEngine_DeleteFusePersistentVolume(t *testing.T) { doTestCases(testCases, t) } -func TestJindoEngine_DeleteFusePersistentVolumeClaim(t *testing.T) { - testPVCInputs := []*v1.PersistentVolumeClaim{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "hbase", - Namespace: "fluid", - Finalizers: []string{"kubernetes.io/pvc-protection"}, // no err - }, - Spec: v1.PersistentVolumeClaimSpec{}, - }, - } - - tests := []runtime.Object{} - - for _, pvcInput := range testPVCInputs { - tests = append(tests, pvcInput.DeepCopy()) - } - - fakeClient := fake.NewFakeClientWithScheme(testScheme, tests...) - JindoEngine := newTestJindoEngine(fakeClient, "hbase", "fluid", true) - JindoEngineNoRuntime := newTestJindoEngine(fakeClient, "hbase", "fluid", false) - testCases := []TestCase{ - { - engine: JindoEngine, - isDeleted: true, - isErr: false, - }, - { - engine: JindoEngineNoRuntime, - isDeleted: true, - isErr: true, - }, - } - doTestCases(testCases, t) -} +// TestJindoEngine_DeleteFusePersistentVolumeClaim tests the DeleteFusePersistentVolumeClaim method of JindoEngine. +// This test verifies the behavior when deleting a PersistentVolumeClaim (PVC) under two scenarios: +// 1. With a functional JindoEngine instance, expecting successful deletion of the PVC. +// 2. With a JindoEngine instance that lacks a runtime, expecting an error upon attempting to delete the PVC. +// The test initializes a fake Kubernetes client and the corresponding PVC inputs to execute these scenarios. +func TestJindoEngine_DeleteFusePersistentVolumeClaim(t *testing.T) { + // Define test PVC inputs with metadata and finalizers + testPVCInputs := []*v1.PersistentVolumeClaim{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "hbase", + Namespace: "fluid", + Finalizers: []string{"kubernetes.io/pvc-protection"}, // This finalizer prevents deletion errors + }, + Spec: v1.PersistentVolumeClaimSpec{}, + }, + } + + // Initialize an empty slice to hold runtime objects for testing + tests := []runtime.Object{} + + // Deep copy each PVC input and append to tests for use in the fake client + for _, pvcInput := range testPVCInputs { + tests = append(tests, pvcInput.DeepCopy()) + } + + // Create a fake Kubernetes client using the defined test scheme and PVCs + fakeClient := fake.NewFakeClientWithScheme(testScheme, tests...) + + // Initialize JindoEngine instances for testing with and without runtime + JindoEngine := newTestJindoEngine(fakeClient, "hbase", "fluid", true) + JindoEngineNoRuntime := newTestJindoEngine(fakeClient, "hbase", "fluid", false) + + // Define test cases with expected outcomes for both JindoEngine instances + testCases := []TestCase{ + { + engine: JindoEngine, + isDeleted: true, // Expect deletion to succeed + isErr: false, // Expect no error + }, + { + engine: JindoEngineNoRuntime, + isDeleted: true, // Expect deletion to be attempted + isErr: true, // Expect an error due to lack of runtime + }, + } + + // Execute the defined test cases, passing in the testing object + doTestCases(testCases, t) +} From 988bd12fb7858de0e146e4efdefec129c75500f8 Mon Sep 17 00:00:00 2001 From: user297370852 <221870222@smail.nju.edu.cn> Date: Wed, 12 Mar 2025 17:38:40 +0800 Subject: [PATCH 2/3] add comments to TestJindoEngine_DeleteFusePersistentVolumeClaim in pkg\ddc\jindo\delete_volume_test.go Signed-off-by: user297370852 <221870222@smail.nju.edu.cn> --- pkg/ddc/jindo/delete_volume_test.go | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/pkg/ddc/jindo/delete_volume_test.go b/pkg/ddc/jindo/delete_volume_test.go index 0f3261450b4..cbb38e878be 100644 --- a/pkg/ddc/jindo/delete_volume_test.go +++ b/pkg/ddc/jindo/delete_volume_test.go @@ -188,47 +188,37 @@ func TestJindoEngine_DeleteFusePersistentVolume(t *testing.T) { // 2. With a JindoEngine instance that lacks a runtime, expecting an error upon attempting to delete the PVC. // The test initializes a fake Kubernetes client and the corresponding PVC inputs to execute these scenarios. func TestJindoEngine_DeleteFusePersistentVolumeClaim(t *testing.T) { - // Define test PVC inputs with metadata and finalizers testPVCInputs := []*v1.PersistentVolumeClaim{ { ObjectMeta: metav1.ObjectMeta{ Name: "hbase", Namespace: "fluid", - Finalizers: []string{"kubernetes.io/pvc-protection"}, // This finalizer prevents deletion errors + Finalizers: []string{"kubernetes.io/pvc-protection"}, // no err }, Spec: v1.PersistentVolumeClaimSpec{}, }, } - // Initialize an empty slice to hold runtime objects for testing tests := []runtime.Object{} - // Deep copy each PVC input and append to tests for use in the fake client for _, pvcInput := range testPVCInputs { tests = append(tests, pvcInput.DeepCopy()) } - // Create a fake Kubernetes client using the defined test scheme and PVCs fakeClient := fake.NewFakeClientWithScheme(testScheme, tests...) - - // Initialize JindoEngine instances for testing with and without runtime JindoEngine := newTestJindoEngine(fakeClient, "hbase", "fluid", true) JindoEngineNoRuntime := newTestJindoEngine(fakeClient, "hbase", "fluid", false) - - // Define test cases with expected outcomes for both JindoEngine instances testCases := []TestCase{ { engine: JindoEngine, - isDeleted: true, // Expect deletion to succeed - isErr: false, // Expect no error + isDeleted: true, + isErr: false, }, { engine: JindoEngineNoRuntime, - isDeleted: true, // Expect deletion to be attempted - isErr: true, // Expect an error due to lack of runtime + isDeleted: true, + isErr: true, }, } - - // Execute the defined test cases, passing in the testing object doTestCases(testCases, t) } From c7c78b085e591bbcaf0dedc7ec1c7b9177ea1829 Mon Sep 17 00:00:00 2001 From: cheyang Date: Wed, 19 Mar 2025 19:42:53 +0800 Subject: [PATCH 3/3] Fix format issue Signed-off-by: cheyang --- pkg/ddc/jindo/delete_volume_test.go | 80 ++++++++++++++--------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/pkg/ddc/jindo/delete_volume_test.go b/pkg/ddc/jindo/delete_volume_test.go index cbb38e878be..a8c9d5570e3 100644 --- a/pkg/ddc/jindo/delete_volume_test.go +++ b/pkg/ddc/jindo/delete_volume_test.go @@ -182,43 +182,43 @@ func TestJindoEngine_DeleteFusePersistentVolume(t *testing.T) { doTestCases(testCases, t) } -// TestJindoEngine_DeleteFusePersistentVolumeClaim tests the DeleteFusePersistentVolumeClaim method of JindoEngine. -// This test verifies the behavior when deleting a PersistentVolumeClaim (PVC) under two scenarios: -// 1. With a functional JindoEngine instance, expecting successful deletion of the PVC. -// 2. With a JindoEngine instance that lacks a runtime, expecting an error upon attempting to delete the PVC. -// The test initializes a fake Kubernetes client and the corresponding PVC inputs to execute these scenarios. -func TestJindoEngine_DeleteFusePersistentVolumeClaim(t *testing.T) { - testPVCInputs := []*v1.PersistentVolumeClaim{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "hbase", - Namespace: "fluid", - Finalizers: []string{"kubernetes.io/pvc-protection"}, // no err - }, - Spec: v1.PersistentVolumeClaimSpec{}, - }, - } - - tests := []runtime.Object{} - - for _, pvcInput := range testPVCInputs { - tests = append(tests, pvcInput.DeepCopy()) - } - - fakeClient := fake.NewFakeClientWithScheme(testScheme, tests...) - JindoEngine := newTestJindoEngine(fakeClient, "hbase", "fluid", true) - JindoEngineNoRuntime := newTestJindoEngine(fakeClient, "hbase", "fluid", false) - testCases := []TestCase{ - { - engine: JindoEngine, - isDeleted: true, - isErr: false, - }, - { - engine: JindoEngineNoRuntime, - isDeleted: true, - isErr: true, - }, - } - doTestCases(testCases, t) -} +// TestJindoEngine_DeleteFusePersistentVolumeClaim tests the DeleteFusePersistentVolumeClaim method of JindoEngine. +// This test verifies the behavior when deleting a PersistentVolumeClaim (PVC) under two scenarios: +// 1. With a functional JindoEngine instance, expecting successful deletion of the PVC. +// 2. With a JindoEngine instance that lacks a runtime, expecting an error upon attempting to delete the PVC. +// The test initializes a fake Kubernetes client and the corresponding PVC inputs to execute these scenarios. +func TestJindoEngine_DeleteFusePersistentVolumeClaim(t *testing.T) { + testPVCInputs := []*v1.PersistentVolumeClaim{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "hbase", + Namespace: "fluid", + Finalizers: []string{"kubernetes.io/pvc-protection"}, // no err + }, + Spec: v1.PersistentVolumeClaimSpec{}, + }, + } + + tests := []runtime.Object{} + + for _, pvcInput := range testPVCInputs { + tests = append(tests, pvcInput.DeepCopy()) + } + + fakeClient := fake.NewFakeClientWithScheme(testScheme, tests...) + JindoEngine := newTestJindoEngine(fakeClient, "hbase", "fluid", true) + JindoEngineNoRuntime := newTestJindoEngine(fakeClient, "hbase", "fluid", false) + testCases := []TestCase{ + { + engine: JindoEngine, + isDeleted: true, + isErr: false, + }, + { + engine: JindoEngineNoRuntime, + isDeleted: true, + isErr: true, + }, + } + doTestCases(testCases, t) +}