Skip to content

Commit 3147b96

Browse files
alerecaDuologic
andauthored
Fix/consolidate unit tests for two PRs (#140)
Signed-off-by: Duologic <[email protected]> Co-authored-by: Duologic <[email protected]>
1 parent aaba25a commit 3147b96

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

pkg/controller/mysql/grant/reconciler.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,22 @@ func (c *external) getPrivileges(ctx context.Context, username, dbname string, t
194194
return nil, nil, errors.Wrap(err, errCurrentGrant)
195195
}
196196

197-
// In mysql when all grants are revoked from user, it still grants usage (meaning no privileges) on *.*
198-
// So the grant can be considered as non existent, just like when privileges slice is nil/empty
197+
// In mysql when all grants are revoked from user, it still grants usage (meaning no
198+
// privileges) on *.* So the grant can be considered as non existent, just like when
199+
// privileges slice is nil/empty
199200
// https://dev.mysql.com/doc/refman/8.0/en/privileges-provided.html#priv_usage
200-
if privileges == nil || privilegesEqual(privileges, []string{"USAGE"}) {
201+
var ret []string
202+
for _, p := range privileges {
203+
if p != "USAGE" {
204+
ret = append(ret, p)
205+
}
206+
}
207+
208+
if ret == nil {
201209
return nil, &managed.ExternalObservation{ResourceExists: false}, nil
202210
}
203211

204-
return privileges, nil, nil
212+
return ret, nil, nil
205213
}
206214

207215
func (c *external) parseGrantRows(ctx context.Context, username string, host string, dbname string, table string) ([]string, error) {

pkg/controller/mysql/grant/reconciler_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,8 @@ func TestObserve(t *testing.T) {
379379
ResourceExists: true,
380380
ResourceUpToDate: false,
381381
},
382-
err: nil,
382+
observedPrivileges: []string{"INSERT"},
383+
err: nil,
383384
},
384385
},
385386
"SuccessDiffGrantUsage": {

0 commit comments

Comments
 (0)