@@ -814,3 +814,69 @@ func TestCompareResource_S3Files_AccessPoint(t *testing.T) {
814814 require .NoError (err )
815815 assert .Equal (expected , got )
816816}
817+
818+ func TestCompareResource_SNS_Topic_NilEqualsZeroValue (t * testing.T ) {
819+ assert := assert .New (t )
820+ require := require .New (t )
821+
822+ g := testutil .NewModelForServiceWithOptions (t , "sns" , & testutil.TestingModelOptions {
823+ GeneratorConfigFile : "generator-nil-equals-zero-value.yaml" ,
824+ })
825+
826+ crd := testutil .GetCRDByName (t , g , "Topic" )
827+ require .NotNil (crd )
828+
829+ // DisplayName has compare.nil_equals_zero_value: true, so the generated
830+ // code should only report a nil difference if the non-nil side (latest
831+ // from AWS) is not an empty string. This prevents permanent drift when
832+ // AWS returns "" for an unset optional field while the desired state has nil.
833+ expected := `
834+ if ackcompare.HasNilDifference(a.ko.Spec.DeliveryPolicy, b.ko.Spec.DeliveryPolicy) {
835+ delta.Add("Spec.DeliveryPolicy", a.ko.Spec.DeliveryPolicy, b.ko.Spec.DeliveryPolicy)
836+ } else if a.ko.Spec.DeliveryPolicy != nil && b.ko.Spec.DeliveryPolicy != nil {
837+ if *a.ko.Spec.DeliveryPolicy != *b.ko.Spec.DeliveryPolicy {
838+ delta.Add("Spec.DeliveryPolicy", a.ko.Spec.DeliveryPolicy, b.ko.Spec.DeliveryPolicy)
839+ }
840+ }
841+ if ackcompare.HasNilDifference(a.ko.Spec.DisplayName, b.ko.Spec.DisplayName) {
842+ if !ackcompare.IsNilEqualsZero(a.ko.Spec.DisplayName, b.ko.Spec.DisplayName) {
843+ delta.Add("Spec.DisplayName", a.ko.Spec.DisplayName, b.ko.Spec.DisplayName)
844+ }
845+ } else if a.ko.Spec.DisplayName != nil && b.ko.Spec.DisplayName != nil {
846+ if *a.ko.Spec.DisplayName != *b.ko.Spec.DisplayName {
847+ delta.Add("Spec.DisplayName", a.ko.Spec.DisplayName, b.ko.Spec.DisplayName)
848+ }
849+ }
850+ if ackcompare.HasNilDifference(a.ko.Spec.KMSMasterKeyID, b.ko.Spec.KMSMasterKeyID) {
851+ delta.Add("Spec.KMSMasterKeyID", a.ko.Spec.KMSMasterKeyID, b.ko.Spec.KMSMasterKeyID)
852+ } else if a.ko.Spec.KMSMasterKeyID != nil && b.ko.Spec.KMSMasterKeyID != nil {
853+ if *a.ko.Spec.KMSMasterKeyID != *b.ko.Spec.KMSMasterKeyID {
854+ delta.Add("Spec.KMSMasterKeyID", a.ko.Spec.KMSMasterKeyID, b.ko.Spec.KMSMasterKeyID)
855+ }
856+ }
857+ if ackcompare.HasNilDifference(a.ko.Spec.Name, b.ko.Spec.Name) {
858+ delta.Add("Spec.Name", a.ko.Spec.Name, b.ko.Spec.Name)
859+ } else if a.ko.Spec.Name != nil && b.ko.Spec.Name != nil {
860+ if *a.ko.Spec.Name != *b.ko.Spec.Name {
861+ delta.Add("Spec.Name", a.ko.Spec.Name, b.ko.Spec.Name)
862+ }
863+ }
864+ if ackcompare.HasNilDifference(a.ko.Spec.Policy, b.ko.Spec.Policy) {
865+ delta.Add("Spec.Policy", a.ko.Spec.Policy, b.ko.Spec.Policy)
866+ } else if a.ko.Spec.Policy != nil && b.ko.Spec.Policy != nil {
867+ if *a.ko.Spec.Policy != *b.ko.Spec.Policy {
868+ delta.Add("Spec.Policy", a.ko.Spec.Policy, b.ko.Spec.Policy)
869+ }
870+ }
871+ desiredACKTags, _ := convertToOrderedACKTags(a.ko.Spec.Tags)
872+ latestACKTags, _ := convertToOrderedACKTags(b.ko.Spec.Tags)
873+ if !ackcompare.MapStringStringEqual(desiredACKTags, latestACKTags) {
874+ delta.Add("Spec.Tags", a.ko.Spec.Tags, b.ko.Spec.Tags)
875+ }
876+ `
877+ got , err := code .CompareResource (
878+ crd .Config (), crd , "delta" , "a.ko" , "b.ko" , 1 ,
879+ )
880+ require .NoError (err )
881+ assert .Equal (expected , got )
882+ }
0 commit comments