-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(rds): DBCluster controller not recognizing changes in VpcSecurity…
…Groups Signed-off-by: Paul Schroeder <[email protected]>
- Loading branch information
1 parent
0f81db2
commit 989cc2d
Showing
4 changed files
with
235 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
package dbcluster | ||
|
||
import ( | ||
"testing" | ||
|
||
svcsdk "github.com/aws/aws-sdk-go/service/rds" | ||
svcapitypes "github.com/crossplane-contrib/provider-aws/apis/rds/v1alpha1" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func ptr[T any](v T) *T { | ||
return &v | ||
} | ||
|
||
func TestIsVPCSecurityGroupIDsUpToDate(t *testing.T) { | ||
type args struct { | ||
cr *svcapitypes.DBCluster | ||
out *svcsdk.DescribeDBClustersOutput | ||
} | ||
|
||
type want struct { | ||
isUpToDate bool | ||
} | ||
|
||
cases := map[string]struct { | ||
args | ||
want | ||
}{ | ||
"NotAsMany": { | ||
args: args{ | ||
cr: &svcapitypes.DBCluster{ | ||
Spec: svcapitypes.DBClusterSpec{ | ||
ForProvider: svcapitypes.DBClusterParameters{ | ||
CustomDBClusterParameters: svcapitypes.CustomDBClusterParameters{ | ||
VPCSecurityGroupIDs: []string{"sg-123", "sg-456"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
out: &svcsdk.DescribeDBClustersOutput{ | ||
DBClusters: []*svcsdk.DBCluster{ | ||
&svcsdk.DBCluster{ | ||
VpcSecurityGroups: []*svcsdk.VpcSecurityGroupMembership{ | ||
&svcsdk.VpcSecurityGroupMembership{ | ||
VpcSecurityGroupId: ptr("sg-123"), | ||
}, | ||
&svcsdk.VpcSecurityGroupMembership{ | ||
VpcSecurityGroupId: ptr("sg-456"), | ||
}, | ||
&svcsdk.VpcSecurityGroupMembership{ | ||
VpcSecurityGroupId: ptr("sg-789"), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
want: want{ | ||
isUpToDate: false, | ||
}, | ||
}, | ||
"DesiredEmpty": { | ||
args: args{ | ||
cr: &svcapitypes.DBCluster{ | ||
Spec: svcapitypes.DBClusterSpec{ | ||
ForProvider: svcapitypes.DBClusterParameters{ | ||
CustomDBClusterParameters: svcapitypes.CustomDBClusterParameters{ | ||
VPCSecurityGroupIDs: nil, | ||
}, | ||
}, | ||
}, | ||
}, | ||
out: &svcsdk.DescribeDBClustersOutput{ | ||
DBClusters: []*svcsdk.DBCluster{ | ||
&svcsdk.DBCluster{ | ||
VpcSecurityGroups: []*svcsdk.VpcSecurityGroupMembership{ | ||
&svcsdk.VpcSecurityGroupMembership{ | ||
VpcSecurityGroupId: ptr("sg-456"), | ||
}, | ||
&svcsdk.VpcSecurityGroupMembership{ | ||
VpcSecurityGroupId: ptr("sg-123"), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
want: want{ | ||
isUpToDate: false, | ||
}, | ||
}, | ||
"ActualEmpty": { | ||
args: args{ | ||
cr: &svcapitypes.DBCluster{ | ||
Spec: svcapitypes.DBClusterSpec{ | ||
ForProvider: svcapitypes.DBClusterParameters{ | ||
CustomDBClusterParameters: svcapitypes.CustomDBClusterParameters{ | ||
VPCSecurityGroupIDs: []string{"sg-123", "sg-456"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
out: &svcsdk.DescribeDBClustersOutput{ | ||
DBClusters: []*svcsdk.DBCluster{ | ||
&svcsdk.DBCluster{ | ||
VpcSecurityGroups: nil, | ||
}, | ||
}, | ||
}, | ||
}, | ||
want: want{ | ||
isUpToDate: false, | ||
}, | ||
}, | ||
"Unsorted": { | ||
args: args{ | ||
cr: &svcapitypes.DBCluster{ | ||
Spec: svcapitypes.DBClusterSpec{ | ||
ForProvider: svcapitypes.DBClusterParameters{ | ||
CustomDBClusterParameters: svcapitypes.CustomDBClusterParameters{ | ||
VPCSecurityGroupIDs: []string{"sg-123", "sg-456"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
out: &svcsdk.DescribeDBClustersOutput{ | ||
DBClusters: []*svcsdk.DBCluster{ | ||
&svcsdk.DBCluster{ | ||
VpcSecurityGroups: []*svcsdk.VpcSecurityGroupMembership{ | ||
&svcsdk.VpcSecurityGroupMembership{ | ||
VpcSecurityGroupId: ptr("sg-456"), | ||
}, | ||
&svcsdk.VpcSecurityGroupMembership{ | ||
VpcSecurityGroupId: ptr("sg-123"), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
want: want{ | ||
isUpToDate: true, | ||
}, | ||
}, | ||
"Identical": { | ||
args: args{ | ||
cr: &svcapitypes.DBCluster{ | ||
Spec: svcapitypes.DBClusterSpec{ | ||
ForProvider: svcapitypes.DBClusterParameters{ | ||
CustomDBClusterParameters: svcapitypes.CustomDBClusterParameters{ | ||
VPCSecurityGroupIDs: []string{"sg-123", "sg-456"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
out: &svcsdk.DescribeDBClustersOutput{ | ||
DBClusters: []*svcsdk.DBCluster{ | ||
&svcsdk.DBCluster{ | ||
VpcSecurityGroups: []*svcsdk.VpcSecurityGroupMembership{ | ||
&svcsdk.VpcSecurityGroupMembership{ | ||
VpcSecurityGroupId: ptr("sg-123"), | ||
}, | ||
&svcsdk.VpcSecurityGroupMembership{ | ||
VpcSecurityGroupId: ptr("sg-456"), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
want: want{ | ||
isUpToDate: true, | ||
}, | ||
}, | ||
} | ||
|
||
for name, tc := range cases { | ||
t.Run(name, func(t *testing.T) { | ||
isUpToDate := isVPCSecurityGroupIDsUpToDate(tc.args.cr, tc.args.out) | ||
|
||
if diff := cmp.Diff(tc.want.isUpToDate, isUpToDate); diff != "" { | ||
t.Errorf("r: -want, +got:\n%s", diff) | ||
} | ||
}) | ||
} | ||
} |