@@ -62,33 +62,49 @@ func TestIsFluidNativeScheme(t *testing.T) {
6262 }
6363}
6464
65+ // TestAlluxioEngine_getInitUserDir tests the getInitUserDir method of AlluxioEngine.
66+ // It verifies that the method returns the expected directory path based on the namespace and name.
6567func TestAlluxioEngine_getInitUserDir (t * testing.T ) {
68+ // fields defines the structure of test input data for AlluxioEngine.
6669 type fields struct {
67- runtime * datav1alpha1.AlluxioRuntime
68- name string
69- namespace string
70- runtimeType string
71- Log logr.Logger
72- Client client.Client
73- retryShutdown int32
70+ runtime * datav1alpha1.AlluxioRuntime // The Alluxio runtime configuration.
71+ name string // Name of the Alluxio instance.
72+ namespace string // Kubernetes namespace of the instance.
73+ runtimeType string // Type of runtime (e.g., "alluxio").
74+ Log logr.Logger // Logger instance for logging.
75+ Client client.Client // Kubernetes client for interacting with the API server.
76+ retryShutdown int32 // Number of retries for shutdown operations.
7477 }
78+
79+ // tests defines a slice of test cases, each with a name, input fields, and expected output.
7580 tests := []struct {
76- name string
77- fields fields
78- want string
81+ name string // Name of the test case.
82+ fields fields // Input fields for the AlluxioEngine instance.
83+ want string // Expected output directory path.
7984 }{
80- {name : "test" ,
81- fields : fields {runtime : & datav1alpha1.AlluxioRuntime {
82- TypeMeta : v1.TypeMeta {},
83- ObjectMeta : v1.ObjectMeta {},
84- Spec : datav1alpha1.AlluxioRuntimeSpec {},
85- Status : datav1alpha1.RuntimeStatus {},
86- }, name : "test" , namespace : "default" , runtimeType : "alluxio" , Log : fake .NullLogger ()},
87- want : fmt .Sprintf ("/tmp/fluid/%s/%s" , "default" , "test" ),
85+ {
86+ name : "test" , // Test case name.
87+ fields : fields {
88+ runtime : & datav1alpha1.AlluxioRuntime {
89+ TypeMeta : v1.TypeMeta {}, // Metadata about the type (kind, API version).
90+ ObjectMeta : v1.ObjectMeta {}, // Object metadata (e.g., name, namespace).
91+ Spec : datav1alpha1.AlluxioRuntimeSpec {}, // Specification of the Alluxio runtime.
92+ Status : datav1alpha1.RuntimeStatus {}, // Status of the Alluxio runtime.
93+ },
94+ name : "test" , // Alluxio instance name set to "test".
95+ namespace : "default" , // Namespace set to "default".
96+ runtimeType : "alluxio" , // Runtime type set to "alluxio".
97+ Log : fake .NullLogger (), // Use a null logger for testing (no actual logging).
98+ },
99+ want : fmt .Sprintf ("/tmp/fluid/%s/%s" , "default" , "test" ), // Expected output: "/tmp/fluid/default/test".
88100 },
89101 }
102+
103+ // Iterate over each test case.
90104 for _ , tt := range tests {
105+ // t.Run runs a subtest with the given test case name.
91106 t .Run (tt .name , func (t * testing.T ) {
107+ // Initialize an AlluxioEngine instance with the test case fields.
92108 e := & AlluxioEngine {
93109 runtime : tt .fields .runtime ,
94110 name : tt .fields .name ,
@@ -98,7 +114,10 @@ func TestAlluxioEngine_getInitUserDir(t *testing.T) {
98114 Client : tt .fields .Client ,
99115 retryShutdown : tt .fields .retryShutdown ,
100116 }
117+
118+ // Call getInitUserDir and compare the result with the expected value.
101119 if got := e .getInitUserDir (); got != tt .want {
120+ // If the result doesn't match, fail the test and report the mismatch.
102121 t .Errorf ("AlluxioEngine.getInitUserDir() = %v, want %v" , got , tt .want )
103122 }
104123 })
0 commit comments