Skip to content

Commit a67b32c

Browse files
scotwellsclaude
andcommitted
fix(lint): extract goconst constants and gofmt the bundled controller tests
Make the cherry-picked instanceType-sizing and blocking-reason tests lint-clean: hoist the repeated "datumcloud/d1-standard-2", "app", and "test/image:latest" literals into named constants (goconst) and apply gofmt. No behavior change. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 184ae3b commit a67b32c

2 files changed

Lines changed: 26 additions & 16 deletions

File tree

internal/controller/instance_controller.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ const (
9696
reasonNetworkFailedToCreate = "NetworkFailedToCreate"
9797
)
9898

99+
// instanceTypeD1Standard2 is the platform instance type name for the
100+
// 1 vCPU / 2 GiB size used as the catalog baseline for quota accounting.
101+
const instanceTypeD1Standard2 = "datumcloud/d1-standard-2"
102+
99103
// instanceTypeResources holds the vCPU and memory for a named instance type.
100104
type instanceTypeResources struct {
101105
// CPUMillicores is the number of CPU millicores (1000 = 1 vCPU).
@@ -114,7 +118,7 @@ type instanceTypeResources struct {
114118
// provisioning; that mapping does not define the quota size here.) When new
115119
// instance types are added, add them here with their vCPU/memory values.
116120
var instanceTypeCatalog = map[string]instanceTypeResources{
117-
"datumcloud/d1-standard-2": {
121+
instanceTypeD1Standard2: {
118122
CPUMillicores: 1000, // 1 vCPU
119123
MemoryMiB: 2048, // 2 GiB
120124
},

internal/controller/instance_controller_test.go

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,6 +1625,12 @@ func TestQuotaPendingRequeueAfter(t *testing.T) {
16251625
}
16261626
}
16271627

1628+
// Shared literals for the instance-sizing / blocking-reason tests below
1629+
// (extracted to satisfy goconst).
1630+
const (
1631+
testContainerName = "app"
1632+
testContainerImage = "test/image:latest"
1633+
)
16281634

16291635
// TestReconcileInstanceReadyCondition_ProviderSubConditionSurfacing verifies
16301636
// that provider-set sub-condition reasons (e.g. ImageUnavailable written by the
@@ -1950,11 +1956,11 @@ func TestResolveInstanceResources(t *testing.T) {
19501956
}
19511957

19521958
tests := []struct {
1953-
name string
1954-
instance *computev1alpha.Instance
1955-
wantCPU int64
1956-
wantMem int64
1957-
wantResolved bool
1959+
name string
1960+
instance *computev1alpha.Instance
1961+
wantCPU int64
1962+
wantMem int64
1963+
wantResolved bool
19581964
}{
19591965
{
19601966
// Common production case: instanceType only, no explicit limits.
@@ -1965,7 +1971,7 @@ func TestResolveInstanceResources(t *testing.T) {
19651971
Spec: computev1alpha.InstanceSpec{
19661972
Runtime: computev1alpha.InstanceRuntimeSpec{
19671973
Resources: computev1alpha.InstanceRuntimeResources{
1968-
InstanceType: "datumcloud/d1-standard-2",
1974+
InstanceType: instanceTypeD1Standard2,
19691975
},
19701976
},
19711977
},
@@ -1982,13 +1988,13 @@ func TestResolveInstanceResources(t *testing.T) {
19821988
Spec: computev1alpha.InstanceSpec{
19831989
Runtime: computev1alpha.InstanceRuntimeSpec{
19841990
Resources: computev1alpha.InstanceRuntimeResources{
1985-
InstanceType: "datumcloud/d1-standard-2",
1991+
InstanceType: instanceTypeD1Standard2,
19861992
},
19871993
Sandbox: &computev1alpha.SandboxRuntime{
19881994
Containers: []computev1alpha.SandboxContainer{
19891995
{
1990-
Name: "app",
1991-
Image: "test/image:latest",
1996+
Name: testContainerName,
1997+
Image: testContainerImage,
19921998
Resources: makeContainerResources(cpu500m, mem256Mi),
19931999
},
19942000
{
@@ -2015,8 +2021,8 @@ func TestResolveInstanceResources(t *testing.T) {
20152021
Sandbox: &computev1alpha.SandboxRuntime{
20162022
Containers: []computev1alpha.SandboxContainer{
20172023
{
2018-
Name: "app",
2019-
Image: "test/image:latest",
2024+
Name: testContainerName,
2025+
Image: testContainerImage,
20202026
Resources: makeContainerResources(cpu1, mem512Mi),
20212027
},
20222028
},
@@ -2087,13 +2093,13 @@ func TestResolveInstanceResources(t *testing.T) {
20872093
Spec: computev1alpha.InstanceSpec{
20882094
Runtime: computev1alpha.InstanceRuntimeSpec{
20892095
Resources: computev1alpha.InstanceRuntimeResources{
2090-
InstanceType: "datumcloud/d1-standard-2",
2096+
InstanceType: instanceTypeD1Standard2,
20912097
},
20922098
Sandbox: &computev1alpha.SandboxRuntime{
20932099
Containers: []computev1alpha.SandboxContainer{
20942100
{
2095-
Name: "app",
2096-
Image: "test/image:latest",
2101+
Name: testContainerName,
2102+
Image: testContainerImage,
20972103
// No Resources.Limits set — common for UKC workloads.
20982104
},
20992105
},
@@ -2158,7 +2164,7 @@ func TestReconcileQuotaClaim_RequestsIncludeVCPUsAndMemory(t *testing.T) {
21582164
Runtime: computev1alpha.InstanceRuntimeSpec{
21592165
Resources: computev1alpha.InstanceRuntimeResources{
21602166
// No Requests, no container Limits — catalog must supply the values.
2161-
InstanceType: "datumcloud/d1-standard-2",
2167+
InstanceType: instanceTypeD1Standard2,
21622168
},
21632169
},
21642170
NetworkInterfaces: []computev1alpha.InstanceNetworkInterface{},

0 commit comments

Comments
 (0)