Skip to content

Commit

Permalink
add missing tests for the endpoint layer
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurent Pages committed Apr 18, 2019
1 parent 74b36fe commit b406482
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/management/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,10 @@ func MakeUpdateRealmCustomConfigurationEndpoint(managementComponent ManagementCo
return func(ctx context.Context, req interface{}) (interface{}, error) {
var m = req.(map[string]string)

roleJson := []byte(m["body"])
configJson := []byte(m["body"])

var customConfig api.RealmCustomConfiguration
err := json.Unmarshal(roleJson, &customConfig)
err := json.Unmarshal(configJson, &customConfig)
if err != nil {
return nil, err
}
Expand Down
67 changes: 67 additions & 0 deletions pkg/management/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -655,3 +655,70 @@ func TestCreateClientRoleEndpoint(t *testing.T) {
assert.NotNil(t, err)
}
}

func TestGetRealmCustomConfigurationEndpoint(t *testing.T) {
var mockCtrl = gomock.NewController(t)
defer mockCtrl.Finish()

var mockManagementComponent = mock.NewManagementComponent(mockCtrl)

var e = MakeGetRealmCustomConfigurationEndpoint(mockManagementComponent)

// No error
{
var realmName = "master"
var clientID = "123456"
var ctx = context.Background()
var req = make(map[string]string)
req["realm"] = realmName
req["clientID"] = clientID

mockManagementComponent.EXPECT().GetRealmCustomConfiguration(ctx, realmName).Return(api.RealmCustomConfiguration{}, nil).Times(1)
var res, err = e(ctx, req)
assert.Nil(t, err)
assert.NotNil(t, res)
}
}

func TestUpdateRealmCustomConfigurationEndpoint(t *testing.T) {
var mockCtrl = gomock.NewController(t)
defer mockCtrl.Finish()

var mockManagementComponent = mock.NewManagementComponent(mockCtrl)

var e = MakeUpdateRealmCustomConfigurationEndpoint(mockManagementComponent)

// No error
{
var realmName = "master"
var clientID = "123456"
var configJSON = "{\"DefaultClientId\":\"clientId\", \"DefaultRedirectUri\":\"http://cloudtrust.io\"}"
var ctx = context.Background()
var req = make(map[string]string)
req["realm"] = realmName
req["clientID"] = clientID
req["body"] = configJSON

mockManagementComponent.EXPECT().UpdateRealmCustomConfiguration(ctx, realmName, gomock.Any()).Return(nil).Times(1)
var res, err = e(ctx, req)
assert.Nil(t, err)
assert.Nil(t, res)
}

// JSON error
{
var realmName = "master"
var clientID = "123456"
var configJSON = "{\"DefaultClientId\":\"clientId\", \"DefaultRedirectUri\":\"http://cloudtrust.io\""
var ctx = context.Background()
var req = make(map[string]string)
req["realm"] = realmName
req["clientID"] = clientID
req["body"] = configJSON

mockManagementComponent.EXPECT().UpdateRealmCustomConfiguration(ctx, realmName, gomock.Any()).Return(nil).Times(0)
var res, err = e(ctx, req)
assert.NotNil(t, err)
assert.Nil(t, res)
}
}

0 comments on commit b406482

Please sign in to comment.