8000 chore: enforcement of dbauthz tests was broken by Emyrk · Pull Request #11218 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

chore: enforcement of dbauthz tests was broken #11218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Dec 15, 2023
Merged
Changes from 1 commit
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
8000 Prev Previous commit
Next Next commit
dbauthz: allow asserting errors in tests
  • Loading branch information
johnstcn authored and Emyrk committed Dec 15, 2023
commit a876975e3eb9451574c592d92e2cefad49d5c575
13 changes: 12 additions & 1 deletion coderd/database/dbauthz/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ func (s *MethodTestSuite) Subtest(testCaseF func(db database.Store, check *expec
fakeAuthorizer.AlwaysReturn = nil

outputs, err := callMethod(ctx)
s.NoError(err, "method %q returned an error", methodName)
if testCase.err == nil {
s.NoError(err, "method %q returned an error", methodName)
} else {
s.EqualError(err, testCase.err.Error(), "method %q returned an unexpected error", methodName)
}

// Some tests may not care about the outputs, so we only assert if
// they are provided.
Expand Down Expand Up @@ -292,6 +296,7 @@ type expects struct {
assertions []AssertRBAC
// outputs is optional. Can assert non-error return values.
outputs []reflect.Value
err error
}

// Asserts is required. Asserts the RBAC authorize calls that should be made.
Expand All @@ -316,6 +321,12 @@ func (m *expects) Returns(rets ...any) *expects {
return m
}

// Errors is optional. If it is never called, it will not be asserted.
func (m *expects) Errors(err error) *expects {
m.err = err
return m
}

// AssertRBAC contains the object and actions to be asserted.
type AssertRBAC struct {
Object rbac.Object
Expand Down
0