Skip to content

Commit d701637

Browse files
committed
test(fluidapp): deduplicate remaining sonar literals
Signed-off-by: Harsh <harshmastic@gmail.com>
1 parent 24bd5eb commit d701637

2 files changed

Lines changed: 23 additions & 21 deletions

File tree

pkg/controllers/v1alpha1/fluidapp/dataflowaffinity/dataflowaffinity_controller_test.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,12 @@ func newTestScheme() *runtime.Scheme {
4343

4444
var _ = Describe("DataOpJobReconciler", func() {
4545
const (
46-
controllerUIDKey = "controller-uid"
47-
testNodeName = "node01"
48-
testPodName = "test-pod"
46+
controllerUIDKey = "controller-uid"
47+
testNodeName = "node01"
48+
testPodName = "test-pod"
49+
testJobName = "test-job"
50+
customLabelKey = "custom-label"
51+
testControllerUID = "test-uid"
4952
)
5053

5154
var testScheme *runtime.Scheme
@@ -115,8 +118,6 @@ var _ = Describe("DataOpJobReconciler", func() {
115118

116119
Context("when job is a valid fluid job without affinity annotation", func() {
117120
It("injects the dataflow affinity annotation and returns no requeue", func() {
118-
const testJobName = "test-job"
119-
120121
job := &batchv1.Job{
121122
ObjectMeta: metav1.ObjectMeta{
122123
Name: testJobName,
@@ -211,13 +212,13 @@ var _ = Describe("DataOpJobReconciler", func() {
211212
common.K8sNodeNameLabelKey: testNodeName,
212213
common.K8sRegionLabelKey: "region01",
213214
common.K8sZoneLabelKey: "zone01",
214-
"custom-label": "custom-value",
215+
customLabelKey: "custom-value",
215216
}
216217
exposedLabelNames := []string{
217218
common.K8sNodeNameLabelKey,
218219
common.K8sRegionLabelKey,
219220
common.K8sZoneLabelKey,
220-
"custom-label",
221+
customLabelKey,
221222
}
222223

223224
fillCustomizedNodeAffinity(annotationsToInject, nodeLabels, exposedLabelNames)
@@ -226,7 +227,7 @@ var _ = Describe("DataOpJobReconciler", func() {
226227
Expect(annotationsToInject[common.AnnotationDataFlowCustomizedAffinityPrefix+common.K8sNodeNameLabelKey]).To(Equal(testNodeName))
227228
Expect(annotationsToInject[common.AnnotationDataFlowCustomizedAffinityPrefix+common.K8sRegionLabelKey]).To(Equal("region01"))
228229
Expect(annotationsToInject[common.AnnotationDataFlowCustomizedAffinityPrefix+common.K8sZoneLabelKey]).To(Equal("zone01"))
229-
Expect(annotationsToInject[common.AnnotationDataFlowCustomizedAffinityPrefix+"custom-label"]).To(Equal("custom-value"))
230+
Expect(annotationsToInject[common.AnnotationDataFlowCustomizedAffinityPrefix+customLabelKey]).To(Equal("custom-value"))
230231
})
231232

232233
It("skips non-existent labels", func() {
@@ -266,7 +267,7 @@ var _ = Describe("DataOpJobReconciler", func() {
266267
It("injects node labels as annotations onto the job", func() {
267268
job := &batchv1.Job{
268269
ObjectMeta: metav1.ObjectMeta{
269-
Name: "test-job",
270+
Name: testJobName,
270271
Labels: map[string]string{
271272
common.LabelAnnotationManagedBy: common.Fluid,
272273
},
@@ -376,15 +377,15 @@ var _ = Describe("DataOpJobReconciler", func() {
376377
It("returns an error", func() {
377378
job := &batchv1.Job{
378379
ObjectMeta: metav1.ObjectMeta{
379-
Name: "test-job",
380+
Name: testJobName,
380381
Labels: map[string]string{
381382
common.LabelAnnotationManagedBy: common.Fluid,
382383
},
383384
},
384385
Spec: batchv1.JobSpec{
385386
Selector: &metav1.LabelSelector{
386387
MatchLabels: map[string]string{
387-
controllerUIDKey: "test-uid",
388+
controllerUIDKey: testControllerUID,
388389
},
389390
},
390391
},
@@ -393,7 +394,7 @@ var _ = Describe("DataOpJobReconciler", func() {
393394
ObjectMeta: metav1.ObjectMeta{
394395
Name: testPodName,
395396
Labels: map[string]string{
396-
controllerUIDKey: "test-uid",
397+
controllerUIDKey: testControllerUID,
397398
},
398399
},
399400
Spec: v1.PodSpec{NodeName: ""},
@@ -413,7 +414,7 @@ var _ = Describe("DataOpJobReconciler", func() {
413414
It("creates the annotations map before injecting labels", func() {
414415
job := &batchv1.Job{
415416
ObjectMeta: metav1.ObjectMeta{
416-
Name: "test-job",
417+
Name: testJobName,
417418
Labels: map[string]string{
418419
common.LabelAnnotationManagedBy: common.Fluid,
419420
},
@@ -422,7 +423,7 @@ var _ = Describe("DataOpJobReconciler", func() {
422423
Spec: batchv1.JobSpec{
423424
Selector: &metav1.LabelSelector{
424425
MatchLabels: map[string]string{
425-
controllerUIDKey: "test-uid",
426+
controllerUIDKey: testControllerUID,
426427
},
427428
},
428429
},
@@ -431,7 +432,7 @@ var _ = Describe("DataOpJobReconciler", func() {
431432
ObjectMeta: metav1.ObjectMeta{
432433
Name: testPodName,
433434
Labels: map[string]string{
434-
controllerUIDKey: "test-uid",
435+
controllerUIDKey: testControllerUID,
435436
},
436437
},
437438
Spec: v1.PodSpec{NodeName: testNodeName},

pkg/controllers/v1alpha1/fluidapp/implement_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ import (
3232

3333
var _ = Describe("FluidAppReconcilerImplement", func() {
3434
const (
35-
fuseMountPath = "/mnt/fuse"
36-
juicefsFuseMount = "juicefs-fuse-mount"
37-
juicefsMountPath = "/mnt/jfs"
35+
fuseMountPath = "/mnt/fuse"
36+
juicefsFuseMount = "juicefs-fuse-mount"
37+
juicefsMountPath = "/mnt/jfs"
38+
shouldSucceedWithoutErrors = "should succeed without errors"
3839
)
3940

4041
Describe("NewFluidAppReconcilerImplement", func() {
@@ -66,7 +67,7 @@ var _ = Describe("FluidAppReconcilerImplement", func() {
6667
})
6768

6869
Context("when pod has no fuse containers", func() {
69-
It("should succeed without errors", func() {
70+
It(shouldSucceedWithoutErrors, func() {
7071
pod := &corev1.Pod{
7172
ObjectMeta: metav1.ObjectMeta{Name: "test"},
7273
Spec: corev1.PodSpec{
@@ -80,7 +81,7 @@ var _ = Describe("FluidAppReconcilerImplement", func() {
8081
})
8182

8283
Context("when fuse container has no mount path", func() {
83-
It("should succeed without errors", func() {
84+
It(shouldSucceedWithoutErrors, func() {
8485
pod := &corev1.Pod{
8586
ObjectMeta: metav1.ObjectMeta{Name: "test"},
8687
Spec: corev1.PodSpec{
@@ -94,7 +95,7 @@ var _ = Describe("FluidAppReconcilerImplement", func() {
9495
})
9596

9697
Context("when fuse container has prestop hook", func() {
97-
It("should succeed without errors", func() {
98+
It(shouldSucceedWithoutErrors, func() {
9899
pod := &corev1.Pod{
99100
ObjectMeta: metav1.ObjectMeta{Name: "test"},
100101
Spec: corev1.PodSpec{

0 commit comments

Comments
 (0)