Skip to content

Commit a2726c4

Browse files
committed
fix: resolve gofmt formatting and forcetypeassert lint issues
- Fix gofmt formatting in kafka_instance.go, kafka_instance_test.go, datasource_instance_test.go, resource_instance.go, and resource_instance_validation_test.go - Add type assertion checks in datasource_instance_test.go to fix forcetypeassert lint errors - Remove acc.config from git tracking and add to .gitignore
1 parent 9b7398e commit a2726c4

File tree

7 files changed

+76
-82
lines changed

7 files changed

+76
-82
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,6 @@ override.tf.json
3737
terraform.rc
3838

3939
dist/
40+
41+
# Local configuration files
42+
acc.config

acc.config

Lines changed: 0 additions & 20 deletions
This file was deleted.

internal/models/kafka_instance.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,17 @@ type NetworkModel struct {
6767
}
6868

6969
type ComputeSpecsModel struct {
70-
ReservedAku types.Int64 `tfsdk:"reserved_aku"`
71-
Networks []NetworkModel `tfsdk:"networks"`
72-
KubernetesNodeGroups []NodeGroupModel `tfsdk:"kubernetes_node_groups"`
73-
DeployType types.String `tfsdk:"deploy_type"`
74-
DnsZone types.String `tfsdk:"dns_zone"`
75-
KubernetesClusterID types.String `tfsdk:"kubernetes_cluster_id"`
76-
KubernetesNamespace types.String `tfsdk:"kubernetes_namespace"`
77-
KubernetesServiceAcct types.String `tfsdk:"kubernetes_service_account"`
78-
InstanceRole types.String `tfsdk:"instance_role"`
79-
DataBuckets types.List `tfsdk:"data_buckets"`
80-
FileSystemParam *FileSystemParamModel `tfsdk:"file_system_param"`
70+
ReservedAku types.Int64 `tfsdk:"reserved_aku"`
71+
Networks []NetworkModel `tfsdk:"networks"`
72+
KubernetesNodeGroups []NodeGroupModel `tfsdk:"kubernetes_node_groups"`
73+
DeployType types.String `tfsdk:"deploy_type"`
74+
DnsZone types.String `tfsdk:"dns_zone"`
75+
KubernetesClusterID types.String `tfsdk:"kubernetes_cluster_id"`
76+
KubernetesNamespace types.String `tfsdk:"kubernetes_namespace"`
77+
KubernetesServiceAcct types.String `tfsdk:"kubernetes_service_account"`
78+
InstanceRole types.String `tfsdk:"instance_role"`
79+
DataBuckets types.List `tfsdk:"data_buckets"`
80+
FileSystemParam *FileSystemParamModel `tfsdk:"file_system_param"`
8181
}
8282

8383
type NodeGroupModel struct {
@@ -322,17 +322,17 @@ func ExpandKafkaInstanceResource(ctx context.Context, instance KafkaInstanceReso
322322
ThroughputMiBpsPerFileSystem: int32(instance.ComputeSpecs.FileSystemParam.ThroughputMibpsPerFileSystem.ValueInt64()),
323323
FileSystemCount: int32(instance.ComputeSpecs.FileSystemParam.FileSystemCount.ValueInt64()),
324324
}
325-
325+
326326
// Security groups protection logic: only include if not empty
327-
if !instance.ComputeSpecs.FileSystemParam.SecurityGroups.IsNull() &&
328-
!instance.ComputeSpecs.FileSystemParam.SecurityGroups.IsUnknown() {
327+
if !instance.ComputeSpecs.FileSystemParam.SecurityGroups.IsNull() &&
328+
!instance.ComputeSpecs.FileSystemParam.SecurityGroups.IsUnknown() {
329329
var securityGroups []string
330330
diags := instance.ComputeSpecs.FileSystemParam.SecurityGroups.ElementsAs(ctx, &securityGroups, false)
331331
if !diags.HasError() && len(securityGroups) > 0 {
332332
fileSystemParam.SecurityGroups = securityGroups
333333
}
334334
}
335-
335+
336336
request.Spec.FileSystem = fileSystemParam
337337
}
338338

@@ -753,14 +753,14 @@ func FlattenKafkaInstanceModel(ctx context.Context, instance *client.InstanceVO,
753753
FileSystemCount: types.Int64Null(),
754754
SecurityGroups: types.ListNull(types.StringType),
755755
}
756-
756+
757757
// Copy previous values if they exist
758758
if previousFileSystemParam != nil {
759759
fileSystemParam.ThroughputMibpsPerFileSystem = previousFileSystemParam.ThroughputMibpsPerFileSystem
760760
fileSystemParam.FileSystemCount = previousFileSystemParam.FileSystemCount
761761
fileSystemParam.SecurityGroups = previousFileSystemParam.SecurityGroups
762762
}
763-
763+
764764
// Update with API response values
765765
if instance.Spec.FileSystem.ThroughputMiBpsPerFileSystem != nil {
766766
fileSystemParam.ThroughputMibpsPerFileSystem = types.Int64Value(int64(*instance.Spec.FileSystem.ThroughputMiBpsPerFileSystem))
@@ -774,7 +774,7 @@ func FlattenKafkaInstanceModel(ctx context.Context, instance *client.InstanceVO,
774774
fileSystemParam.SecurityGroups = securityGroupsList
775775
}
776776
}
777-
777+
778778
resource.ComputeSpecs.FileSystemParam = fileSystemParam
779779
} else if previousFileSystemParam != nil {
780780
// Preserve previous file system parameters if API doesn't return them

internal/models/kafka_instance_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -580,37 +580,37 @@ func TestFlattenKafkaInstanceModel_FSWAL(t *testing.T) {
580580
t.Run(tt.name, func(t *testing.T) {
581581
resource := &KafkaInstanceResourceModel{}
582582
diags := FlattenKafkaInstanceModel(context.Background(), tt.input, resource)
583-
583+
584584
assert.False(t, diags.HasError(), "FlattenKafkaInstanceModel should not return errors")
585-
585+
586586
// Check basic fields
587587
assert.Equal(t, tt.expected.InstanceID, resource.InstanceID)
588588
assert.Equal(t, tt.expected.Name, resource.Name)
589589
assert.Equal(t, tt.expected.Description, resource.Description)
590590
assert.Equal(t, tt.expected.Version, resource.Version)
591591
assert.Equal(t, tt.expected.InstanceStatus, resource.InstanceStatus)
592-
592+
593593
// Check compute specs
594594
if tt.expected.ComputeSpecs == nil {
595595
assert.Nil(t, resource.ComputeSpecs)
596596
} else {
597597
assert.NotNil(t, resource.ComputeSpecs)
598598
assert.Equal(t, tt.expected.ComputeSpecs.ReservedAku, resource.ComputeSpecs.ReservedAku)
599-
599+
600600
// Check file system parameters
601601
if tt.expected.ComputeSpecs.FileSystemParam == nil {
602602
assert.Nil(t, resource.ComputeSpecs.FileSystemParam)
603603
} else {
604604
assert.NotNil(t, resource.ComputeSpecs.FileSystemParam)
605-
assert.Equal(t, tt.expected.ComputeSpecs.FileSystemParam.ThroughputMibpsPerFileSystem,
605+
assert.Equal(t, tt.expected.ComputeSpecs.FileSystemParam.ThroughputMibpsPerFileSystem,
606606
resource.ComputeSpecs.FileSystemParam.ThroughputMibpsPerFileSystem)
607-
assert.Equal(t, tt.expected.ComputeSpecs.FileSystemParam.FileSystemCount,
607+
assert.Equal(t, tt.expected.ComputeSpecs.FileSystemParam.FileSystemCount,
608608
resource.ComputeSpecs.FileSystemParam.FileSystemCount)
609-
assert.Equal(t, tt.expected.ComputeSpecs.FileSystemParam.SecurityGroups,
609+
assert.Equal(t, tt.expected.ComputeSpecs.FileSystemParam.SecurityGroups,
610610
resource.ComputeSpecs.FileSystemParam.SecurityGroups)
611611
}
612612
}
613-
613+
614614
// Check features
615615
if tt.expected.Features == nil {
616616
assert.Nil(t, resource.Features)

internal/provider/datasource_instance_test.go

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,43 +13,55 @@ import (
1313

1414
func TestKafkaInstanceDataSourceSchema(t *testing.T) {
1515
ds := NewKafkaInstanceDataSource()
16-
16+
1717
req := datasource.SchemaRequest{}
1818
resp := &datasource.SchemaResponse{}
19-
19+
2020
ds.Schema(context.Background(), req, resp)
21-
21+
2222
assert.False(t, resp.Diagnostics.HasError(), "Schema should not have errors")
23-
23+
2424
// Verify that file_system_param is present in compute_specs
2525
computeSpecs, exists := resp.Schema.Attributes["compute_specs"]
2626
assert.True(t, exists, "compute_specs should exist in schema")
27-
28-
computeSpecsNested := computeSpecs.(schema.SingleNestedAttribute)
27+
28+
computeSpecsNested, ok := computeSpecs.(schema.SingleNestedAttribute)
29+
if !ok {
30+
t.Fatalf("compute_specs has unexpected type %T", computeSpecs)
31+
}
2932
fileSystemParam, exists := computeSpecsNested.Attributes["file_system_param"]
3033
assert.True(t, exists, "file_system_param should exist in compute_specs")
31-
34+
3235
// Verify file_system_param attributes
33-
fileSystemParamNested := fileSystemParam.(schema.SingleNestedAttribute)
34-
36+
fileSystemParamNested, ok := fileSystemParam.(schema.SingleNestedAttribute)
37+
if !ok {
38+
t.Fatalf("file_system_param has unexpected type %T", fileSystemParam)
39+
}
40+
3541
_, exists = fileSystemParamNested.Attributes["throughput_mibps_per_file_system"]
3642
assert.True(t, exists, "throughput_mibps_per_file_system should exist")
37-
43+
3844
_, exists = fileSystemParamNested.Attributes["file_system_count"]
3945
assert.True(t, exists, "file_system_count should exist")
40-
46+
4147
_, exists = fileSystemParamNested.Attributes["security_groups"]
4248
assert.True(t, exists, "security_groups should exist")
43-
49+
4450
// Verify WAL mode description includes FSWAL
4551
features, exists := resp.Schema.Attributes["features"]
4652
assert.True(t, exists, "features should exist in schema")
47-
48-
featuresNested := features.(schema.SingleNestedAttribute)
53+
54+
featuresNested, ok := features.(schema.SingleNestedAttribute)
55+
if !ok {
56+
t.Fatalf("features has unexpected type %T", features)
57+
}
4958
walMode, exists := featuresNested.Attributes["wal_mode"]
5059
assert.True(t, exists, "wal_mode should exist in features")
51-
52-
walModeAttr := walMode.(schema.StringAttribute)
60+
61+
walModeAttr, ok := walMode.(schema.StringAttribute)
62+
if !ok {
63+
t.Fatalf("wal_mode has unexpected type %T", walMode)
64+
}
5365
assert.Contains(t, walModeAttr.Description, "FSWAL", "wal_mode description should mention FSWAL")
5466
}
5567

internal/provider/resource_instance.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -601,13 +601,13 @@ func validateKafkaInstanceConfiguration(ctx context.Context, plan *models.KafkaI
601601
if state != nil && state.Features != nil {
602602
stateWalMode = &state.Features.WalMode
603603
}
604-
604+
605605
hasFileSystemParam := plan.ComputeSpecs.FileSystemParam != nil
606-
606+
607607
if plan.Features != nil {
608608
planWalMode := plan.Features.WalMode
609609
walMode, walModeSet := resolvePlannedStringValue(planWalMode, stateWalMode)
610-
610+
611611
if walModeSet && strings.EqualFold(walMode, "FSWAL") {
612612
// When wal_mode is FSWAL, file_system_param must be provided
613613
if !hasFileSystemParam {
@@ -617,15 +617,15 @@ func validateKafkaInstanceConfiguration(ctx context.Context, plan *models.KafkaI
617617
)
618618
} else {
619619
// Validate required fields in file_system_param
620-
if plan.ComputeSpecs.FileSystemParam.ThroughputMibpsPerFileSystem.IsNull() ||
621-
plan.ComputeSpecs.FileSystemParam.ThroughputMibpsPerFileSystem.IsUnknown() {
620+
if plan.ComputeSpecs.FileSystemParam.ThroughputMibpsPerFileSystem.IsNull() ||
621+
plan.ComputeSpecs.FileSystemParam.ThroughputMibpsPerFileSystem.IsUnknown() {
622622
diagnostics.AddError(
623623
"Invalid Configuration",
624624
"throughput_mibps_per_file_system is required when wal_mode is FSWAL",
625625
)
626626
}
627-
if plan.ComputeSpecs.FileSystemParam.FileSystemCount.IsNull() ||
628-
plan.ComputeSpecs.FileSystemParam.FileSystemCount.IsUnknown() {
627+
if plan.ComputeSpecs.FileSystemParam.FileSystemCount.IsNull() ||
628+
plan.ComputeSpecs.FileSystemParam.FileSystemCount.IsUnknown() {
629629
diagnostics.AddError(
630630
"Invalid Configuration",
631631
"file_system_count is required when wal_mode is FSWAL",
@@ -935,26 +935,26 @@ func (r *KafkaInstanceResource) Update(ctx context.Context, req resource.UpdateR
935935
if state.ComputeSpecs != nil {
936936
stateFileSystemParam = state.ComputeSpecs.FileSystemParam
937937
}
938-
938+
939939
planFileSystemParam := plan.ComputeSpecs.FileSystemParam
940940
if fileSystemParamChanged(planFileSystemParam, stateFileSystemParam) {
941941
if planFileSystemParam != nil {
942942
fileSystemParam := &client.FileSystemParam{
943943
ThroughputMiBpsPerFileSystem: int32(planFileSystemParam.ThroughputMibpsPerFileSystem.ValueInt64()),
944944
FileSystemCount: int32(planFileSystemParam.FileSystemCount.ValueInt64()),
945945
}
946-
946+
947947
// Security groups protection logic: only include if not empty and not changing from existing value
948948
// This prevents overwriting auto-generated security groups
949-
if !planFileSystemParam.SecurityGroups.IsNull() &&
950-
!planFileSystemParam.SecurityGroups.IsUnknown() {
949+
if !planFileSystemParam.SecurityGroups.IsNull() &&
950+
!planFileSystemParam.SecurityGroups.IsUnknown() {
951951
var securityGroups []string
952952
diags := planFileSystemParam.SecurityGroups.ElementsAs(ctx, &securityGroups, false)
953953
if !diags.HasError() && len(securityGroups) > 0 {
954954
fileSystemParam.SecurityGroups = securityGroups
955955
}
956956
}
957-
957+
958958
spec := ensureSpec()
959959
spec.FileSystem = fileSystemParam
960960
hasUpdate = true
@@ -1280,23 +1280,23 @@ func fileSystemParamChanged(plan, state *models.FileSystemParamModel) bool {
12801280
if state == nil {
12811281
return plan != nil
12821282
}
1283-
1283+
12841284
// Compare throughput
12851285
if !int64AttrEqual(plan.ThroughputMibpsPerFileSystem, state.ThroughputMibpsPerFileSystem) {
12861286
return true
12871287
}
1288-
1288+
12891289
// Compare file system count
12901290
if !int64AttrEqual(plan.FileSystemCount, state.FileSystemCount) {
12911291
return true
12921292
}
1293-
1293+
12941294
// Compare security groups - note: security groups changes should trigger replacement, not update
12951295
// But we still need to detect the change for validation purposes
12961296
if !listAttrEqual(plan.SecurityGroups, state.SecurityGroups) {
12971297
return true
12981298
}
1299-
1299+
13001300
return false
13011301
}
13021302

internal/provider/resource_instance_validation_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,6 @@ func TestSecurityGroupsValidator(t *testing.T) {
657657
}
658658
}
659659

660-
661660
// TestValidateKafkaInstanceConfiguration_FSWALWithEmptySecurityGroups tests that
662661
// FSWAL configuration with empty security_groups list is handled correctly.
663662
// Empty security_groups should be valid (backend will auto-generate).
@@ -687,11 +686,11 @@ func TestValidateKafkaInstanceConfiguration_FSWALWithEmptySecurityGroups(t *test
687686
// Note: The schema validator (listvalidator.SizeAtLeast(1)) will reject empty lists,
688687
// but validateKafkaInstanceConfiguration itself should not add additional errors.
689688
// This test verifies the custom validation logic doesn't break with empty security_groups.
690-
689+
691690
// Check if there's an error specifically about file_system_param being ignored
692691
for _, d := range diags {
693-
if strings.Contains(d.Detail(), "file_system_param") &&
694-
!strings.Contains(d.Detail(), "security_groups") {
692+
if strings.Contains(d.Detail(), "file_system_param") &&
693+
!strings.Contains(d.Detail(), "security_groups") {
695694
t.Fatalf("unexpected file_system_param error with empty security_groups: %v", d)
696695
}
697696
}

0 commit comments

Comments
 (0)