Skip to content

Commit

Permalink
fix: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
christianwoehrle committed Oct 22, 2022
1 parent 1a54ea6 commit 501f92a
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion pkg/common/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const (
RealmsGetPath = "/auth/admin/realms/%s"
RealmsCreatePath = "/auth/admin/realms"
RealmsDeletePath = "/auth/admin/realms/%s"
UserCreatePath = "/auth/admin/realms/%s/users"
ClientCreatePath = "/auth/admin/realms/%s/clients"
UserDeletePath = "/auth/admin/realms/%s/users/%s"
UserGetPath = "/auth/admin/realms/%s/users/%s"
UserFindByUsernamePath = "/auth/admin/realms/%s/users?username=%s&max=-1"
Expand All @@ -35,6 +35,13 @@ func getDummyRealm() *v1alpha1.KeycloakRealm {
},
}
}
func getDummyClient() *v1alpha1.KeycloakAPIClient {
return &v1alpha1.KeycloakAPIClient{
ID: "dummy",
Name: "dummy",
Enabled: false,
}
}

func getExistingDummyUser() *v1alpha1.KeycloakAPIUser {
return &v1alpha1.KeycloakAPIUser{
Expand Down Expand Up @@ -178,3 +185,28 @@ func TestClient_useKeycloakServerCertificate(t *testing.T) {
defer resp.Body.Close()
assert.Equal(t, resp.StatusCode, 200)
}

func TestClient_CreateKeycloakCLient(t *testing.T) {
// given
realm := getDummyRealm()

handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
assert.Equal(t, fmt.Sprintf(ClientCreatePath, realm.Spec.Realm.Realm), req.URL.Path)
w.WriteHeader(204)
})
server := httptest.NewServer(handler)
defer server.Close()

client := Client{
requester: server.Client(),
URL: server.URL,
token: "dummy",
}

// when
_, err := client.CreateClient(getDummyClient(), realm.Spec.Realm.Realm)

// then
// correct path expected on httptest server
assert.NoError(t, err)
}

0 comments on commit 501f92a

Please sign in to comment.