Skip to content

Commit 88fc33d

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 d48f490 commit 88fc33d

3 files changed

Lines changed: 11 additions & 9 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_location_test.go

Lines changed: 5 additions & 6 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

@@ -45,7 +44,7 @@ func TestReconcileNetworks_PersistsLocation_WhenLocationFound(t *testing.T) {
4544
},
4645
Spec: networkingv1alpha.LocationSpec{
4746
Topology: map[string]string{
48-
"topology.datum.net/city-code": cityCode,
47+
"topology.datum.net/city-code": wdControllerTestCityCode,
4948
},
5049
},
5150
}
@@ -54,9 +53,9 @@ 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{
59-
CityCode: cityCode,
58+
CityCode: wdControllerTestCityCode,
6059
// No NetworkInterfaces — the function returns false,locationRef,nil
6160
// after the location is found but before bindings are checked.
6261
},
@@ -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: wdControllerTestCityCode, // no matching Location
104103
},
105104
}
106105

0 commit comments

Comments
 (0)