Creation of reusable components for mcs & implementation in users page (#63)
Creation of reusable componentes for mcs: - ModalWrapper => Modal box component with MinIO styles - InputBoxWrapper => Input box component with MinIO styles - RadioGroupSelector => Component that generates a Radio Group Selector combo with the requested options and MinIO styles Implementation of these new components in users creation / edit components Co-authored-by: Benjamin Perez <benjamin@bexsoft.net>
This commit is contained in:
@@ -33,6 +33,7 @@ var minioListUsersMock func() (map[string]madmin.UserInfo, error)
|
||||
var minioAddUserMock func(accessKey, secreyKey string) error
|
||||
var minioRemoveUserMock func(accessKey string) error
|
||||
var minioGetUserInfoMock func(accessKey string) (madmin.UserInfo, error)
|
||||
var minioSetUserStatusMock func(accessKey string, status madmin.AccountStatus) error
|
||||
|
||||
// mock function of listUsers()
|
||||
func (ac adminClientMock) listUsers(ctx context.Context) (map[string]madmin.UserInfo, error) {
|
||||
@@ -54,6 +55,11 @@ func (ac adminClientMock) getUserInfo(ctx context.Context, accessKey string) (ma
|
||||
return minioGetUserInfoMock(accessKey)
|
||||
}
|
||||
|
||||
//mock function of setUserStatus()
|
||||
func (ac adminClientMock) setUserStatus(ctx context.Context, accessKey string, status madmin.AccountStatus) error {
|
||||
return minioSetUserStatusMock(accessKey, status)
|
||||
}
|
||||
|
||||
func TestListUsers(t *testing.T) {
|
||||
assert := asrt.New(t)
|
||||
adminClient := adminClientMock{}
|
||||
@@ -321,3 +327,44 @@ func TestGetUserInfo(t *testing.T) {
|
||||
assert.Equal("error", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetUserStatus(t *testing.T) {
|
||||
assert := asrt.New(t)
|
||||
adminClient := adminClientMock{}
|
||||
function := "setUserStatus()"
|
||||
userName := "userName123"
|
||||
ctx := context.Background()
|
||||
|
||||
// Test-1: setUserStatus() update valid disabled status
|
||||
expectedStatus := "disabled"
|
||||
minioSetUserStatusMock = func(accessKey string, status madmin.AccountStatus) error {
|
||||
return nil
|
||||
}
|
||||
if err := setUserStatus(ctx, adminClient, userName, expectedStatus); err != nil {
|
||||
t.Errorf("Failed on %s:, error occurred: %s", function, err.Error())
|
||||
}
|
||||
// Test-2: setUserStatus() update valid enabled status
|
||||
expectedStatus = "enabled"
|
||||
minioSetUserStatusMock = func(accessKey string, status madmin.AccountStatus) error {
|
||||
return nil
|
||||
}
|
||||
if err := setUserStatus(ctx, adminClient, userName, expectedStatus); err != nil {
|
||||
t.Errorf("Failed on %s:, error occurred: %s", function, err.Error())
|
||||
}
|
||||
// Test-3: setUserStatus() update invalid status, should send error
|
||||
expectedStatus = "invalid"
|
||||
minioSetUserStatusMock = func(accessKey string, status madmin.AccountStatus) error {
|
||||
return nil
|
||||
}
|
||||
if err := setUserStatus(ctx, adminClient, userName, expectedStatus); assert.Error(err) {
|
||||
assert.Equal("status not valid", err.Error())
|
||||
}
|
||||
// Test-4: setUserStatus() handler error correctly
|
||||
expectedStatus = "enabled"
|
||||
minioSetUserStatusMock = func(accessKey string, status madmin.AccountStatus) error {
|
||||
return errors.New("error")
|
||||
}
|
||||
if err := setUserStatus(ctx, adminClient, userName, expectedStatus); assert.Error(err) {
|
||||
assert.Equal("error", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user