Skip to content

Commit b369c99

Browse files
committed
Add comments
1 parent 97ad3df commit b369c99

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

coderd/authzquery/methods_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ func (s *MethodTestSuite) TearDownSuite() {
8686
})
8787
}
8888

89+
// Subtest is a helper function that returns a function that can be passed to
90+
// s.Run(). This function will run the test case for the method that is being
91+
// tested. The check parameter is used to assert the results of the method.
92+
// If the caller does not use the `check` parameter, the test will fail.
8993
func (s *MethodTestSuite) Subtest(testCaseF func(db database.Store, check *MethodCase)) func() {
9094
return func() {
9195
t := s.T()
@@ -112,6 +116,9 @@ func (s *MethodTestSuite) Subtest(testCaseF func(db database.Store, check *Metho
112116

113117
var testCase MethodCase
114118
testCaseF(db, &testCase)
119+
// Check the developer added assertions. If there are no assertions,
120+
// an empty list should be passed.
121+
s.Require().False(testCase.assertions == nil, "rbac assertions not set, use the 'check' parameter")
115122

116123
// Find the method with the name of the test.
117124
var callMethod func(ctx context.Context) ([]reflect.Value, error)
@@ -121,6 +128,7 @@ func (s *MethodTestSuite) Subtest(testCaseF func(db database.Store, check *Metho
121128
method := azt.Method(i)
122129
if method.Name == methodName {
123130
methodF := reflect.ValueOf(az).Method(i)
131+
124132
callMethod = func(ctx context.Context) ([]reflect.Value, error) {
125133
resp := methodF.Call(append([]reflect.Value{reflect.ValueOf(ctx)}, testCase.inputs...))
126134
return splitResp(t, resp)
@@ -249,11 +257,17 @@ type MethodCase struct {
249257
expectedOutputs []reflect.Value
250258
}
251259

260+
// Asserts is required. Asserts the RBAC authorize calls that should be made.
261+
// If no RBAC calls are expected, pass an empty list: 'm.Asserts()'
252262
func (m *MethodCase) Asserts(pairs ...any) *MethodCase {
253263
m.assertions = asserts(pairs...)
254264
return m
255265
}
256266

267+
// Args is required. The arguments to be provided to the method.
268+
// If there are no arguments, pass an empty list: 'm.Args()'
269+
// The first context argument should not be included, as the test suite
270+
// will provide it.
257271
func (m *MethodCase) Args(args ...any) *MethodCase {
258272
m.inputs = values(args...)
259273
return m

0 commit comments

Comments
 (0)