Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkg/generate/code/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,8 @@ func CompareStruct(
var compareConfig *ackgenconfig.CompareFieldConfig
// memberFieldPath contains the field path along with the prefix cfg.PrefixConfig.SpecField + "." hence we
// would need to substring to exclude cfg.PrefixConfig.SpecField + "." to get correct field config.
fieldConfig := fieldConfigs[memberFieldPath[len(cfg.PrefixConfig.SpecField) + 1 :len(memberFieldPath)]]
specFieldLen := len(strings.TrimPrefix(cfg.PrefixConfig.SpecField, "."))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix makes sense, i still wonder what part of elasticache/memorydb delta generated code was broken? can we add some unit tests? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a new unit test :)

fieldConfig := fieldConfigs[memberFieldPath[specFieldLen + 1: len(memberFieldPath)]]
if fieldConfig != nil {
compareConfig = fieldConfig.Compare
}
Expand Down
46 changes: 46 additions & 0 deletions pkg/generate/code/compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,3 +475,49 @@ func TestCompareResource_APIGatewayv2_Route(t *testing.T) {
),
)
}

func TestCompareResource_MemoryDB_User(t *testing.T) {
assert := assert.New(t)
require := require.New(t)

g := testutil.NewModelForService(t, "memorydb")

crd := testutil.GetCRDByName(t, g, "User")
require.NotNil(crd)
expected := `
if ackcompare.HasNilDifference(a.ko.Spec.AccessString, b.ko.Spec.AccessString) {
delta.Add("Spec.AccessString", a.ko.Spec.AccessString, b.ko.Spec.AccessString)
} else if a.ko.Spec.AccessString != nil && b.ko.Spec.AccessString != nil {
if *a.ko.Spec.AccessString != *b.ko.Spec.AccessString {
delta.Add("Spec.AccessString", a.ko.Spec.AccessString, b.ko.Spec.AccessString)
}
}
if ackcompare.HasNilDifference(a.ko.Spec.AuthenticationMode, b.ko.Spec.AuthenticationMode) {
delta.Add("Spec.AuthenticationMode", a.ko.Spec.AuthenticationMode, b.ko.Spec.AuthenticationMode)
} else if a.ko.Spec.AuthenticationMode != nil && b.ko.Spec.AuthenticationMode != nil {
if ackcompare.HasNilDifference(a.ko.Spec.AuthenticationMode.Type, b.ko.Spec.AuthenticationMode.Type) {
delta.Add("Spec.AuthenticationMode.Type", a.ko.Spec.AuthenticationMode.Type, b.ko.Spec.AuthenticationMode.Type)
} else if a.ko.Spec.AuthenticationMode.Type != nil && b.ko.Spec.AuthenticationMode.Type != nil {
if *a.ko.Spec.AuthenticationMode.Type != *b.ko.Spec.AuthenticationMode.Type {
delta.Add("Spec.AuthenticationMode.Type", a.ko.Spec.AuthenticationMode.Type, b.ko.Spec.AuthenticationMode.Type)
}
}
}
if ackcompare.HasNilDifference(a.ko.Spec.Name, b.ko.Spec.Name) {
delta.Add("Spec.Name", a.ko.Spec.Name, b.ko.Spec.Name)
} else if a.ko.Spec.Name != nil && b.ko.Spec.Name != nil {
if *a.ko.Spec.Name != *b.ko.Spec.Name {
delta.Add("Spec.Name", a.ko.Spec.Name, b.ko.Spec.Name)
}
}
if !reflect.DeepEqual(a.ko.Spec.Tags, b.ko.Spec.Tags) {
delta.Add("Spec.Tags", a.ko.Spec.Tags, b.ko.Spec.Tags)
}
`
assert.Equal(
expected,
code.CompareResource(
crd.Config(), crd, "delta", "a.ko", "b.ko", 1,
),
)
}
14 changes: 14 additions & 0 deletions pkg/testdata/models/apis/memorydb/0000-00-00/generator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ resources:
terminal_codes:
- InvalidParameterValueException
- UserAlreadyExistsFault
renames:
operations:
CreateUser:
input_fields:
UserName: Name
UpdateUser:
input_fields:
UserName: Name
DeleteUser:
input_fields:
UserName: Name
DescribeUsers:
input_fields:
UserName: Name
fields:
AuthenticationMode.Passwords:
is_secret: true
Expand Down