BenchmarkRBACFilter benchmarks the rbac.Filter method. go test -bench '^BenchmarkRBACFilter$' -benchmem -memprofile memprofile.out -cpuprofile profile.out
(b *testing.B)
| 231 | // |
| 232 | // go test -bench '^BenchmarkRBACFilter$' -benchmem -memprofile memprofile.out -cpuprofile profile.out |
| 233 | func BenchmarkRBACFilter(b *testing.B) { |
| 234 | benchCases, user, orgs := benchmarkUserCases() |
| 235 | users := append([]uuid.UUID{}, |
| 236 | user, |
| 237 | uuid.MustParse("4ca78b1d-f2d2-4168-9d76-cd93b51c6c1e"), |
| 238 | uuid.MustParse("0632b012-49e0-4d70-a5b3-f4398f1dcd52"), |
| 239 | uuid.MustParse("70dbaa7a-ea9c-4f68-a781-97b08af8461d"), |
| 240 | ) |
| 241 | |
| 242 | authorizer := rbac.NewStrictCachingAuthorizer(prometheus.NewRegistry()) |
| 243 | |
| 244 | for _, c := range benchCases { |
| 245 | b.Run("PrepareOnly-"+c.Name, func(b *testing.B) { |
| 246 | obType := rbac.ResourceWorkspace.Type |
| 247 | for i := 0; i < b.N; i++ { |
| 248 | _, err := authorizer.Prepare(context.Background(), c.Actor, policy.ActionRead, obType) |
| 249 | require.NoError(b, err) |
| 250 | } |
| 251 | }) |
| 252 | } |
| 253 | |
| 254 | for _, c := range benchCases { |
| 255 | b.Run(c.Name, func(b *testing.B) { |
| 256 | objects := benchmarkSetup(orgs, users, b.N) |
| 257 | b.ResetTimer() |
| 258 | allowed, err := rbac.Filter(context.Background(), authorizer, c.Actor, policy.ActionRead, objects) |
| 259 | require.NoError(b, err) |
| 260 | _ = allowed |
| 261 | }) |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | func benchmarkSetup(orgs []uuid.UUID, users []uuid.UUID, size int, opts ...func(object rbac.Object) rbac.Object) []rbac.Object { |
| 266 | // Create a "random" but deterministic set of objects. |
nothing calls this directly
no test coverage detected