diff --git a/client_benchmark_test.go b/client_benchmark_test.go index 2e9ae7e5..fca042d2 100644 --- a/client_benchmark_test.go +++ b/client_benchmark_test.go @@ -100,3 +100,41 @@ func BenchmarkGetGroupsBrief(b *testing.B) { assert.NoError(b, err) } } + +func BenchmarkGetGroup(b *testing.B) { + cfg := GetConfig(b) + client := gocloak.NewClient(cfg.HostName) + teardown, groupID := CreateGroup(b, client) + defer teardown() + token := GetAdminToken(b, client) + b.ResetTimer() + for i := 0; i < b.N; i++ { + _, err := client.GetGroup( + context.Background(), + token.AccessToken, + cfg.GoCloak.Realm, + groupID, + ) + assert.NoError(b, err) + } +} + +func BenchmarkGetGroupByPath(b *testing.B) { + cfg := GetConfig(b) + client := gocloak.NewClient(cfg.HostName) + teardown, groupID := CreateGroup(b, client) + token := GetAdminToken(b, client) + group, err := client.GetGroup(context.Background(), token.AccessToken, cfg.GoCloak.Realm, groupID) + assert.NoError(b, err) + defer teardown() + b.ResetTimer() + for i := 0; i < b.N; i++ { + _, err := client.GetGroupByPath( + context.Background(), + token.AccessToken, + cfg.GoCloak.Realm, + *group.Path, + ) + assert.NoError(b, err) + } +} diff --git a/client_test.go b/client_test.go index 08bacd7e..b59c9cf4 100644 --- a/client_test.go +++ b/client_test.go @@ -163,7 +163,7 @@ func GetClientByClientID(t *testing.T, client *gocloak.GoCloak, clientID string) return nil } -func CreateGroup(t *testing.T, client *gocloak.GoCloak) (func(), string) { +func CreateGroup(t testing.TB, client *gocloak.GoCloak) (func(), string) { cfg := GetConfig(t) token := GetAdminToken(t, client) group := gocloak.Group{ @@ -179,7 +179,9 @@ func CreateGroup(t *testing.T, client *gocloak.GoCloak) (func(), string) { cfg.GoCloak.Realm, group) require.NoError(t, err, "CreateGroup failed") - t.Logf("Created Group ID: %s ", groupID) + if _, isBenchmark := t.(*testing.B); !isBenchmark { + t.Logf("Created Group ID: %s ", groupID) + } tearDown := func() { err := client.DeleteGroup(