From ef26dc36152a2d9cf45e4eead50c07e8876af6e8 Mon Sep 17 00:00:00 2001 From: Zhangggggggggg <1253360905@qq.com> Date: Thu, 12 Jun 2025 19:36:44 +0800 Subject: [PATCH 1/3] Add comments to TestShouldCheckUFS in pkg/ddc/alluxio/ufs_test.go. Signed-off-by: Zhangggggggggg <1253360905@qq.com> --- pkg/ddc/alluxio/ufs_test.go | 56 ++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/pkg/ddc/alluxio/ufs_test.go b/pkg/ddc/alluxio/ufs_test.go index a8271c2c43a..e5de783d23f 100644 --- a/pkg/ddc/alluxio/ufs_test.go +++ b/pkg/ddc/alluxio/ufs_test.go @@ -583,15 +583,57 @@ func TestTotalFileNums(t *testing.T) { } } -// TestFindUnmountedUFS verifies if AlluxioEngine's FindUnmountedUFS method correctly identifies -// UFS paths that should be considered for mounting based on their scheme. -// It iterates through predefined test cases, each with a set of mount points and the expected -// unmounted paths. For each case, it mocks the necessary dependencies, calls FindUnmountedUFS, -// and then compares the returned unmounted paths with the expected ones. +// TestShouldCheckUFS validates the AlluxioEngine's logic for determining whether +// it should perform a check on the Under File System (UFS). // -// param: t *testing.T - The testing context used for running the test and reporting failures. +// The test performs the following operations: +// - Initializes a minimal AlluxioEngine instance +// - Invokes the ShouldCheckUFS() method +// - Verifies the boolean result and error status // -// returns: None (This is a test function and does not return any value.) +// Test Components: +// - tests: A table-driven slice defining expected outcomes for each case +// +// Flow: +// 1. Construct a new AlluxioEngine instance (with default or minimal config) +// 2. Call the ShouldCheckUFS() method +// 3. Check if the returned value matches expected 'wantShould' +// 4. Validate that the presence or absence of an error matches 'wantErr' +// +// Note: +// - This test assumes default internal state is sufficient for logic evaluation +// - It can be extended to include more cases or mocked dependencies if needed +func TestShouldCheckUFS(t *testing.T) { + tests := []struct { + name string + wantShould bool + wantErr bool + }{ + { + name: "test", + wantShould: true, + wantErr: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + e := &AlluxioEngine{} + gotShould, err := e.ShouldCheckUFS() + if (err != nil) != tt.wantErr { + t.Errorf("AlluxioEngine.ShouldCheckUFS() error = %v, wantErr %v", err, tt.wantErr) + return + } + if gotShould != tt.wantShould { + t.Errorf("AlluxioEngine.ShouldCheckUFS() = %v, want %v", gotShould, tt.wantShould) + } + }) + } +} + +// TestPrepareUFS tests the PrepareUFS method of AlluxioEngine. +// This method prepares the underlying file system (UFS) by checking +// the Alluxio master state, mounting UFS, and performing necessary +// metadata synchronization. func TestFindUnmountedUFS(t *testing.T) { type fields struct { From ace62022355cb24ce073ffe85e8e00c5e6b0cbae Mon Sep 17 00:00:00 2001 From: Zhangggggggggg <1253360905@qq.com> Date: Thu, 12 Jun 2025 20:28:43 +0800 Subject: [PATCH 2/3] Add comments to newTestJindoEngine in pkg/ddc/jindo/delete_volume_test.go. Signed-off-by: Zhangggggggggg <1253360905@qq.com> --- pkg/ddc/jindo/delete_volume_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/ddc/jindo/delete_volume_test.go b/pkg/ddc/jindo/delete_volume_test.go index 1ca108088a1..81e291c9bd1 100644 --- a/pkg/ddc/jindo/delete_volume_test.go +++ b/pkg/ddc/jindo/delete_volume_test.go @@ -38,6 +38,20 @@ type TestCase struct { isErr bool } +// newTestJindoEngine creates a mock JindoEngine instance for testing purposes. +// This helper function is used to simulate JindoEngine behavior under different runtime conditions. +// It accepts a Kubernetes client, a runtime name and namespace, and a boolean flag indicating whether +// to initialize the engine with a runtime. +// +// Parameters: +// - client: a fake or real Kubernetes client used by the engine to interact with cluster resources. +// - name: the name of the JindoRuntime, used to build runtime metadata. +// - namespace: the namespace of the JindoRuntime. +// - withRunTime: if true, the engine will be initialized with a valid JindoRuntime and runtimeInfo; +// if false, the runtime and runtimeInfo will be set to nil, simulating a missing runtime. +// +// Returns: +// - A pointer to the initialized JindoEngine instance, ready for use in unit tests. func newTestJindoEngine(client client.Client, name string, namespace string, withRunTime bool) *JindoEngine { runTime := &datav1alpha1.JindoRuntime{} runTimeInfo, _ := base.BuildRuntimeInfo(name, namespace, common.JindoRuntime) From dc35b588dacdefce6bb1d3c94bf5d59d9660e9f8 Mon Sep 17 00:00:00 2001 From: cheyang Date: Mon, 15 Sep 2025 15:41:39 +0800 Subject: [PATCH 3/3] Update comments of function newTestJindoEngine Signed-off-by: cheyang --- pkg/ddc/alluxio/ufs_test.go | 56 +++++-------------------------------- 1 file changed, 7 insertions(+), 49 deletions(-) diff --git a/pkg/ddc/alluxio/ufs_test.go b/pkg/ddc/alluxio/ufs_test.go index e5de783d23f..a8271c2c43a 100644 --- a/pkg/ddc/alluxio/ufs_test.go +++ b/pkg/ddc/alluxio/ufs_test.go @@ -583,57 +583,15 @@ func TestTotalFileNums(t *testing.T) { } } -// TestShouldCheckUFS validates the AlluxioEngine's logic for determining whether -// it should perform a check on the Under File System (UFS). +// TestFindUnmountedUFS verifies if AlluxioEngine's FindUnmountedUFS method correctly identifies +// UFS paths that should be considered for mounting based on their scheme. +// It iterates through predefined test cases, each with a set of mount points and the expected +// unmounted paths. For each case, it mocks the necessary dependencies, calls FindUnmountedUFS, +// and then compares the returned unmounted paths with the expected ones. // -// The test performs the following operations: -// - Initializes a minimal AlluxioEngine instance -// - Invokes the ShouldCheckUFS() method -// - Verifies the boolean result and error status -// -// Test Components: -// - tests: A table-driven slice defining expected outcomes for each case -// -// Flow: -// 1. Construct a new AlluxioEngine instance (with default or minimal config) -// 2. Call the ShouldCheckUFS() method -// 3. Check if the returned value matches expected 'wantShould' -// 4. Validate that the presence or absence of an error matches 'wantErr' +// param: t *testing.T - The testing context used for running the test and reporting failures. // -// Note: -// - This test assumes default internal state is sufficient for logic evaluation -// - It can be extended to include more cases or mocked dependencies if needed -func TestShouldCheckUFS(t *testing.T) { - tests := []struct { - name string - wantShould bool - wantErr bool - }{ - { - name: "test", - wantShould: true, - wantErr: false, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - e := &AlluxioEngine{} - gotShould, err := e.ShouldCheckUFS() - if (err != nil) != tt.wantErr { - t.Errorf("AlluxioEngine.ShouldCheckUFS() error = %v, wantErr %v", err, tt.wantErr) - return - } - if gotShould != tt.wantShould { - t.Errorf("AlluxioEngine.ShouldCheckUFS() = %v, want %v", gotShould, tt.wantShould) - } - }) - } -} - -// TestPrepareUFS tests the PrepareUFS method of AlluxioEngine. -// This method prepares the underlying file system (UFS) by checking -// the Alluxio master state, mounting UFS, and performing necessary -// metadata synchronization. +// returns: None (This is a test function and does not return any value.) func TestFindUnmountedUFS(t *testing.T) { type fields struct {