Skip to content

Commit

Permalink
Merge pull request #75 from crossplane-contrib/duologic/panic_without…
Browse files Browse the repository at this point in the history
…_desired_resourceoptions

test(mysql/user): fail with panic, resourceOptions are optional
  • Loading branch information
jdotw authored Mar 21, 2022
2 parents fb38f43 + 90cd56d commit 77cd294
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 35 deletions.
6 changes: 4 additions & 2 deletions pkg/controller/mysql/user/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,11 @@ func (c *external) Delete(ctx context.Context, mg resource.Managed) error {
}

func upToDate(observed *v1alpha1.UserParameters, desired *v1alpha1.UserParameters) bool {
if desired.ResourceOptions == nil {
// Return true if there are no desired ResourceOptions
return true
}
if observed.ResourceOptions.MaxQueriesPerHour != desired.ResourceOptions.MaxQueriesPerHour {
fmt.Printf("%#v\n", observed.ResourceOptions.MaxQueriesPerHour)
fmt.Printf("%#v\n", desired.ResourceOptions.MaxQueriesPerHour)
return false
}
if observed.ResourceOptions.MaxUpdatesPerHour != desired.ResourceOptions.MaxUpdatesPerHour {
Expand Down
37 changes: 4 additions & 33 deletions pkg/controller/mysql/user/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,7 @@ func TestObserve(t *testing.T) {
args: args{
mg: &v1alpha1.User{
Spec: v1alpha1.UserSpec{
ForProvider: v1alpha1.UserParameters{
ResourceOptions: &v1alpha1.ResourceOptions{
MaxQueriesPerHour: new(int),
MaxUpdatesPerHour: new(int),
MaxConnectionsPerHour: new(int),
MaxUserConnections: new(int),
},
},
ForProvider: v1alpha1.UserParameters{},
},
},
},
Expand Down Expand Up @@ -265,9 +258,7 @@ func TestObserve(t *testing.T) {
args: args{
mg: &v1alpha1.User{
Spec: v1alpha1.UserSpec{
ForProvider: v1alpha1.UserParameters{
ResourceOptions: &v1alpha1.ResourceOptions{},
},
ForProvider: v1alpha1.UserParameters{},
},
},
},
Expand Down Expand Up @@ -306,12 +297,6 @@ func TestObserve(t *testing.T) {
},
Key: "password",
},
ResourceOptions: &v1alpha1.ResourceOptions{
MaxQueriesPerHour: new(int),
MaxUpdatesPerHour: new(int),
MaxConnectionsPerHour: new(int),
MaxUserConnections: new(int),
},
},
ResourceSpec: xpv1.ResourceSpec{
WriteConnectionSecretToReference: &xpv1.SecretReference{
Expand Down Expand Up @@ -411,14 +396,7 @@ func TestCreate(t *testing.T) {
},
},
Spec: v1alpha1.UserSpec{
ForProvider: v1alpha1.UserParameters{
ResourceOptions: &v1alpha1.ResourceOptions{
MaxQueriesPerHour: new(int),
MaxUpdatesPerHour: new(int),
MaxConnectionsPerHour: new(int),
MaxUserConnections: new(int),
},
},
ForProvider: v1alpha1.UserParameters{},
},
},
},
Expand Down Expand Up @@ -860,14 +838,7 @@ func TestDelete(t *testing.T) {
args: args{
mg: &v1alpha1.User{
Spec: v1alpha1.UserSpec{
ForProvider: v1alpha1.UserParameters{
ResourceOptions: &v1alpha1.ResourceOptions{
MaxQueriesPerHour: new(int),
MaxUpdatesPerHour: new(int),
MaxConnectionsPerHour: new(int),
MaxUserConnections: new(int),
},
},
ForProvider: v1alpha1.UserParameters{},
},
},
},
Expand Down

0 comments on commit 77cd294

Please sign in to comment.