Skip to content

Commit

Permalink
add management of DB failure while reading the configuration --> retu…
Browse files Browse the repository at this point in the history
…rn error
  • Loading branch information
Laurent Pages committed Apr 23, 2019
1 parent f02da37 commit 8687d7e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/management/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,11 @@ func (c *component) GetRealmCustomConfiguration(ctx context.Context, realmName s
// from the realm ID, fetch the custom configuration
realmID := realmConfig.Id
customConfigJSON, err := c.configDBModule.GetConfiguration(ctx, *realmID)
// DB error
if err != nil {
return customConfig, err
}
// empty config
if customConfigJSON == "" {
// database is empty
return customConfig, nil
Expand Down
26 changes: 26 additions & 0 deletions pkg/management/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1562,6 +1562,32 @@ func TestGetRealmCustomConfiguration(t *testing.T) {

assert.NotNil(t, err)
}

// DB error
{
var id = realmID
var keycloakVersion = "4.8.3"
var realm = "master"
var displayName = "Master"
var enabled = true

var kcRealmRep = kc.RealmRepresentation{
Id: &id,
KeycloakVersion: &keycloakVersion,
Realm: &realm,
DisplayName: &displayName,
Enabled: &enabled,
}

mockKeycloakClient.EXPECT().GetRealm(accessToken, realmID).Return(kcRealmRep, nil).Times(1)

var ctx = context.WithValue(context.Background(), "access_token", accessToken)
mockConfigurationDBModule.EXPECT().GetConfiguration(ctx, realmID).Return("", errors.New("error")).Times(1)

_, err := managementComponent.GetRealmCustomConfiguration(ctx, realmID)

assert.NotNil(t, err)
}
}

func TestUpdateRealmCustomConfiguration(t *testing.T) {
Expand Down

0 comments on commit 8687d7e

Please sign in to comment.