@@ -86,6 +86,10 @@ func (s *MethodTestSuite) TearDownSuite() {
86
86
})
87
87
}
88
88
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.
89
93
func (s * MethodTestSuite ) Subtest (testCaseF func (db database.Store , check * MethodCase )) func () {
90
94
return func () {
91
95
t := s .T ()
@@ -112,6 +116,9 @@ func (s *MethodTestSuite) Subtest(testCaseF func(db database.Store, check *Metho
112
116
113
117
var testCase MethodCase
114
118
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" )
115
122
116
123
// Find the method with the name of the test.
117
124
var callMethod func (ctx context.Context ) ([]reflect.Value , error )
@@ -121,6 +128,7 @@ func (s *MethodTestSuite) Subtest(testCaseF func(db database.Store, check *Metho
121
128
method := azt .Method (i )
122
129
if method .Name == methodName {
123
130
methodF := reflect .ValueOf (az ).Method (i )
131
+
124
132
callMethod = func (ctx context.Context ) ([]reflect.Value , error ) {
125
133
resp := methodF .Call (append ([]reflect.Value {reflect .ValueOf (ctx )}, testCase .inputs ... ))
126
134
return splitResp (t , resp )
@@ -249,11 +257,17 @@ type MethodCase struct {
249
257
expectedOutputs []reflect.Value
250
258
}
251
259
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()'
252
262
func (m * MethodCase ) Asserts (pairs ... any ) * MethodCase {
253
263
m .assertions = asserts (pairs ... )
254
264
return m
255
265
}
256
266
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.
257
271
func (m * MethodCase ) Args (args ... any ) * MethodCase {
258
272
m .inputs = values (args ... )
259
273
return m
0 commit comments