Skip to content

Commit f239f5e

Browse files
authored
Correct type mismatch errors in SetResourceIdentifiers generated code (#115)
Related to #105 and aws-controllers-k8s/runtime#13 Description of changes: - replace nil pointer checks with string zero value checks - replace `string` value assignment with `string` ptr assignments By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 8f6723d commit f239f5e

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

pkg/generate/code/set_resource.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ func SetResourceIdentifiers(
844844

845845
indent := strings.Repeat("\t", indentLevel)
846846

847-
primaryKeyOut += fmt.Sprintf("%sif %s.NameOrID == nil {\n", indent, sourceVarName)
847+
primaryKeyOut += fmt.Sprintf("%sif %s.NameOrID == \"\" {\n", indent, sourceVarName)
848848
primaryKeyOut += fmt.Sprintf("%s\treturn ackerrors.MissingNameIdentifier\n", indent)
849849
primaryKeyOut += fmt.Sprintf("%s}\n", indent)
850850

@@ -940,7 +940,7 @@ func SetResourceIdentifiers(
940940

941941
if isPrimaryIdentifier {
942942
// r.ko.Status.BrokerID = identifier.NameOrID
943-
primaryKeyOut += fmt.Sprintf("%s%s%s.%s = %s.NameOrID\n", indent, targetVarName, memberPath, cleanMemberName, sourceVarName)
943+
primaryKeyOut += fmt.Sprintf("%s%s%s.%s = &%s.NameOrID\n", indent, targetVarName, memberPath, cleanMemberName, sourceVarName)
944944
} else {
945945
// f0, f0ok := identifier.AdditionalKeys["scalableDimension"]
946946
// if f0ok {
@@ -954,7 +954,7 @@ func SetResourceIdentifiers(
954954
// throwing an error accessible to the user
955955
additionalKeyOut += fmt.Sprintf("%s%s, %sok := %s\n", indent, fieldIndexName, fieldIndexName, sourceAdaptedVarName)
956956
additionalKeyOut += fmt.Sprintf("%sif %sok {\n", indent, fieldIndexName)
957-
additionalKeyOut += fmt.Sprintf("%s\t%s%s.%s = %s\n", indent, targetVarName, memberPath, cleanMemberName, fieldIndexName)
957+
additionalKeyOut += fmt.Sprintf("%s\t%s%s.%s = &%s\n", indent, targetVarName, memberPath, cleanMemberName, fieldIndexName)
958958
additionalKeyOut += fmt.Sprintf("%s}\n", indent)
959959

960960
additionalKeyCount++

pkg/generate/code/set_resource_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2656,10 +2656,10 @@ func TestSetResource_MQ_Broker_SetResourceIdentifiers(t *testing.T) {
26562656
require.NotNil(crd)
26572657

26582658
expected := `
2659-
if identifier.NameOrID == nil {
2659+
if identifier.NameOrID == "" {
26602660
return ackerrors.MissingNameIdentifier
26612661
}
2662-
r.ko.Status.BrokerID = identifier.NameOrID
2662+
r.ko.Status.BrokerID = &identifier.NameOrID
26632663
26642664
`
26652665
assert.Equal(
@@ -2678,10 +2678,10 @@ func TestSetResource_RDS_DBInstances_SetResourceIdentifiers(t *testing.T) {
26782678
require.NotNil(crd)
26792679

26802680
expected := `
2681-
if identifier.NameOrID == nil {
2681+
if identifier.NameOrID == "" {
26822682
return ackerrors.MissingNameIdentifier
26832683
}
2684-
r.ko.Spec.DBInstanceIdentifier = identifier.NameOrID
2684+
r.ko.Spec.DBInstanceIdentifier = &identifier.NameOrID
26852685
26862686
`
26872687
assert.Equal(
@@ -2700,14 +2700,14 @@ func TestSetResource_APIGWV2_ApiMapping_SetResourceIdentifiers(t *testing.T) {
27002700
require.NotNil(crd)
27012701

27022702
expected := `
2703-
if identifier.NameOrID == nil {
2703+
if identifier.NameOrID == "" {
27042704
return ackerrors.MissingNameIdentifier
27052705
}
2706-
r.ko.Status.APIMappingID = identifier.NameOrID
2706+
r.ko.Status.APIMappingID = &identifier.NameOrID
27072707
27082708
f0, f0ok := identifier.AdditionalKeys["domainName"]
27092709
if f0ok {
2710-
r.ko.Spec.DomainName = f0
2710+
r.ko.Spec.DomainName = &f0
27112711
}
27122712
`
27132713
assert.Equal(

0 commit comments

Comments
 (0)