From a86732e9a677c18e2af30c1f9972782495200d24 Mon Sep 17 00:00:00 2001 From: dorr <1836196933@qq.com> Date: Mon, 10 Mar 2025 23:28:30 +0800 Subject: [PATCH 1/2] Add comments to TestTransformDatasetToVolume function in pkg/ddc/alluxio/transform_ufs_test.go Signed-off-by: dorr <1836196933@qq.com> --- pkg/ddc/alluxio/transform_ufs_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/ddc/alluxio/transform_ufs_test.go b/pkg/ddc/alluxio/transform_ufs_test.go index 6e213feb0c2..020ac44960f 100644 --- a/pkg/ddc/alluxio/transform_ufs_test.go +++ b/pkg/ddc/alluxio/transform_ufs_test.go @@ -23,6 +23,15 @@ import ( v1 "k8s.io/api/core/v1" ) +// TestTransformDatasetToVolume is a unit test function that verifies the transformation of a Dataset into a UFSPath +// in the Alluxio runtime. It ensures that the Dataset's mount points are correctly converted into corresponding +// container and host paths. +// +// Parameters: +// - t: *testing.T, the Go testing framework's object used to manage the test execution and report failures. +// +// Return value: +// - None (this is a test function, and it does not return any values). func TestTransformDatasetToVolume(t *testing.T) { var ufsPath = UFSPath{} ufsPath.Name = "test" From b162ab77a76eee4b40735cc0181610d5dcb2ecfb Mon Sep 17 00:00:00 2001 From: dorr <1836196933@qq.com> Date: Mon, 10 Mar 2025 23:54:46 +0800 Subject: [PATCH 2/2] Add comments to TestTransformDatasetToVolume function in pkg/ddc/alluxio/transform_ufs_test.go Signed-off-by: dorr <1836196933@qq.com> --- pkg/ddc/alluxio/transform_ufs_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/ddc/alluxio/transform_ufs_test.go b/pkg/ddc/alluxio/transform_ufs_test.go index 020ac44960f..7ae5394355b 100644 --- a/pkg/ddc/alluxio/transform_ufs_test.go +++ b/pkg/ddc/alluxio/transform_ufs_test.go @@ -33,6 +33,7 @@ import ( // Return value: // - None (this is a test function, and it does not return any values). func TestTransformDatasetToVolume(t *testing.T) { + // Initialize UFSPath variables for expected results. var ufsPath = UFSPath{} ufsPath.Name = "test" ufsPath.HostPath = "/mnt/test" @@ -43,12 +44,14 @@ func TestTransformDatasetToVolume(t *testing.T) { ufsPath1.HostPath = "/mnt/test" ufsPath1.ContainerPath = "/underFSStorage" + // Define test cases with different Dataset configurations var tests = []struct { runtime *datav1alpha1.AlluxioRuntime dataset *datav1alpha1.Dataset value *Alluxio expect UFSPath }{ + // Test case 1: Simple Mount configuration {&datav1alpha1.AlluxioRuntime{}, &datav1alpha1.Dataset{ Spec: datav1alpha1.DatasetSpec{ Mounts: []datav1alpha1.Mount{{ @@ -57,6 +60,8 @@ func TestTransformDatasetToVolume(t *testing.T) { }}, }, }, &Alluxio{}, ufsPath}, + + // Test case 2: Mount with a path specified {&datav1alpha1.AlluxioRuntime{}, &datav1alpha1.Dataset{ Spec: datav1alpha1.DatasetSpec{ Mounts: []datav1alpha1.Mount{{ @@ -67,11 +72,17 @@ func TestTransformDatasetToVolume(t *testing.T) { }, }, &Alluxio{}, ufsPath1}, } + + // Iterate through all test cases and run the test. for _, test := range tests { + // Create an instance of AlluxioEngine to call the function under test. engine := &AlluxioEngine{} + // Call the function that we want to test. engine.transformDatasetToVolume(test.runtime, test.dataset, test.value) + // Compare the actual result with the expected result. if test.value.UFSPaths[0].HostPath != test.expect.HostPath || test.value.UFSPaths[0].ContainerPath != test.expect.ContainerPath { + // If the result doesn't match the expected values, report an error. t.Errorf("expected %v, got %v", test.expect, test.value.UFSPaths[0]) } }