@@ -20,17 +20,44 @@ import (
20
20
"github.com/coder/coder/coderd/rbac"
21
21
)
22
22
23
+ var (
24
+ skipMethods = map [string ]any {
25
+ "InTx" : struct {}{},
26
+ "Ping" : struct {}{},
27
+ }
28
+ )
29
+
23
30
// Define the suite, and absorb the built-in basic suite
24
31
// functionality from testify - including a T() method which
25
32
// returns the current testing context
26
33
type MethodTestSuite struct {
27
34
suite.Suite
35
+ // methodAccounting counts all methods called by a 'RunMethodTest'
36
+ methodAccounting map [string ]int
28
37
}
29
38
30
- func (suite * MethodTestSuite ) SetupTest () {
39
+ func (suite * MethodTestSuite ) SetupSuite () {
40
+ az := & authzquery.AuthzQuerier {}
41
+ azt := reflect .TypeOf (az )
42
+ suite .methodAccounting = make (map [string ]int )
43
+ for i := 0 ; i < azt .NumMethod (); i ++ {
44
+ method := azt .Method (i )
45
+ if _ , ok := skipMethods [method .Name ]; ok {
46
+ continue
47
+ }
48
+ suite .methodAccounting [method .Name ] = 0
49
+ }
31
50
}
32
51
33
- func (suite * MethodTestSuite ) TearDownTest () {
52
+ func (suite * MethodTestSuite ) TearDownSuite () {
53
+ suite .Run ("Accounting" , func () {
54
+ t := suite .T ()
55
+ for m , c := range suite .methodAccounting {
56
+ if c <= 0 {
57
+ t .Errorf ("Method %q never called" , m )
58
+ }
59
+ }
60
+ })
34
61
}
35
62
36
63
// In order for 'go test' to run this suite, we need to create
@@ -49,10 +76,12 @@ type AssertRBAC struct {
49
76
Actions []rbac.Action
50
77
}
51
78
52
- func (suite * MethodTestSuite ) RunMethodTest (t * testing.T , testCaseF func (t * testing.T , db database.Store ) MethodCase ) {
79
+ func (suite * MethodTestSuite ) RunMethodTest (testCaseF func (t * testing.T , db database.Store ) MethodCase ) {
80
+ t := suite .T ()
53
81
testName := suite .T ().Name ()
54
82
names := strings .Split (testName , "/" )
55
83
methodName := names [len (names )- 1 ]
84
+ suite .methodAccounting [methodName ]++
56
85
57
86
db := databasefake .New ()
58
87
rec := & coderdtest.RecordingAuthorizer {
0 commit comments