AllAsserted returns an error if all calls to Authorize() have not been asserted and checked. This is useful for testing to ensure that all Authorize() calls are checked in the unit test.
()
| 179 | // asserted and checked. This is useful for testing to ensure that all |
| 180 | // Authorize() calls are checked in the unit test. |
| 181 | func (r *RecordingAuthorizer) AllAsserted() error { |
| 182 | r.RLock() |
| 183 | defer r.RUnlock() |
| 184 | missed := []AuthCall{} |
| 185 | for _, c := range r.Called { |
| 186 | if !c.asserted { |
| 187 | missed = append(missed, c) |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | if len(missed) > 0 { |
| 192 | return xerrors.Errorf("missed calls: %+v", missed) |
| 193 | } |
| 194 | return nil |
| 195 | } |
| 196 | |
| 197 | // AllCalls is useful for debugging. |
| 198 | func (r *RecordingAuthorizer) AllCalls(actor *rbac.Subject) []AuthCall { |