From fc341142c68b8a5d1784dbe72a49f7aa7a8355e3 Mon Sep 17 00:00:00 2001 From: Sirilaw <480469140@qq.com> Date: Thu, 6 Mar 2025 19:20:27 -0800 Subject: [PATCH 1/3] Add Comments to TestTransformWorkerValumes in pkg/ddc/alluxio/transform_volumes_test.go Signed-off-by: Sirilaw <480469140@qq.com> --- pkg/ddc/alluxio/transform_volumes_test.go | 76 ++++++++++++++--------- 1 file changed, 45 insertions(+), 31 deletions(-) diff --git a/pkg/ddc/alluxio/transform_volumes_test.go b/pkg/ddc/alluxio/transform_volumes_test.go index cc79bad2520..2d581890f4a 100644 --- a/pkg/ddc/alluxio/transform_volumes_test.go +++ b/pkg/ddc/alluxio/transform_volumes_test.go @@ -133,33 +133,41 @@ func TestTransformMasterVolumes(t *testing.T) { } +// TestTransformWorkerVolumes is a unit test function that tests the transformWorkerVolumes method of the AlluxioEngine. +// It defines a series of test cases to verify the correctness of volume and volume mount transformations for the Alluxio worker. +// Each test case includes an input AlluxioRuntime object and an expected Alluxio object, along with a flag to indicate if an error is expected. +// The function iterates through each test case, applies the transformWorkerVolumes method, and checks if the output matches the expected result. +// If an error occurs and it is not expected, or if the output does not match the expected result, the test fails with an appropriate error message. func TestTransformWorkerVolumes(t *testing.T) { + // Define a testCase struct to represent each test case. type testCase struct { - name string - runtime *datav1alpha1.AlluxioRuntime - expect *Alluxio - expectErr bool + name string // Name of the test case. + runtime *datav1alpha1.AlluxioRuntime // Input AlluxioRuntime object. + expect *Alluxio // Expected Alluxio object after transformation. + expectErr bool // Flag to indicate if an error is expected. } + // Define a list of test cases to be executed. testCases := []testCase{ { - name: "all", + name: "all", // Test case name. runtime: &datav1alpha1.AlluxioRuntime{ Spec: datav1alpha1.AlluxioRuntimeSpec{ - Volumes: []corev1.Volume{ + Volumes: []corev1.Volume{ // Define volumes in the runtime. { Name: "test", VolumeSource: corev1.VolumeSource{ Secret: &corev1.SecretVolumeSource{ - SecretName: "test", + SecretName: "test", // Use a secret as the volume source. }, }, }, - }, Worker: datav1alpha1.AlluxioCompTemplateSpec{ - VolumeMounts: []corev1.VolumeMount{ + }, + Worker: datav1alpha1.AlluxioCompTemplateSpec{ + VolumeMounts: []corev1.VolumeMount{ // Define volume mounts for the worker. { Name: "test", - MountPath: "/test", + MountPath: "/test", // Mount path for the volume. }, }, }, @@ -167,33 +175,35 @@ func TestTransformWorkerVolumes(t *testing.T) { }, expect: &Alluxio{ Worker: Worker{ - Volumes: []corev1.Volume{ + Volumes: []corev1.Volume{ // Expected volumes in the Alluxio worker. { Name: "test", VolumeSource: corev1.VolumeSource{ Secret: &corev1.SecretVolumeSource{ - SecretName: "test", + SecretName: "test", // Expected secret volume source. }, }, }, - }, VolumeMounts: []corev1.VolumeMount{ + }, + VolumeMounts: []corev1.VolumeMount{ // Expected volume mounts in the Alluxio worker. { Name: "test", - MountPath: "/test", + MountPath: "/test", // Expected mount path. }, }, }, }, - expectErr: false, - }, { - name: "onlyVolumeMounts", + expectErr: false, // No error is expected for this test case. + }, + { + name: "onlyVolumeMounts", // Test case name. runtime: &datav1alpha1.AlluxioRuntime{ Spec: datav1alpha1.AlluxioRuntimeSpec{ Worker: datav1alpha1.AlluxioCompTemplateSpec{ - VolumeMounts: []corev1.VolumeMount{ + VolumeMounts: []corev1.VolumeMount{ // Define only volume mounts without volumes. { Name: "test", - MountPath: "/test", + MountPath: "/test", // Mount path for the volume. }, }, }, @@ -201,45 +211,49 @@ func TestTransformWorkerVolumes(t *testing.T) { }, expect: &Alluxio{ Worker: Worker{ - Volumes: []corev1.Volume{ + Volumes: []corev1.Volume{ // Expected volumes in the Alluxio worker. { Name: "test", VolumeSource: corev1.VolumeSource{ Secret: &corev1.SecretVolumeSource{ - SecretName: "test", + SecretName: "test", // Expected secret volume source. }, }, }, - }, VolumeMounts: []corev1.VolumeMount{ + }, + VolumeMounts: []corev1.VolumeMount{ // Expected volume mounts in the Alluxio worker. { Name: "test", - MountPath: "/test", + MountPath: "/test", // Expected mount path. }, }, }, }, - expectErr: true, + expectErr: true, // An error is expected for this test case due to missing volumes. }, } + // Iterate through each test case and execute the test. for _, testCase := range testCases { - engine := &AlluxioEngine{} - got := &Alluxio{} - err := engine.transformWorkerVolumes(testCase.runtime, got) + engine := &AlluxioEngine{} // Initialize the AlluxioEngine. + got := &Alluxio{} // Initialize the output Alluxio object. + err := engine.transformWorkerVolumes(testCase.runtime, got) // Apply the transformation. + + // Check if an error occurred and handle accordingly. if err != nil && !testCase.expectErr { - t.Errorf("Got unexpected error %v", err) + t.Errorf("Got unexpected error %v", err) // Fail the test if an unexpected error occurs. } + // Skip further checks if an error is expected. if testCase.expectErr { continue } + // Compare the output with the expected result. if !reflect.DeepEqual(got, testCase.expect) { - t.Errorf("want %v, got %v for testcase %s", testCase.expect, got, testCase.name) + t.Errorf("want %v, got %v for testcase %s", testCase.expect, got, testCase.name) // Fail the test if the output does not match the expected result. } - } - } func TestTransformFuseVolumes(t *testing.T) { From d31acd2d4b8795dcc837993e71926fee0b95e75f Mon Sep 17 00:00:00 2001 From: Sirilaw <480469140@qq.com> Date: Sun, 9 Mar 2025 03:24:09 -0700 Subject: [PATCH 2/3] Add Comments to TestTransformWorkerValumes in pkg/ddc/alluxio/transform_volumes_test.go Signed-off-by: Sirilaw <480469140@qq.com> --- pkg/ddc/alluxio/transform_volumes_test.go | 62 ++++++++++------------- 1 file changed, 27 insertions(+), 35 deletions(-) diff --git a/pkg/ddc/alluxio/transform_volumes_test.go b/pkg/ddc/alluxio/transform_volumes_test.go index 2d581890f4a..5313da08c8c 100644 --- a/pkg/ddc/alluxio/transform_volumes_test.go +++ b/pkg/ddc/alluxio/transform_volumes_test.go @@ -139,35 +139,32 @@ func TestTransformMasterVolumes(t *testing.T) { // The function iterates through each test case, applies the transformWorkerVolumes method, and checks if the output matches the expected result. // If an error occurs and it is not expected, or if the output does not match the expected result, the test fails with an appropriate error message. func TestTransformWorkerVolumes(t *testing.T) { - // Define a testCase struct to represent each test case. type testCase struct { - name string // Name of the test case. - runtime *datav1alpha1.AlluxioRuntime // Input AlluxioRuntime object. - expect *Alluxio // Expected Alluxio object after transformation. - expectErr bool // Flag to indicate if an error is expected. + name string + runtime *datav1alpha1.AlluxioRuntime + expect *Alluxio + expectErr bool } - - // Define a list of test cases to be executed. testCases := []testCase{ { - name: "all", // Test case name. + name: "all", runtime: &datav1alpha1.AlluxioRuntime{ Spec: datav1alpha1.AlluxioRuntimeSpec{ - Volumes: []corev1.Volume{ // Define volumes in the runtime. + Volumes: []corev1.Volume{ { Name: "test", VolumeSource: corev1.VolumeSource{ Secret: &corev1.SecretVolumeSource{ - SecretName: "test", // Use a secret as the volume source. + SecretName: "test", }, }, }, }, Worker: datav1alpha1.AlluxioCompTemplateSpec{ - VolumeMounts: []corev1.VolumeMount{ // Define volume mounts for the worker. + VolumeMounts: []corev1.VolumeMount{ { Name: "test", - MountPath: "/test", // Mount path for the volume. + MountPath: "/test", }, }, }, @@ -175,35 +172,35 @@ func TestTransformWorkerVolumes(t *testing.T) { }, expect: &Alluxio{ Worker: Worker{ - Volumes: []corev1.Volume{ // Expected volumes in the Alluxio worker. + Volumes: []corev1.Volume{ { Name: "test", VolumeSource: corev1.VolumeSource{ Secret: &corev1.SecretVolumeSource{ - SecretName: "test", // Expected secret volume source. + SecretName: "test", }, }, }, }, - VolumeMounts: []corev1.VolumeMount{ // Expected volume mounts in the Alluxio worker. + VolumeMounts: []corev1.VolumeMount{ { Name: "test", - MountPath: "/test", // Expected mount path. + MountPath: "/test", }, }, }, }, - expectErr: false, // No error is expected for this test case. + expectErr: false, }, { - name: "onlyVolumeMounts", // Test case name. + name: "onlyVolumeMounts", runtime: &datav1alpha1.AlluxioRuntime{ Spec: datav1alpha1.AlluxioRuntimeSpec{ Worker: datav1alpha1.AlluxioCompTemplateSpec{ - VolumeMounts: []corev1.VolumeMount{ // Define only volume mounts without volumes. + VolumeMounts: []corev1.VolumeMount{ { Name: "test", - MountPath: "/test", // Mount path for the volume. + MountPath: "/test", }, }, }, @@ -211,47 +208,42 @@ func TestTransformWorkerVolumes(t *testing.T) { }, expect: &Alluxio{ Worker: Worker{ - Volumes: []corev1.Volume{ // Expected volumes in the Alluxio worker. + Volumes: []corev1.Volume{ { Name: "test", VolumeSource: corev1.VolumeSource{ Secret: &corev1.SecretVolumeSource{ - SecretName: "test", // Expected secret volume source. + SecretName: "test", }, }, }, }, - VolumeMounts: []corev1.VolumeMount{ // Expected volume mounts in the Alluxio worker. + VolumeMounts: []corev1.VolumeMount{ { Name: "test", - MountPath: "/test", // Expected mount path. + MountPath: "/test", }, }, }, }, - expectErr: true, // An error is expected for this test case due to missing volumes. + expectErr: true, }, } - - // Iterate through each test case and execute the test. for _, testCase := range testCases { - engine := &AlluxioEngine{} // Initialize the AlluxioEngine. - got := &Alluxio{} // Initialize the output Alluxio object. - err := engine.transformWorkerVolumes(testCase.runtime, got) // Apply the transformation. + engine := &AlluxioEngine{} + got := &Alluxio{} + err := engine.transformWorkerVolumes(testCase.runtime, got) - // Check if an error occurred and handle accordingly. if err != nil && !testCase.expectErr { - t.Errorf("Got unexpected error %v", err) // Fail the test if an unexpected error occurs. + t.Errorf("Got unexpected error %v", err) } - // Skip further checks if an error is expected. if testCase.expectErr { continue } - // Compare the output with the expected result. if !reflect.DeepEqual(got, testCase.expect) { - t.Errorf("want %v, got %v for testcase %s", testCase.expect, got, testCase.name) // Fail the test if the output does not match the expected result. + t.Errorf("want %v, got %v for testcase %s", testCase.expect, got, testCase.name) } } } From 94882995dd0842c0b25913147dcbdc8b980c8cc9 Mon Sep 17 00:00:00 2001 From: cheyang Date: Thu, 13 Mar 2025 10:27:02 +0800 Subject: [PATCH 3/3] Gofmt transform_volumes_test.go Signed-off-by: cheyang --- pkg/ddc/alluxio/transform_volumes_test.go | 54 +++++++++++------------ 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/pkg/ddc/alluxio/transform_volumes_test.go b/pkg/ddc/alluxio/transform_volumes_test.go index 5313da08c8c..daf8bb7589d 100644 --- a/pkg/ddc/alluxio/transform_volumes_test.go +++ b/pkg/ddc/alluxio/transform_volumes_test.go @@ -140,31 +140,31 @@ func TestTransformMasterVolumes(t *testing.T) { // If an error occurs and it is not expected, or if the output does not match the expected result, the test fails with an appropriate error message. func TestTransformWorkerVolumes(t *testing.T) { type testCase struct { - name string - runtime *datav1alpha1.AlluxioRuntime - expect *Alluxio - expectErr bool + name string + runtime *datav1alpha1.AlluxioRuntime + expect *Alluxio + expectErr bool } testCases := []testCase{ { - name: "all", + name: "all", runtime: &datav1alpha1.AlluxioRuntime{ Spec: datav1alpha1.AlluxioRuntimeSpec{ - Volumes: []corev1.Volume{ + Volumes: []corev1.Volume{ { Name: "test", VolumeSource: corev1.VolumeSource{ Secret: &corev1.SecretVolumeSource{ - SecretName: "test", + SecretName: "test", }, }, }, }, Worker: datav1alpha1.AlluxioCompTemplateSpec{ - VolumeMounts: []corev1.VolumeMount{ + VolumeMounts: []corev1.VolumeMount{ { Name: "test", - MountPath: "/test", + MountPath: "/test", }, }, }, @@ -172,35 +172,35 @@ func TestTransformWorkerVolumes(t *testing.T) { }, expect: &Alluxio{ Worker: Worker{ - Volumes: []corev1.Volume{ + Volumes: []corev1.Volume{ { Name: "test", VolumeSource: corev1.VolumeSource{ Secret: &corev1.SecretVolumeSource{ - SecretName: "test", + SecretName: "test", }, }, }, }, - VolumeMounts: []corev1.VolumeMount{ + VolumeMounts: []corev1.VolumeMount{ { Name: "test", - MountPath: "/test", + MountPath: "/test", }, }, }, }, - expectErr: false, + expectErr: false, }, { - name: "onlyVolumeMounts", + name: "onlyVolumeMounts", runtime: &datav1alpha1.AlluxioRuntime{ Spec: datav1alpha1.AlluxioRuntimeSpec{ Worker: datav1alpha1.AlluxioCompTemplateSpec{ - VolumeMounts: []corev1.VolumeMount{ + VolumeMounts: []corev1.VolumeMount{ { Name: "test", - MountPath: "/test", + MountPath: "/test", }, }, }, @@ -208,34 +208,34 @@ func TestTransformWorkerVolumes(t *testing.T) { }, expect: &Alluxio{ Worker: Worker{ - Volumes: []corev1.Volume{ + Volumes: []corev1.Volume{ { Name: "test", VolumeSource: corev1.VolumeSource{ Secret: &corev1.SecretVolumeSource{ - SecretName: "test", + SecretName: "test", }, }, }, }, - VolumeMounts: []corev1.VolumeMount{ + VolumeMounts: []corev1.VolumeMount{ { Name: "test", - MountPath: "/test", + MountPath: "/test", }, }, }, }, - expectErr: true, + expectErr: true, }, } for _, testCase := range testCases { - engine := &AlluxioEngine{} - got := &Alluxio{} - err := engine.transformWorkerVolumes(testCase.runtime, got) + engine := &AlluxioEngine{} + got := &Alluxio{} + err := engine.transformWorkerVolumes(testCase.runtime, got) if err != nil && !testCase.expectErr { - t.Errorf("Got unexpected error %v", err) + t.Errorf("Got unexpected error %v", err) } if testCase.expectErr { @@ -243,7 +243,7 @@ func TestTransformWorkerVolumes(t *testing.T) { } if !reflect.DeepEqual(got, testCase.expect) { - t.Errorf("want %v, got %v for testcase %s", testCase.expect, got, testCase.name) + t.Errorf("want %v, got %v for testcase %s", testCase.expect, got, testCase.name) } } }