Skip to content

Commit bc253fd

Browse files
scotwellsclaude
andcommitted
fix(lint): dedupe test fixture constants for goconst
Extract shared WorkloadDeployment test fixtures (cityCode, wdControllerTestUID) and the quota-denied message into package-level constants so goconst no longer flags repeated string literals across the controller test files. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 4ff51ab commit bc253fd

4 files changed

Lines changed: 29 additions & 23 deletions

File tree

internal/controller/instance_controller_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ const (
4646
testQuotaAPIGroup = "quota.miloapis.com"
4747
testQuotaResource = "resourceclaims"
4848
kindWorkloadDeploymentTest = "WorkloadDeployment" // mirrors kindWorkloadDeployment
49+
50+
// testMsgQuotaExceeded is the quota-denied message used across quota tests.
51+
testMsgQuotaExceeded = "Quota exceeded for project"
4952
)
5053

5154
// newTestScheme builds a runtime.Scheme with the types needed for instance reconcile tests.
@@ -345,7 +348,7 @@ func TestReconcileInstanceReadyConditionWithQuota(t *testing.T) {
345348
Type: computev1alpha.InstanceQuotaGranted,
346349
Status: metav1.ConditionFalse,
347350
Reason: computev1alpha.InstanceQuotaGrantedReasonQuotaExceeded,
348-
Message: "Quota exceeded for project",
351+
Message: testMsgQuotaExceeded,
349352
LastTransitionTime: metav1.Now(),
350353
},
351354
{
@@ -370,7 +373,7 @@ func TestReconcileInstanceReadyConditionWithQuota(t *testing.T) {
370373
Type: computev1alpha.InstanceReady,
371374
Status: metav1.ConditionFalse,
372375
Reason: computev1alpha.InstanceProgrammedReasonPendingQuota,
373-
Message: "Quota exceeded for project",
376+
Message: testMsgQuotaExceeded,
374377
},
375378
},
376379
{

internal/controller/instance_referenced_data_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ func TestFederated_QuotaAndSourceNotFound_SourceNotFoundWins(t *testing.T) {
751751
Type: computev1alpha.InstanceQuotaGranted,
752752
Status: metav1.ConditionFalse,
753753
Reason: computev1alpha.InstanceQuotaGrantedReasonQuotaExceeded,
754-
Message: "Quota exceeded for project",
754+
Message: testMsgQuotaExceeded,
755755
ObservedGeneration: 1,
756756
LastTransitionTime: metav1.Now(),
757757
},

internal/controller/workloaddeployment_controller_test.go

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@ import (
1717
)
1818

1919
const (
20-
// wdControllerTestName / wdControllerTestNS are shared fixtures for the
21-
// WorkloadDeployment controller unit tests.
20+
// wdControllerTestName / wdControllerTestNS / wdControllerTestUID are shared
21+
// fixtures for the WorkloadDeployment controller unit tests.
2222
wdControllerTestName = "test-wd"
2323
wdControllerTestNS = "default"
24+
wdControllerTestUID = "wd-uid-test"
25+
26+
// cityCode is the shared CityCode fixture for WorkloadDeployment tests.
27+
cityCode = "DFW"
2428

2529
// testMsgConfigMapNotFound is a representative terminal referenced-data
2630
// message used across the Available-rollup unit tests.
@@ -46,14 +50,14 @@ func TestReconcileInstanceGates_NilController_DoesNotPanic(t *testing.T) {
4650
// Build a deployment with a minimal template so ComputeHash produces a stable hash.
4751
deployment := &computev1alpha.WorkloadDeployment{
4852
ObjectMeta: metav1.ObjectMeta{
49-
Name: "test-wd",
50-
Namespace: "default",
51-
UID: "wd-uid-test",
53+
Name: wdControllerTestName,
54+
Namespace: wdControllerTestNS,
55+
UID: wdControllerTestUID,
5256
},
5357
Spec: computev1alpha.WorkloadDeploymentSpec{
54-
CityCode: "DFW",
58+
CityCode: cityCode,
5559
PlacementName: testDefaultPlacement,
56-
WorkloadRef: computev1alpha.WorkloadReference{Name: "test-workload"},
60+
WorkloadRef: computev1alpha.WorkloadReference{Name: rdTestWorkloadName},
5761
ScaleSettings: computev1alpha.HorizontalScaleSettings{
5862
MinReplicas: 2,
5963
},
@@ -74,9 +78,9 @@ func TestReconcileInstanceGates_NilController_DoesNotPanic(t *testing.T) {
7478
instanceNilController := computev1alpha.Instance{
7579
ObjectMeta: metav1.ObjectMeta{
7680
Name: "instance-nil-controller",
77-
Namespace: "default",
81+
Namespace: wdControllerTestNS,
7882
Labels: map[string]string{
79-
computev1alpha.WorkloadDeploymentUIDLabel: "wd-uid-test",
83+
computev1alpha.WorkloadDeploymentUIDLabel: wdControllerTestUID,
8084
},
8185
},
8286
Status: computev1alpha.InstanceStatus{
@@ -98,9 +102,9 @@ func TestReconcileInstanceGates_NilController_DoesNotPanic(t *testing.T) {
98102
instanceWithController := computev1alpha.Instance{
99103
ObjectMeta: metav1.ObjectMeta{
100104
Name: "instance-with-controller",
101-
Namespace: "default",
105+
Namespace: wdControllerTestNS,
102106
Labels: map[string]string{
103-
computev1alpha.WorkloadDeploymentUIDLabel: "wd-uid-test",
107+
computev1alpha.WorkloadDeploymentUIDLabel: wdControllerTestUID,
104108
},
105109
},
106110
Status: computev1alpha.InstanceStatus{
@@ -122,9 +126,9 @@ func TestReconcileInstanceGates_NilController_DoesNotPanic(t *testing.T) {
122126
instanceReady := computev1alpha.Instance{
123127
ObjectMeta: metav1.ObjectMeta{
124128
Name: "instance-ready",
125-
Namespace: "default",
129+
Namespace: wdControllerTestNS,
126130
Labels: map[string]string{
127-
computev1alpha.WorkloadDeploymentUIDLabel: "wd-uid-test",
131+
computev1alpha.WorkloadDeploymentUIDLabel: wdControllerTestUID,
128132
},
129133
},
130134
Status: computev1alpha.InstanceStatus{
@@ -188,9 +192,9 @@ func TestReconcileInstanceGates_NilSpecController_DoesNotPanic(t *testing.T) {
188192
t.Parallel()
189193

190194
deployment := &computev1alpha.WorkloadDeployment{
191-
ObjectMeta: metav1.ObjectMeta{Name: "test-wd", Namespace: "default", UID: "wd-uid-test"},
195+
ObjectMeta: metav1.ObjectMeta{Name: wdControllerTestName, Namespace: wdControllerTestNS, UID: wdControllerTestUID},
192196
Spec: computev1alpha.WorkloadDeploymentSpec{
193-
CityCode: "DFW",
197+
CityCode: cityCode,
194198
PlacementName: testDefaultPlacement,
195199
WorkloadRef: computev1alpha.WorkloadReference{Name: "test-workload"},
196200
ScaleSettings: computev1alpha.HorizontalScaleSettings{MinReplicas: 1},
@@ -201,7 +205,7 @@ func TestReconcileInstanceGates_NilSpecController_DoesNotPanic(t *testing.T) {
201205
// Spec.Controller intentionally nil — the network gate-clearing path runs
202206
// (networkReady=true) and must skip this instance instead of panicking.
203207
instanceNilSpecController := computev1alpha.Instance{
204-
ObjectMeta: metav1.ObjectMeta{Name: "instance-nil-spec-controller", Namespace: "default"},
208+
ObjectMeta: metav1.ObjectMeta{Name: "instance-nil-spec-controller", Namespace: wdControllerTestNS},
205209
}
206210

207211
cl := newProjectFakeClient()

internal/controller/workloaddeployment_location_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ func newNetworkingScheme() *runtime.Scheme {
3434
func TestReconcileNetworks_PersistsLocation_WhenLocationFound(t *testing.T) {
3535
t.Parallel()
3636

37-
const cityCode = "DFW"
3837
const locationName = "loc-dfw-1"
3938
const locationNamespace = "networking-system"
4039

@@ -54,7 +53,7 @@ func TestReconcileNetworks_PersistsLocation_WhenLocationFound(t *testing.T) {
5453
cl := fake.NewClientBuilder().WithScheme(s).WithObjects(location).Build()
5554

5655
deployment := &computev1alpha.WorkloadDeployment{
57-
ObjectMeta: metav1.ObjectMeta{Name: "test-wd", Namespace: "default"},
56+
ObjectMeta: metav1.ObjectMeta{Name: wdControllerTestName, Namespace: wdControllerTestNS},
5857
Spec: computev1alpha.WorkloadDeploymentSpec{
5958
CityCode: cityCode,
6059
// No NetworkInterfaces — the function returns false,locationRef,nil
@@ -98,9 +97,9 @@ func TestReconcileNetworks_ReturnsNilLocation_WhenNoLocationFound(t *testing.T)
9897
cl := fake.NewClientBuilder().WithScheme(s).WithObjects(otherLocation).Build()
9998

10099
deployment := &computev1alpha.WorkloadDeployment{
101-
ObjectMeta: metav1.ObjectMeta{Name: "test-wd", Namespace: "default"},
100+
ObjectMeta: metav1.ObjectMeta{Name: wdControllerTestName, Namespace: wdControllerTestNS},
102101
Spec: computev1alpha.WorkloadDeploymentSpec{
103-
CityCode: "DFW", // no matching Location
102+
CityCode: cityCode, // no matching Location
104103
},
105104
}
106105

0 commit comments

Comments
 (0)