(b *testing.B)
| 45 | } |
| 46 | |
| 47 | func BenchmarkRoleManagerMedium(b *testing.B) { |
| 48 | e, _ := NewEnforcer("examples/rbac_model.conf") |
| 49 | // Do not rebuild the role inheritance relations for every AddGroupingPolicy() call. |
| 50 | e.EnableAutoBuildRoleLinks(false) |
| 51 | |
| 52 | // 1000 roles, 100 resources. |
| 53 | pPolicies := make([][]string, 0) |
| 54 | for i := 0; i < 1000; i++ { |
| 55 | pPolicies = append(pPolicies, []string{fmt.Sprintf("group%d", i), fmt.Sprintf("data%d", i/10), "read"}) |
| 56 | } |
| 57 | _, err := e.AddPolicies(pPolicies) |
| 58 | if err != nil { |
| 59 | b.Fatal(err) |
| 60 | } |
| 61 | |
| 62 | // 10000 users. |
| 63 | gPolicies := make([][]string, 0) |
| 64 | for i := 0; i < 10000; i++ { |
| 65 | gPolicies = append(gPolicies, []string{fmt.Sprintf("user%d", i), fmt.Sprintf("group%d", i/10)}) |
| 66 | } |
| 67 | |
| 68 | _, err = e.AddGroupingPolicies(gPolicies) |
| 69 | if err != nil { |
| 70 | b.Fatal(err) |
| 71 | } |
| 72 | |
| 73 | err = e.BuildRoleLinks() |
| 74 | if err != nil { |
| 75 | b.Fatal(err) |
| 76 | } |
| 77 | |
| 78 | rm := e.GetRoleManager() |
| 79 | |
| 80 | b.ResetTimer() |
| 81 | for i := 0; i < b.N; i++ { |
| 82 | for j := 0; j < 1000; j++ { |
| 83 | _, _ = rm.HasLink("user501", fmt.Sprintf("group%d", j)) |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | func BenchmarkRoleManagerLarge(b *testing.B) { |
| 89 | e, _ := NewEnforcer("examples/rbac_model.conf") |
nothing calls this directly
no test coverage detected
searching dependent graphs…