@@ -79,17 +79,14 @@ func TestAlluxioEngine_GetDeprecatedCommonLabelname(t *testing.T) {
7979// This test verifies whether the HasDeprecatedCommonLabelname method can correctly identify if a DaemonSet
8080// contains deprecated label formats.
8181func TestAlluxioEngine_HasDeprecatedCommonLabelname (t * testing.T ) {
82- // Create a DaemonSet with a specific node selector.
83- // This DaemonSet uses a deprecated label format: "data.fluid.io/storage-<runtime>-<dataset>"
8482 daemonSetWithSelector := & v1.DaemonSet {
8583 ObjectMeta : metav1.ObjectMeta {
86- Name : "hbase-worker" , // workload name
87- Namespace : "fluid" , // namespace
84+ Name : "hbase-worker" ,
85+ Namespace : "fluid" ,
8886 },
8987 Spec : v1.DaemonSetSpec {
9088 Template : corev1.PodTemplateSpec {
9189 Spec : corev1.PodSpec {
92- // Node selector uses the deprecated label format
9390 NodeSelector : map [string ]string {
9491 "data.fluid.io/storage-fluid-hbase" : "selector" ,
9592 },
@@ -98,16 +95,14 @@ func TestAlluxioEngine_HasDeprecatedCommonLabelname(t *testing.T) {
9895 },
9996 }
10097
101- // Create another DaemonSet (different name but same deprecated label format)
10298 daemonSetWithoutSelector := & v1.DaemonSet {
10399 ObjectMeta : metav1.ObjectMeta {
104- Name : "hadoop-worker" , // different workload
105- Namespace : "fluid" , // same namespace
100+ Name : "hadoop-worker" ,
101+ Namespace : "fluid" , /
106102 },
107103 Spec : v1.DaemonSetSpec {
108104 Template : corev1.PodTemplateSpec {
109105 Spec : corev1.PodSpec {
110- // Also uses the deprecated label format
111106 NodeSelector : map [string ]string {
112107 "data.fluid.io/storage-fluid-hbase" : "selector" ,
113108 },
@@ -116,56 +111,46 @@ func TestAlluxioEngine_HasDeprecatedCommonLabelname(t *testing.T) {
116111 },
117112 }
118113
119- // Prepare Kubernetes API objects for testing
120114 runtimeObjs := []runtime.Object {}
121115 runtimeObjs = append (runtimeObjs , daemonSetWithSelector )
122116 runtimeObjs = append (runtimeObjs , daemonSetWithoutSelector )
123- // Create Scheme and register API types
124117 scheme := runtime .NewScheme ()
125118 scheme .AddKnownTypes (v1 .SchemeGroupVersion , daemonSetWithSelector )
126- // Use a fake client to simulate Kubernetes API
127119 fakeClient := fake .NewFakeClientWithScheme (scheme , runtimeObjs ... )
128- // Define test cases
129120 testCases := []struct {
130- name string // dataset name
131- namespace string // namespace
132- out bool // expected result
133- isErr bool // whether an error is expected
121+ name string
122+ namespace string
123+ out bool
124+ isErr bool
134125 }{
135126 {
136- name : "hbase" , // matches an existing DaemonSet
127+ name : "hbase" ,
137128 namespace : "fluid" ,
138- out : true , // should detect deprecated label
129+ out : true ,
139130 isErr : false ,
140131 },
141132 {
142- name : "none" , // dataset does not exist
133+ name : "none" ,
143134 namespace : "fluid" ,
144- out : false , // should not detect deprecated label
135+ out : false ,
145136 isErr : false ,
146137 },
147138 {
148- name : "hadoop" , // DaemonSet exists but name does not match
139+ name : "hadoop" ,
149140 namespace : "fluid" ,
150- out : false , // should not detect deprecated label
141+ out : false ,
151142 isErr : false ,
152143 },
153144 }
154-
155- // Execute all test cases
156145 for _ , test := range testCases {
157- // Create an Alluxio engine instance for the current test case
158146 engine := getTestAlluxioEngine (fakeClient , test .name , test .namespace )
159- // Call the method under test
160147 out , err := engine .HasDeprecatedCommonLabelname ()
161- // Validate the result
162148 if out != test .out {
163149 t .Errorf (
164150 "Dataset %s/%s test failed: expected %t, got %t" ,
165151 test .namespace , test .name , test .out , out ,
166152 )
167153 }
168- // Validate error expectation
169154 isErr := err != nil
170155 if isErr != test .isErr {
171156 t .Errorf (
0 commit comments