diff --git a/pkg/ddc/alluxio/utils_test.go b/pkg/ddc/alluxio/utils_test.go index 32db3ab0ca5..5c4ecce51f4 100644 --- a/pkg/ddc/alluxio/utils_test.go +++ b/pkg/ddc/alluxio/utils_test.go @@ -361,6 +361,35 @@ func TestGetDataSetFileNum(t *testing.T) { } } +// TestGetRuntime tests the AlluxioEngine.getRuntime() method to verify it correctly retrieves +// the AlluxioRuntime custom resource from the Kubernetes cluster. +// +// Test Structure: +// - Defines a test table with multiple test cases (though currently only one example exists). +// - Each test case specifies: +// * Input fields: Simulated AlluxioEngine instance configuration. +// * Expected output: The AlluxioRuntime object that should be returned. +// * Error expectation: Whether an error is expected during retrieval. +// +// Key Testing Components: +// - Uses Kubernetes client-go testing utilities (fake client, scheme registration) to mock +// API server interactions, avoiding real cluster dependencies. +// - Validates both successful retrieval and error conditions. +// - Checks deep equality between retrieved and expected objects to ensure metadata accuracy. +// +// Test Workflow for Each Case: +// 1. Register required Kubernetes resource types (AlluxioRuntime, core v1) into the scheme. +// 2. Initialize a fake client preloaded with the expected AlluxioRuntime object. +// 3. Instantiate the AlluxioEngine with test-specific configurations and the fake client. +// 4. Execute getRuntime() and validate: +// - Error behavior matches expectations +// - Retrieved object matches the expected object structure exactly +// +// Edge Cases Covered (via additional test cases in TODO): +// - Non-existent runtime +// - Invalid namespace/name configurations +// - API version/kind mismatches +// - Cluster connection failures (simulated via client misconfiguration) func TestGetRuntime(t *testing.T) { type fields struct { runtime *datav1alpha1.AlluxioRuntime