Skip to content

Commit

Permalink
get group and get group by path benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Osmian authored and Mike Osmian committed Apr 7, 2023
1 parent 2189847 commit d3ddd05
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
38 changes: 38 additions & 0 deletions client_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
6 changes: 4 additions & 2 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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(
Expand Down

0 comments on commit d3ddd05

Please sign in to comment.