Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/ddc/alluxio/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ import (
"k8s.io/apimachinery/pkg/types"
)

// TestBuild tests the build function by creating a fake client with predefined test objects.
// It verifies that the engine is successfully built without any errors.
// Parameters:
// - t *testing.T: The testing object used to report test results.
// Returns:
// - None. It reports test failures using t.Errorf if the build function fails.
func TestBuild(t *testing.T) {
var namespace = v1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Expand Down
3 changes: 2 additions & 1 deletion pkg/ddc/alluxio/load_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ func (e *AlluxioEngine) genDataLoadValue(image string, targetDataset *datav1alph
// It obtains master pod details, creates file utilities, and checks readiness.
//
// Returns:
// ready bool - Runtime readiness status (true = ready, false = not ready).
//
// ready bool - Runtime readiness status (true = ready, false = not ready).
func (e *AlluxioEngine) CheckRuntimeReady() (ready bool) {
podName, containerName := e.getMasterPodInfo()
fileUtils := operations.NewAlluxioFileUtils(podName, containerName, e.namespace, e.Log)
Expand Down
8 changes: 4 additions & 4 deletions pkg/ddc/alluxio/transform_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ func (e *AlluxioEngine) transformResourcesForMaster(runtime *datav1alpha1.Alluxi
}

// transformResourcesForWorker is responsible for transforming and setting resource limits for the Alluxio Worker component.
// This function updates the resource requirements for the Worker and JobWorker based on the runtime configuration
// This function updates the resource requirements for the Worker and JobWorker based on the runtime configuration
// and ensures that memory requests meet the required constraints.
//
// Parameters:
// - runtime: *datav1alpha1.AlluxioRuntime, the runtime configuration of Alluxio, including resource definitions
// for Worker and JobWorker.
// - runtime: *datav1alpha1.AlluxioRuntime, the runtime configuration of Alluxio, including resource definitions
// for Worker and JobWorker.
// - value: *Alluxio, the Alluxio runtime instance used to store the transformed resource information.
//
//
// Return value:
// - error: Returns an error if any issue occurs during resource transformation; otherwise, returns nil.
func (e *AlluxioEngine) transformResourcesForWorker(runtime *datav1alpha1.AlluxioRuntime, value *Alluxio) error {
Expand Down
12 changes: 6 additions & 6 deletions pkg/ddc/alluxio/transform_resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,12 +450,12 @@ func TestTransformResourcesForWorkerWithOnlyRequest(t *testing.T) {
// resource requests are handled as expected.
//
// The function performs the following steps:
// 1. Defines resource requirements with limits for memory (20Gi) and CPU (500m).
// 2. Sets up test cases to validate the transformation logic, including scenarios with and without
// tiered store configurations.
// 3. Initializes an AlluxioEngine instance with a fake client and runtime objects for testing.
// 4. Transforms the resource requirements for the worker using the AlluxioEngine.
// 5. Validates the transformed resource limits and requests against the expected results.
// 1. Defines resource requirements with limits for memory (20Gi) and CPU (500m).
// 2. Sets up test cases to validate the transformation logic, including scenarios with and without
// tiered store configurations.
// 3. Initializes an AlluxioEngine instance with a fake client and runtime objects for testing.
// 4. Transforms the resource requirements for the worker using the AlluxioEngine.
// 5. Validates the transformed resource limits and requests against the expected results.
//
// Test cases include:
// - A scenario where tiered store configuration is provided, ensuring memory limits and requests are set correctly.
Expand Down
10 changes: 5 additions & 5 deletions pkg/ddc/alluxio/transform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ func TestTransformMaster(t *testing.T) {
}
}

// TestTransformWorkers verifies that the transformWorkers function correctly transforms
// the worker configuration of AlluxioRuntime into the expected Alluxio structure.
// It tests different network modes, node selectors, and image pull secrets to ensure
// TestTransformWorkers verifies that the transformWorkers function correctly transforms
// the worker configuration of AlluxioRuntime into the expected Alluxio structure.
// It tests different network modes, node selectors, and image pull secrets to ensure
// correct transformation behavior.
func TestTransformWorkers(t *testing.T) {
testCases := map[string]struct {
Expand Down Expand Up @@ -882,10 +882,10 @@ func TestAlluxioEngine_allocatePorts(t *testing.T) {
//
// Test Cases:
// 1. "master properties is not null":
// - Ensures that when master-specific properties exist, they override the global properties.
// - Ensures that when master-specific properties exist, they override the global properties.
//
// 2. "properties is not null for master":
// - Ensures that both master-specific and additional global properties are correctly handled.
// - Ensures that both master-specific and additional global properties are correctly handled.
//
// The function iterates over multiple test cases and checks if the transformed properties
// match the expected values. If the transformation does not produce the expected result, the test fails.
Expand Down
4 changes: 2 additions & 2 deletions pkg/ddc/jindo/dataset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ func TestUpdateDatasetStatus(t *testing.T) {
}
}

// TestBindToDataset tests the BindToDataset method of JindoEngine to verify whether it can correctly bind the dataset to the runtime
// and update the dataset's cache state and HCFS status. The test creates mock Dataset and JindoRuntime objects,
// TestBindToDataset tests the BindToDataset method of JindoEngine to verify whether it can correctly bind the dataset to the runtime
// and update the dataset's cache state and HCFS status. The test creates mock Dataset and JindoRuntime objects,
// uses a fake client to simulate operations, and finally checks if the dataset's Phase, CacheStates, and HCFSStatus match the expected results.
func TestBindToDataset(t *testing.T) {
testDatasetInputs := []*datav1alpha1.Dataset{
Expand Down
26 changes: 13 additions & 13 deletions pkg/ddc/jindo/delete_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,19 @@ func doTestCases(testCases []TestCase, t *testing.T) {
//
// Test Strategy:
// 1. Setup test environment with mocked Kubernetes resources:
// - PVs with 'CreatedBy=fluid' annotation to simulate Fluid-managed persistent volumes
// - PVCs with different configurations (normal vs error cases)
// 2. Create 3 test scenarios using parameterized test pattern:
// Case 1: Normal deletion (JindoEngineCommon)
// - Input: Valid PV/PVC without conflicting annotations
// - Expected: Successful deletion (isDeleted=true, isErr=false)
// Case 2: Protected PVC deletion (JindoEngineErr)
// - Input: PVC with 'CreatedBy=fluid' annotation (protected resource)
// - Expected: Failed deletion (isErr=true)
// Case 3: Missing runtime scenario (JindoEngineNoRunTime)
// - Input: Engine with runtime=false configuration
// - Expected: Failed deletion (isErr=true)
// 3. Verification: Uses doTestCases() helper to validate deletion outcomes against expectations
// - PVs with 'CreatedBy=fluid' annotation to simulate Fluid-managed persistent volumes
// - PVCs with different configurations (normal vs error cases)
// 2. Create 3 test scenarios using parameterized test pattern:
// Case 1: Normal deletion (JindoEngineCommon)
// - Input: Valid PV/PVC without conflicting annotations
// - Expected: Successful deletion (isDeleted=true, isErr=false)
// Case 2: Protected PVC deletion (JindoEngineErr)
// - Input: PVC with 'CreatedBy=fluid' annotation (protected resource)
// - Expected: Failed deletion (isErr=true)
// Case 3: Missing runtime scenario (JindoEngineNoRunTime)
// - Input: Engine with runtime=false configuration
// - Expected: Failed deletion (isErr=true)
// 3. Verification: Uses doTestCases() helper to validate deletion outcomes against expectations
//
// Test Resources:
// - fake.NewFakeClientWithScheme: Simulates Kubernetes API server with predefined resources
Expand Down
2 changes: 1 addition & 1 deletion pkg/ddc/juicefs/datasetinfo_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func TestGetFSInfoFromConfigMap(t *testing.T) {
}

// Test_parseFSInfoFromConfigMap is a unit test function for the parseFSInfoFromConfigMap method.
// It validates whether the function correctly extracts and parses dataset information
// It validates whether the function correctly extracts and parses dataset information
// from a given Kubernetes ConfigMap.
//
// Steps:
Expand Down
11 changes: 6 additions & 5 deletions pkg/ddc/juicefs/delete_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ type TestCase struct {

// newTestJuiceEngine creates a JuiceFSEngine for testing
// Parameters:
// - client: fake client
// - client: fake client
// - name: the name of the JuiceFS engine
// - namespace: the namespace of the JuiceFS engine
// - withRunTime: whether the JuiceFS engine has runtime
//
// Returns:
// - JuiceFSEngine: the JuiceFS engine for testing
func newTestJuiceEngine(client client.Client, name string, namespace string, withRunTime bool) *JuiceFSEngine {
// 1. Create a JuiceFSRuntime and RuntimeInfo
// 1. Create a JuiceFSRuntime and RuntimeInfo
runTime := &datav1alpha1.JuiceFSRuntime{}
runTimeInfo, _ := base.BuildRuntimeInfo(name, namespace, common.JuiceFSRuntime)
// 2. If the JuiceFS engine does not have runtime, set the runtime and runtimeInfo to nil
Expand Down Expand Up @@ -214,17 +215,17 @@ func TestJuiceFSEngine_deleteFusePersistentVolume(t *testing.T) {
// - Proper handling of PVC finalizers (e.g., kubernetes.io/pvc-protection)
// - Failure scenarios when Runtime integration is disabled
// - Interaction with mocked Kubernetes API using fake client
//
//
// The test suite includes two primary cases:
// 1. Normal deletion with Runtime enabled (expected success)
// 2. Deletion failure when Runtime is disabled (simulates missing dependency)
//
//
// Setup steps:
// - Creates test PVCs with protection finalizer to simulate real-world conditions
// - Uses deep copies to ensure test data isolation
// - Configures fake client with predefined test objects for controlled testing
// - Exercises both enabled/disabled Runtime engine variations
//
//
// This test ensures JuiceFS Engine correctly handles PVC lifecycle operations while respecting Kubernetes resource protection mechanisms.
func TestJuiceFSEngine_deleteFusePersistentVolumeClaim(t *testing.T) {
testPVCInputs := []*v1.PersistentVolumeClaim{
Expand Down
Loading