Skip to content

Commit aeed8b3

Browse files
committed
Fix delta code generation for nested structs shapes
When generating and compiling the lambda controller delta code, i noticed few compilation errors, moslty about type mismatches between values and function parameters. This was due to a misplacement of the arugments passed to `code.compareSlice` and `code.compareMap` functions when they are called from `code.compareStruct`. This commit corrects the order/placement of arguments passed to the `compareSlice` and `compareMap` functions
1 parent e7326c5 commit aeed8b3

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

pkg/generate/code/compare.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,9 +543,9 @@ func compareStruct(
543543
compareConfig,
544544
memberShape,
545545
deltaVarName,
546-
memberFieldPath,
547546
firstResAdaptedVarName,
548547
secondResAdaptedVarName,
548+
memberFieldPath,
549549
indentLevel,
550550
)
551551
case "list":
@@ -555,9 +555,9 @@ func compareStruct(
555555
compareConfig,
556556
memberShape,
557557
deltaVarName,
558-
memberFieldPath,
559558
firstResAdaptedVarName,
560559
secondResAdaptedVarName,
560+
memberFieldPath,
561561
indentLevel,
562562
)
563563
case "map":
@@ -567,9 +567,9 @@ func compareStruct(
567567
compareConfig,
568568
memberShape,
569569
deltaVarName,
570-
memberFieldPath,
571570
firstResAdaptedVarName,
572571
secondResAdaptedVarName,
572+
memberFieldPath,
573573
indentLevel,
574574
)
575575
default:

pkg/generate/code/compare_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,48 @@ func TestCompareResource_S3_Bucket(t *testing.T) {
103103
),
104104
)
105105
}
106+
107+
func TestCompareResource_Lambda_CodeSigningConfig(t *testing.T) {
108+
assert := assert.New(t)
109+
require := require.New(t)
110+
111+
g := testutil.NewGeneratorForService(t, "lambda")
112+
113+
crd := testutil.GetCRDByName(t, g, "CodeSigningConfig")
114+
require.NotNil(crd)
115+
116+
expected := `
117+
if ackcompare.HasNilDifference(a.ko.Spec.AllowedPublishers, b.ko.Spec.AllowedPublishers) {
118+
delta.Add("Spec.AllowedPublishers", a.ko.Spec.AllowedPublishers, b.ko.Spec.AllowedPublishers)
119+
} else if a.ko.Spec.AllowedPublishers != nil && b.ko.Spec.AllowedPublishers != nil {
120+
121+
if !ackcompare.SliceStringPEqual(a.ko.Spec.AllowedPublishers.SigningProfileVersionARNs, b.ko.Spec.AllowedPublishers.SigningProfileVersionARNs) {
122+
delta.Add("Spec.AllowedPublishers.SigningProfileVersionARNs", a.ko.Spec.AllowedPublishers.SigningProfileVersionARNs, b.ko.Spec.AllowedPublishers.SigningProfileVersionARNs)
123+
}
124+
}
125+
if ackcompare.HasNilDifference(a.ko.Spec.CodeSigningPolicies, b.ko.Spec.CodeSigningPolicies) {
126+
delta.Add("Spec.CodeSigningPolicies", a.ko.Spec.CodeSigningPolicies, b.ko.Spec.CodeSigningPolicies)
127+
} else if a.ko.Spec.CodeSigningPolicies != nil && b.ko.Spec.CodeSigningPolicies != nil {
128+
if ackcompare.HasNilDifference(a.ko.Spec.CodeSigningPolicies.UntrustedArtifactOnDeployment, b.ko.Spec.CodeSigningPolicies.UntrustedArtifactOnDeployment) {
129+
delta.Add("Spec.CodeSigningPolicies.UntrustedArtifactOnDeployment", a.ko.Spec.CodeSigningPolicies.UntrustedArtifactOnDeployment, b.ko.Spec.CodeSigningPolicies.UntrustedArtifactOnDeployment)
130+
} else if a.ko.Spec.CodeSigningPolicies.UntrustedArtifactOnDeployment != nil && b.ko.Spec.CodeSigningPolicies.UntrustedArtifactOnDeployment != nil {
131+
if *a.ko.Spec.CodeSigningPolicies.UntrustedArtifactOnDeployment != *b.ko.Spec.CodeSigningPolicies.UntrustedArtifactOnDeployment {
132+
delta.Add("Spec.CodeSigningPolicies.UntrustedArtifactOnDeployment", a.ko.Spec.CodeSigningPolicies.UntrustedArtifactOnDeployment, b.ko.Spec.CodeSigningPolicies.UntrustedArtifactOnDeployment)
133+
}
134+
}
135+
}
136+
if ackcompare.HasNilDifference(a.ko.Spec.Description, b.ko.Spec.Description) {
137+
delta.Add("Spec.Description", a.ko.Spec.Description, b.ko.Spec.Description)
138+
} else if a.ko.Spec.Description != nil && b.ko.Spec.Description != nil {
139+
if *a.ko.Spec.Description != *b.ko.Spec.Description {
140+
delta.Add("Spec.Description", a.ko.Spec.Description, b.ko.Spec.Description)
141+
}
142+
}
143+
`
144+
assert.Equal(
145+
expected,
146+
code.CompareResource(
147+
crd.Config(), crd, "delta", "a.ko", "b.ko", 1,
148+
),
149+
)
150+
}

0 commit comments

Comments
 (0)