@@ -122,7 +122,7 @@ func (s *MethodTestSuite) Subtest(testCaseF func(db database.Store, check *Metho
122
122
if method .Name == methodName {
123
123
methodF := reflect .ValueOf (az ).Method (i )
124
124
callMethod = func (ctx context.Context ) ([]reflect.Value , error ) {
125
- resp := methodF .Call (append ([]reflect.Value {reflect .ValueOf (ctx )}, testCase .Inputs ... ))
125
+ resp := methodF .Call (append ([]reflect.Value {reflect .ValueOf (ctx )}, testCase .inputs ... ))
126
126
return splitResp (t , resp )
127
127
}
128
128
break MethodLoop
@@ -133,7 +133,7 @@ func (s *MethodTestSuite) Subtest(testCaseF func(db database.Store, check *Metho
133
133
134
134
// Run tests that are only run if the method makes rbac assertions.
135
135
// These tests assert the error conditions of the method.
136
- if len (testCase .Assertions ) > 0 {
136
+ if len (testCase .assertions ) > 0 {
137
137
// Only run these tests if we know the underlying call makes
138
138
// rbac assertions.
139
139
s .NotAuthorizedErrorTest (ctx , fakeAuthorizer , callMethod )
@@ -150,11 +150,11 @@ func (s *MethodTestSuite) Subtest(testCaseF func(db database.Store, check *Metho
150
150
151
151
// Some tests may not care about the outputs, so we only assert if
152
152
// they are provided.
153
- if testCase .ExpectedOutputs != nil {
153
+ if testCase .expectedOutputs != nil {
154
154
// Assert the required outputs
155
- s .Equal (len (testCase .ExpectedOutputs ), len (outputs ), "method %q returned unexpected number of outputs" , methodName )
155
+ s .Equal (len (testCase .expectedOutputs ), len (outputs ), "method %q returned unexpected number of outputs" , methodName )
156
156
for i := range outputs {
157
- a , b := testCase .ExpectedOutputs [i ].Interface (), outputs [i ].Interface ()
157
+ a , b := testCase .expectedOutputs [i ].Interface (), outputs [i ].Interface ()
158
158
if reflect .TypeOf (a ).Kind () == reflect .Slice || reflect .TypeOf (a ).Kind () == reflect .Array {
159
159
// Order does not matter
160
160
s .ElementsMatch (a , b , "method %q returned unexpected output %d" , methodName , i )
@@ -165,7 +165,7 @@ func (s *MethodTestSuite) Subtest(testCaseF func(db database.Store, check *Metho
165
165
}
166
166
167
167
var pairs []coderdtest.ActionObjectPair
168
- for _ , assrt := range testCase .Assertions {
168
+ for _ , assrt := range testCase .assertions {
169
169
for _ , action := range assrt .Actions {
170
170
pairs = append (pairs , coderdtest.ActionObjectPair {
171
171
Action : action ,
@@ -246,17 +246,17 @@ MethodLoop:
246
246
if method .Name == methodName {
247
247
methodF := reflect .ValueOf (az ).Method (i )
248
248
callMethod = func (ctx context.Context ) ([]reflect.Value , error ) {
249
- resp := methodF .Call (append ([]reflect.Value {reflect .ValueOf (ctx )}, testCase .Inputs ... ))
249
+ resp := methodF .Call (append ([]reflect.Value {reflect .ValueOf (ctx )}, testCase .inputs ... ))
250
250
return splitResp (t , resp )
251
251
}
252
252
break MethodLoop
253
253
254
- //if len(testCase.Assertions ) > 0 {
254
+ //if len(testCase.assertions ) > 0 {
255
255
// fakeAuthorizer.AlwaysReturn = xerrors.New("Always fail authz")
256
256
// // If we have assertions, that means the method should FAIL
257
257
// // if RBAC will disallow the request. The returned error should
258
258
// // be expected to be a NotAuthorizedError.
259
- // erroredResp := reflect.ValueOf(az).Method(i).Call(append([]reflect.Value{reflect.ValueOf(ctx)}, testCase.Inputs ...))
259
+ // erroredResp := reflect.ValueOf(az).Method(i).Call(append([]reflect.Value{reflect.ValueOf(ctx)}, testCase.inputs ...))
260
260
// _, err := splitResp(t, erroredResp)
261
261
// // This is unfortunate, but if we are using `Filter` the error returned will be nil. So filter out
262
262
// // any case where the error is nil and the response is an empty slice.
@@ -270,7 +270,7 @@ MethodLoop:
270
270
// rec.Reset()
271
271
//}
272
272
273
- //resp := reflect.ValueOf(az).Method(i).Call(append([]reflect.Value{reflect.ValueOf(ctx)}, testCase.Inputs ...))
273
+ //resp := reflect.ValueOf(az).Method(i).Call(append([]reflect.Value{reflect.ValueOf(ctx)}, testCase.inputs ...))
274
274
//
275
275
//outputs, err := splitResp(t, resp)
276
276
//require.NoError(t, err, "method %q returned an error", testName)
@@ -299,7 +299,7 @@ MethodLoop:
299
299
300
300
// Run tests that are only run if the method makes rbac assertions.
301
301
// These tests assert the error conditions of the method.
302
- if len (testCase .Assertions ) > 0 {
302
+ if len (testCase .assertions ) > 0 {
303
303
// Only run these tests if we know the underlying call makes
304
304
// rbac assertions.
305
305
s .NotAuthorizedErrorTest (ctx , fakeAuthorizer , callMethod )
@@ -315,11 +315,11 @@ MethodLoop:
315
315
316
316
// Some tests may not care about the outputs, so we only assert if
317
317
// they are provided.
318
- if testCase .ExpectedOutputs != nil {
318
+ if testCase .expectedOutputs != nil {
319
319
// Assert the required outputs
320
- s .Equal (len (testCase .ExpectedOutputs ), len (outputs ), "method %q returned unexpected number of outputs" , methodName )
320
+ s .Equal (len (testCase .expectedOutputs ), len (outputs ), "method %q returned unexpected number of outputs" , methodName )
321
321
for i := range outputs {
322
- a , b := testCase .ExpectedOutputs [i ].Interface (), outputs [i ].Interface ()
322
+ a , b := testCase .expectedOutputs [i ].Interface (), outputs [i ].Interface ()
323
323
if reflect .TypeOf (a ).Kind () == reflect .Slice || reflect .TypeOf (a ).Kind () == reflect .Array {
324
324
// Order does not matter
325
325
s .ElementsMatch (a , b , "method %q returned unexpected output %d" , methodName , i )
@@ -330,7 +330,7 @@ MethodLoop:
330
330
}
331
331
332
332
var pairs []coderdtest.ActionObjectPair
333
- for _ , assrt := range testCase .Assertions {
333
+ for _ , assrt := range testCase .assertions {
334
334
for _ , action := range assrt .Actions {
335
335
pairs = append (pairs , coderdtest.ActionObjectPair {
336
336
Action : action ,
@@ -377,25 +377,25 @@ func splitResp(t *testing.T, values []reflect.Value) ([]reflect.Value, error) {
377
377
// A MethodCase contains the inputs to be provided to a single method call,
378
378
// and the assertions to be made on the RBAC checks.
379
379
type MethodCase struct {
380
- Inputs []reflect.Value
381
- Assertions []AssertRBAC
382
- // Output is optional. Can assert non-error return values.
383
- ExpectedOutputs []reflect.Value
380
+ inputs []reflect.Value
381
+ assertions []AssertRBAC
382
+ // expectedOutputs is optional. Can assert non-error return values.
383
+ expectedOutputs []reflect.Value
384
384
}
385
385
386
386
func (m * MethodCase ) Asserts (pairs ... any ) * MethodCase {
387
- m .Assertions = asserts (pairs ... )
387
+ m .assertions = asserts (pairs ... )
388
388
return m
389
389
}
390
390
391
391
func (m * MethodCase ) Args (args ... any ) * MethodCase {
392
- m .Inputs = values (args ... )
392
+ m .inputs = values (args ... )
393
393
return m
394
394
}
395
395
396
396
// Returns is optional. If it is never called, it will not be asserted.
397
397
func (m * MethodCase ) Returns (rets ... any ) * MethodCase {
398
- m .ExpectedOutputs = values (rets ... )
398
+ m .expectedOutputs = values (rets ... )
399
399
return m
400
400
}
401
401
@@ -412,16 +412,16 @@ type AssertRBAC struct {
412
412
// is equivalent to
413
413
//
414
414
// MethodCase{
415
- // Inputs : values(workspace, template, ...),
416
- // Assertions : asserts(workspace, rbac.ActionRead, template, rbac.ActionRead, ...),
415
+ // inputs : values(workspace, template, ...),
416
+ // assertions : asserts(workspace, rbac.ActionRead, template, rbac.ActionRead, ...),
417
417
// }
418
418
//
419
419
// Deprecated: use MethodCase instead.
420
420
func methodCase (ins []reflect.Value , assertions []AssertRBAC , outs []reflect.Value ) MethodCase {
421
421
return MethodCase {
422
- Inputs : ins ,
423
- Assertions : assertions ,
424
- ExpectedOutputs : outs ,
422
+ inputs : ins ,
423
+ assertions : assertions ,
424
+ expectedOutputs : outs ,
425
425
}
426
426
}
427
427
@@ -500,20 +500,16 @@ func asserts(inputs ...any) []AssertRBAC {
500
500
}
501
501
502
502
func (s * MethodTestSuite ) TestExtraMethods () {
503
- s .Run ("GetProvisionerDaemons" , func () {
504
- s .RunMethodTest (func (t * testing.T , db database.Store ) MethodCase {
505
- d , err := db .InsertProvisionerDaemon (context .Background (), database.InsertProvisionerDaemonParams {
506
- ID : uuid .New (),
507
- })
508
- require .NoError (t , err , "insert provisioner daemon" )
509
- return methodCase (values (), asserts (d , rbac .ActionRead ), nil )
510
- })
511
- })
512
- s .Run ("GetDeploymentDAUs" , func () {
513
- s .RunMethodTest (func (t * testing.T , db database.Store ) MethodCase {
514
- return methodCase (values (), asserts (rbac .ResourceUser .All (), rbac .ActionRead ), nil )
503
+ s .Run ("GetProvisionerDaemons" , s .Subtest (func (db database.Store , check * MethodCase ) {
504
+ d , err := db .InsertProvisionerDaemon (context .Background (), database.InsertProvisionerDaemonParams {
505
+ ID : uuid .New (),
515
506
})
516
- })
507
+ s .NoError (err , "insert provisioner daemon" )
508
+ check .Args ().Asserts (d , rbac .ActionRead )
509
+ }))
510
+ s .Run ("GetDeploymentDAUs" , s .Subtest (func (db database.Store , check * MethodCase ) {
511
+ check .Args ().Asserts (rbac .ResourceUser .All (), rbac .ActionRead )
512
+ }))
517
513
}
518
514
519
515
type emptyPreparedAuthorized struct {}
0 commit comments