Skip to content

Commit

Permalink
Fix/consolidate unit tests for two PRs (#140)
Browse files Browse the repository at this point in the history
Signed-off-by: Duologic <[email protected]>
Co-authored-by: Duologic <[email protected]>
  • Loading branch information
alereca and Duologic authored Mar 21, 2023
1 parent aaba25a commit 3147b96
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
16 changes: 12 additions & 4 deletions pkg/controller/mysql/grant/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,22 @@ func (c *external) getPrivileges(ctx context.Context, username, dbname string, t
return nil, nil, errors.Wrap(err, errCurrentGrant)
}

// In mysql when all grants are revoked from user, it still grants usage (meaning no privileges) on *.*
// So the grant can be considered as non existent, just like when privileges slice is nil/empty
// In mysql when all grants are revoked from user, it still grants usage (meaning no
// privileges) on *.* So the grant can be considered as non existent, just like when
// privileges slice is nil/empty
// https://dev.mysql.com/doc/refman/8.0/en/privileges-provided.html#priv_usage
if privileges == nil || privilegesEqual(privileges, []string{"USAGE"}) {
var ret []string
for _, p := range privileges {
if p != "USAGE" {
ret = append(ret, p)
}
}

if ret == nil {
return nil, &managed.ExternalObservation{ResourceExists: false}, nil
}

return privileges, nil, nil
return ret, nil, nil
}

func (c *external) parseGrantRows(ctx context.Context, username string, host string, dbname string, table string) ([]string, error) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/mysql/grant/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,8 @@ func TestObserve(t *testing.T) {
ResourceExists: true,
ResourceUpToDate: false,
},
err: nil,
observedPrivileges: []string{"INSERT"},
err: nil,
},
},
"SuccessDiffGrantUsage": {
Expand Down

0 comments on commit 3147b96

Please sign in to comment.