diff --git a/pkg/generate/code/synced.go b/pkg/generate/code/synced.go index dd40abfd..c4ebcf31 100644 --- a/pkg/generate/code/synced.go +++ b/pkg/generate/code/synced.go @@ -121,7 +121,12 @@ func scalarFieldEqual( ) string { out := "" fieldPath := fmt.Sprintf("%s.%s", resVarName, *condCfg.Path) - + // if r.ko.Status.Status == nil + out += fmt.Sprintf("\tif %s == nil {\n", fieldPath) + // return false, nil + out += "\t\treturn false, nil\n" + // } + out += "\t}\n" valuesSlice := "" switch goType { case "string": @@ -174,9 +179,8 @@ func fieldPathSafeEqual( subFieldPath := rootPath for index, shape := range shapes { if index == len(shapes)-1 { - // Some aws-sdk-go scalar shapes don't contain the real name of a shape - // In this case we use the full path given in condition.Path - subFieldPath = fmt.Sprintf("%s.%s", resVarName, *condCfg.Path) + // We would check for nil in scalarFieldEqual method so no need to loop anymore + break } else { subFieldPath += "." + shape.Shape.ShapeName } diff --git a/pkg/generate/code/synced_test.go b/pkg/generate/code/synced_test.go index f8a0b782..853658f0 100644 --- a/pkg/generate/code/synced_test.go +++ b/pkg/generate/code/synced_test.go @@ -33,14 +33,23 @@ func TestSyncedLambdaFunction(t *testing.T) { require.NotNil(crd) expectedSyncedConditions := ` + if r.ko.Status.State == nil { + return false, nil + } stateCandidates := []string{"AVAILABLE", "ACTIVE"} if !ackutil.InStrings(*r.ko.Status.State, stateCandidates) { return false, nil } + if r.ko.Status.LastUpdateStatus == nil { + return false, nil + } lastUpdateStatusCandidates := []string{"AVAILABLE", "ACTIVE"} if !ackutil.InStrings(*r.ko.Status.LastUpdateStatus, lastUpdateStatusCandidates) { return false, nil } + if r.ko.Status.CodeSize == nil { + return false, nil + } codeSizeCandidates := []int{1, 2} if !ackutil.InStrings(*r.ko.Status.CodeSize, codeSizeCandidates) { return false, nil @@ -64,6 +73,9 @@ func TestSyncedDynamodbTable(t *testing.T) { require.NotNil(crd) expectedSyncedConditions := ` + if r.ko.Status.TableStatus == nil { + return false, nil + } tableStatusCandidates := []string{"AVAILABLE", "ACTIVE"} if !ackutil.InStrings(*r.ko.Status.TableStatus, tableStatusCandidates) { return false, nil @@ -78,6 +90,9 @@ func TestSyncedDynamodbTable(t *testing.T) { if !ackutil.InStrings(*r.ko.Spec.ProvisionedThroughput.ReadCapacityUnits, provisionedThroughputCandidates) { return false, nil } + if r.ko.Status.ItemCount == nil { + return false, nil + } itemCountCandidates := []int{0} if !ackutil.InStrings(*r.ko.Status.ItemCount, itemCountCandidates) { return false, nil