Restore mock files and adjust failing tests

This commit is contained in:
Juan Pablo Villafáñez
2022-01-13 09:33:49 +01:00
parent 7bfb6c7d3e
commit b62c9044af
6 changed files with 323 additions and 44 deletions

View File

@@ -8,7 +8,7 @@ import (
"github.com/owncloud/ocis/ocis-pkg/indexer/option"
//. "github.com/owncloud/ocis/ocis-pkg/indexer/test"
"github.com/owncloud/ocis/accounts/pkg/proto/v0"
accountsmsg "github.com/owncloud/ocis/protogen/gen/ocis/messages/accounts/v1"
"github.com/stretchr/testify/assert"
)
@@ -236,7 +236,7 @@ func TestAdd(t *testing.T) {
}),
option.WithDataDir(tmpDir),
option.WithFilesDir(filepath.Join(tmpDir, "data")),
option.WithEntity(&proto.Account{}),
option.WithEntity(&accountsmsg.Account{}),
option.WithTypeName("owncloud.Account"),
option.WithIndexBy("UidNumber"),
)

View File

@@ -22,13 +22,14 @@ import (
"github.com/golang/protobuf/ptypes/empty"
accountsCfg "github.com/owncloud/ocis/accounts/pkg/config"
accountsLogging "github.com/owncloud/ocis/accounts/pkg/logging"
accountsProto "github.com/owncloud/ocis/accounts/pkg/proto/v0"
accountsSvc "github.com/owncloud/ocis/accounts/pkg/service/v0"
accountsServiceExt "github.com/owncloud/ocis/accounts/pkg/service/v0"
ocisLog "github.com/owncloud/ocis/ocis-pkg/log"
"github.com/owncloud/ocis/ocis-pkg/service/grpc"
"github.com/owncloud/ocis/ocs/pkg/config"
svc "github.com/owncloud/ocis/ocs/pkg/service/v0"
accountsmsg "github.com/owncloud/ocis/protogen/gen/ocis/messages/accounts/v1"
settingsmsg "github.com/owncloud/ocis/protogen/gen/ocis/messages/settings/v1"
accountssvc "github.com/owncloud/ocis/protogen/gen/ocis/services/accounts/v1"
settingssvc "github.com/owncloud/ocis/protogen/gen/ocis/services/settings/v1"
ssvc "github.com/owncloud/ocis/settings/pkg/service/v0"
"github.com/stretchr/testify/assert"
@@ -481,10 +482,10 @@ func assertUsersSame(t *testing.T, expected, actual User, quotaAvailable bool) {
}
}
func findAccount(t *testing.T, username string) (*accountsProto.Account, error) {
cl := accountsProto.NewAccountsService("com.owncloud.api.accounts", service.Client())
func findAccount(t *testing.T, username string) (*accountsmsg.Account, error) {
cl := accountssvc.NewAccountsService("com.owncloud.api.accounts", service.Client())
req := &accountsProto.ListAccountsRequest{
req := &accountssvc.ListAccountsRequest{
Query: "preferred_name eq '" + username + "'",
}
res, err := cl.ListAccounts(context.Background(), req)
@@ -498,17 +499,17 @@ func findAccount(t *testing.T, username string) (*accountsProto.Account, error)
}
func deleteAccount(t *testing.T, id string) (*empty.Empty, error) {
cl := accountsProto.NewAccountsService("com.owncloud.api.accounts", service.Client())
cl := accountssvc.NewAccountsService("com.owncloud.api.accounts", service.Client())
req := &accountsProto.DeleteAccountRequest{Id: id}
req := &accountssvc.DeleteAccountRequest{Id: id}
res, err := cl.DeleteAccount(context.Background(), req)
return res, err
}
func deleteGroup(t *testing.T, id string) (*empty.Empty, error) {
cl := accountsProto.NewGroupsService("com.owncloud.api.accounts", service.Client())
cl := accountssvc.NewGroupsService("com.owncloud.api.accounts", service.Client())
req := &accountsProto.DeleteGroupRequest{Id: id}
req := &accountssvc.DeleteGroupRequest{Id: id}
res, err := cl.DeleteGroup(context.Background(), req)
return res, err
}
@@ -518,7 +519,7 @@ func buildRoleServiceMock() settingssvc.RoleService {
AssignRoleToUserFunc: func(ctx context.Context, req *settingssvc.AssignRoleToUserRequest, opts ...client.CallOption) (res *settingssvc.AssignRoleToUserResponse, err error) {
mockedRoleAssignment[req.AccountUuid] = req.RoleId
return &settingssvc.AssignRoleToUserResponse{
Assignment: &settingssvc.UserRoleAssignment{
Assignment: &settingsmsg.UserRoleAssignment{
AccountUuid: req.AccountUuid,
RoleId: req.RoleId,
},
@@ -531,7 +532,7 @@ func buildRoleServiceMock() settingssvc.RoleService {
Id: ssvc.BundleUUIDRoleAdmin,
Settings: []*settingsmsg.Setting{
{
Id: accountsSvc.AccountManagementPermissionID,
Id: accountsServiceExt.AccountManagementPermissionID,
},
},
},
@@ -539,7 +540,7 @@ func buildRoleServiceMock() settingssvc.RoleService {
Id: ssvc.BundleUUIDRoleUser,
Settings: []*settingsmsg.Setting{
{
Id: accountsSvc.SelfManagementPermissionID,
Id: accountsServiceExt.SelfManagementPermissionID,
},
},
},
@@ -571,22 +572,22 @@ func init() {
},
}
var hdlr *accountsSvc.Service
var hdlr *accountsServiceExt.Service
var err error
if hdlr, err = accountsSvc.New(
accountsSvc.Logger(accountsLogging.Configure("accounts", c.Log)),
accountsSvc.Config(c),
accountsSvc.RoleService(buildRoleServiceMock()),
if hdlr, err = accountsServiceExt.New(
accountsServiceExt.Logger(accountsLogging.Configure("accounts", c.Log)),
accountsServiceExt.Config(c),
accountsServiceExt.RoleService(buildRoleServiceMock()),
); err != nil {
log.Fatalf("Could not create new service")
}
err = accountsProto.RegisterAccountsServiceHandler(service.Server(), hdlr)
err = accountssvc.RegisterAccountsServiceHandler(service.Server(), hdlr)
if err != nil {
log.Fatal("could not register the Accounts handler")
}
err = accountsProto.RegisterGroupsServiceHandler(service.Server(), hdlr)
err = accountssvc.RegisterGroupsServiceHandler(service.Server(), hdlr)
if err != nil {
log.Fatal("could not register the Groups handler")
}

View File

@@ -0,0 +1,90 @@
package v1
import (
context "context"
accountsmsg "github.com/owncloud/ocis/protogen/gen/ocis/messages/accounts/v1"
client "go-micro.dev/v4/client"
empty "google.golang.org/protobuf/types/known/emptypb"
)
// MockAccountsService can be used to write tests
/*
To create a mock overwrite the functions of an instance like this:
```go
func mockAccSvc(retErr bool) proto.AccountsService {
if retErr {
return &proto.MockAccountsService{
ListFunc: func(ctx context.Context, in *proto.ListAccountsRequest, opts ...client.CallOption) (out *proto.ListAccountsResponse, err error) {
return nil, fmt.Errorf("error returned by mockAccountsService LIST")
},
}
}
return &proto.MockAccountsService{
ListFunc: func(ctx context.Context, in *proto.ListAccountsRequest, opts ...client.CallOption) (out *proto.ListAccountsResponse, err error) {
return &proto.ListAccountsResponse{
Accounts: []*proto.Account{
{
Id: "yay",
},
},
}, nil
},
}
}
```
*/
type MockAccountsService struct {
ListFunc func(ctx context.Context, in *ListAccountsRequest, opts ...client.CallOption) (*ListAccountsResponse, error)
GetFunc func(ctx context.Context, in *GetAccountRequest, opts ...client.CallOption) (*accountsmsg.Account, error)
CreateFunc func(ctx context.Context, in *CreateAccountRequest, opts ...client.CallOption) (*accountsmsg.Account, error)
UpdateFunc func(ctx context.Context, in *UpdateAccountRequest, opts ...client.CallOption) (*accountsmsg.Account, error)
DeleteFunc func(ctx context.Context, in *DeleteAccountRequest, opts ...client.CallOption) (*empty.Empty, error)
}
// ListAccounts will panic if the function has been called, but not mocked
func (m MockAccountsService) ListAccounts(ctx context.Context, in *ListAccountsRequest, opts ...client.CallOption) (*ListAccountsResponse, error) {
if m.ListFunc != nil {
return m.ListFunc(ctx, in, opts...)
}
panic("ListFunc was called in test but not mocked")
}
// GetAccount will panic if the function has been called, but not mocked
func (m MockAccountsService) GetAccount(ctx context.Context, in *GetAccountRequest, opts ...client.CallOption) (*accountsmsg.Account, error) {
if m.GetFunc != nil {
return m.GetFunc(ctx, in, opts...)
}
panic("GetFunc was called in test but not mocked")
}
// CreateAccount will panic if the function has been called, but not mocked
func (m MockAccountsService) CreateAccount(ctx context.Context, in *CreateAccountRequest, opts ...client.CallOption) (*accountsmsg.Account, error) {
if m.CreateFunc != nil {
return m.CreateFunc(ctx, in, opts...)
}
panic("CreateFunc was called in test but not mocked")
}
// UpdateAccount will panic if the function has been called, but not mocked
func (m MockAccountsService) UpdateAccount(ctx context.Context, in *UpdateAccountRequest, opts ...client.CallOption) (*accountsmsg.Account, error) {
if m.UpdateFunc != nil {
return m.UpdateFunc(ctx, in, opts...)
}
panic("UpdateFunc was called in test but not mocked")
}
// DeleteAccount will panic if the function has been called, but not mocked
func (m MockAccountsService) DeleteAccount(ctx context.Context, in *DeleteAccountRequest, opts ...client.CallOption) (*empty.Empty, error) {
if m.DeleteFunc != nil {
return m.DeleteFunc(ctx, in, opts...)
}
panic("DeleteFunc was called in test but not mocked")
}

View File

@@ -0,0 +1,186 @@
package v1
import (
"context"
"go-micro.dev/v4/client"
"google.golang.org/protobuf/types/known/emptypb"
)
// MockBundleService can be used to write tests against the bundle service.
/*
To create a mock overwrite the functions of an instance like this:
```go
func mockBundleSvc(returnErr bool) proto.BundleService {
if returnErr {
return &proto.MockBundleService{
ListBundlesFunc: func(ctx context.Context, in *proto.ListBundlesRequest, opts ...client.CallOption) (out *proto.ListBundlesResponse, err error) {
return nil, fmt.Errorf("error returned by mockBundleSvc LIST")
},
}
}
return &proto.MockBundleService{
ListBundlesFunc: func(ctx context.Context, in *proto.ListBundlesRequest, opts ...client.CallOption) (out *proto.ListBundlesResponse, err error) {
return &proto.ListBundlesResponse{
Bundles: []*proto.Bundle{
{
Id: "hello-there",
},
},
}, nil
},
}
}
```
*/
type MockBundleService struct {
ListBundlesFunc func(ctx context.Context, req *ListBundlesRequest, opts ...client.CallOption) (*ListBundlesResponse, error)
GetBundleFunc func(ctx context.Context, req *GetBundleRequest, opts ...client.CallOption) (*GetBundleResponse, error)
SaveBundleFunc func(ctx context.Context, req *SaveBundleRequest, opts ...client.CallOption) (*SaveBundleResponse, error)
AddSettingToBundleFunc func(ctx context.Context, req *AddSettingToBundleRequest, opts ...client.CallOption) (*AddSettingToBundleResponse, error)
RemoveSettingFromBundleFunc func(ctx context.Context, req *RemoveSettingFromBundleRequest, opts ...client.CallOption) (*emptypb.Empty, error)
}
// ListBundles will panic if the function has been called, but not mocked
func (m MockBundleService) ListBundles(ctx context.Context, req *ListBundlesRequest, opts ...client.CallOption) (*ListBundlesResponse, error) {
if m.ListBundlesFunc != nil {
return m.ListBundlesFunc(ctx, req, opts...)
}
panic("ListBundlesFunc was called in test but not mocked")
}
// GetBundle will panic if the function has been called, but not mocked
func (m MockBundleService) GetBundle(ctx context.Context, req *GetBundleRequest, opts ...client.CallOption) (*GetBundleResponse, error) {
if m.GetBundleFunc != nil {
return m.GetBundleFunc(ctx, req, opts...)
}
panic("GetBundleFunc was called in test but not mocked")
}
// SaveBundle will panic if the function has been called, but not mocked
func (m MockBundleService) SaveBundle(ctx context.Context, req *SaveBundleRequest, opts ...client.CallOption) (*SaveBundleResponse, error) {
if m.SaveBundleFunc != nil {
return m.SaveBundleFunc(ctx, req, opts...)
}
panic("SaveBundleFunc was called in test but not mocked")
}
// AddSettingToBundle will panic if the function has been called, but not mocked
func (m MockBundleService) AddSettingToBundle(ctx context.Context, req *AddSettingToBundleRequest, opts ...client.CallOption) (*AddSettingToBundleResponse, error) {
if m.AddSettingToBundleFunc != nil {
return m.AddSettingToBundleFunc(ctx, req, opts...)
}
panic("AddSettingToBundleFunc was called in test but not mocked")
}
// RemoveSettingFromBundle will panic if the function has been called, but not mocked
func (m MockBundleService) RemoveSettingFromBundle(ctx context.Context, req *RemoveSettingFromBundleRequest, opts ...client.CallOption) (*emptypb.Empty, error) {
if m.RemoveSettingFromBundleFunc != nil {
return m.RemoveSettingFromBundleFunc(ctx, req, opts...)
}
panic("RemoveSettingFromBundleFunc was called in test but not mocked")
}
// MockValueService can be used to write tests against the value service.
type MockValueService struct {
ListValuesFunc func(ctx context.Context, req *ListValuesRequest, opts ...client.CallOption) (*ListValuesResponse, error)
GetValueFunc func(ctx context.Context, req *GetValueRequest, opts ...client.CallOption) (*GetValueResponse, error)
GetValueByUniqueIdentifiersFunc func(ctx context.Context, req *GetValueByUniqueIdentifiersRequest, opts ...client.CallOption) (*GetValueResponse, error)
SaveValueFunc func(ctx context.Context, req *SaveValueRequest, opts ...client.CallOption) (*SaveValueResponse, error)
}
// ListValues will panic if the function has been called, but not mocked
func (m MockValueService) ListValues(ctx context.Context, req *ListValuesRequest, opts ...client.CallOption) (*ListValuesResponse, error) {
if m.ListValuesFunc != nil {
return m.ListValuesFunc(ctx, req, opts...)
}
panic("ListValuesFunc was called in test but not mocked")
}
// GetValue will panic if the function has been called, but not mocked
func (m MockValueService) GetValue(ctx context.Context, req *GetValueRequest, opts ...client.CallOption) (*GetValueResponse, error) {
if m.GetValueFunc != nil {
return m.GetValueFunc(ctx, req, opts...)
}
panic("GetValueFunc was called in test but not mocked")
}
// GetValueByUniqueIdentifiers will panic if the function has been called, but not mocked
func (m MockValueService) GetValueByUniqueIdentifiers(ctx context.Context, req *GetValueByUniqueIdentifiersRequest, opts ...client.CallOption) (*GetValueResponse, error) {
if m.GetValueByUniqueIdentifiersFunc != nil {
return m.GetValueByUniqueIdentifiersFunc(ctx, req, opts...)
}
panic("GetValueByUniqueIdentifiersFunc was called in test but not mocked")
}
// SaveValue will panic if the function has been called, but not mocked
func (m MockValueService) SaveValue(ctx context.Context, req *SaveValueRequest, opts ...client.CallOption) (*SaveValueResponse, error) {
if m.SaveValueFunc != nil {
return m.SaveValueFunc(ctx, req, opts...)
}
panic("SaveValueFunc was called in test but not mocked")
}
// MockRoleService will panic if the function has been called, but not mocked
type MockRoleService struct {
ListRolesFunc func(ctx context.Context, req *ListBundlesRequest, opts ...client.CallOption) (*ListBundlesResponse, error)
ListRoleAssignmentsFunc func(ctx context.Context, req *ListRoleAssignmentsRequest, opts ...client.CallOption) (*ListRoleAssignmentsResponse, error)
AssignRoleToUserFunc func(ctx context.Context, req *AssignRoleToUserRequest, opts ...client.CallOption) (*AssignRoleToUserResponse, error)
RemoveRoleFromUserFunc func(ctx context.Context, req *RemoveRoleFromUserRequest, opts ...client.CallOption) (*emptypb.Empty, error)
}
// ListRoles will panic if the function has been called, but not mocked
func (m MockRoleService) ListRoles(ctx context.Context, req *ListBundlesRequest, opts ...client.CallOption) (*ListBundlesResponse, error) {
if m.ListRolesFunc != nil {
return m.ListRolesFunc(ctx, req, opts...)
}
panic("ListRolesFunc was called in test but not mocked")
}
// ListRoleAssignments will panic if the function has been called, but not mocked
func (m MockRoleService) ListRoleAssignments(ctx context.Context, req *ListRoleAssignmentsRequest, opts ...client.CallOption) (*ListRoleAssignmentsResponse, error) {
if m.ListRoleAssignmentsFunc != nil {
return m.ListRoleAssignmentsFunc(ctx, req, opts...)
}
panic("ListRoleAssignmentsFunc was called in test but not mocked")
}
// AssignRoleToUser will panic if the function has been called, but not mocked
func (m MockRoleService) AssignRoleToUser(ctx context.Context, req *AssignRoleToUserRequest, opts ...client.CallOption) (*AssignRoleToUserResponse, error) {
if m.AssignRoleToUserFunc != nil {
return m.AssignRoleToUserFunc(ctx, req, opts...)
}
panic("AssignRoleToUserFunc was called in test but not mocked")
}
// RemoveRoleFromUser will panic if the function has been called, but not mocked
func (m MockRoleService) RemoveRoleFromUser(ctx context.Context, req *RemoveRoleFromUserRequest, opts ...client.CallOption) (*emptypb.Empty, error) {
if m.RemoveRoleFromUserFunc != nil {
return m.RemoveRoleFromUserFunc(ctx, req, opts...)
}
panic("RemoveRoleFromUserFunc was called in test but not mocked")
}
// MockPermissionService will panic if the function has been called, but not mocked
type MockPermissionService struct {
ListPermissionsByResourceFunc func(ctx context.Context, req *ListPermissionsByResourceRequest, opts ...client.CallOption) (*ListPermissionsByResourceResponse, error)
GetPermissionByIDFunc func(ctx context.Context, req *GetPermissionByIDRequest, opts ...client.CallOption) (*GetPermissionByIDResponse, error)
}
// ListPermissionsByResource will panic if the function has been called, but not mocked
func (m MockPermissionService) ListPermissionsByResource(ctx context.Context, req *ListPermissionsByResourceRequest, opts ...client.CallOption) (*ListPermissionsByResourceResponse, error) {
if m.ListPermissionsByResourceFunc != nil {
return m.ListPermissionsByResourceFunc(ctx, req, opts...)
}
panic("ListPermissionsByResourceFunc was called in test but not mocked")
}
// GetPermissionByID will panic if the function has been called, but not mocked
func (m MockPermissionService) GetPermissionByID(ctx context.Context, req *GetPermissionByIDRequest, opts ...client.CallOption) (*GetPermissionByIDResponse, error) {
if m.GetPermissionByIDFunc != nil {
return m.GetPermissionByIDFunc(ctx, req, opts...)
}
panic("GetPermissionByIDFunc was called in test but not mocked")
}

View File

@@ -9,8 +9,9 @@ import (
userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
revactx "github.com/cs3org/reva/pkg/ctx"
"github.com/owncloud/ocis/accounts/pkg/proto/v0"
"github.com/owncloud/ocis/ocis-pkg/oidc"
accountsmsg "github.com/owncloud/ocis/protogen/gen/ocis/messages/accounts/v1"
accountssvc "github.com/owncloud/ocis/protogen/gen/ocis/services/accounts/v1"
"github.com/owncloud/ocis/proxy/pkg/config"
"go-micro.dev/v4/client"
)
@@ -110,18 +111,18 @@ func TestMigrationSelector(t *testing.T) {
}
}
func mockAccSvc(retErr bool) proto.AccountsService {
func mockAccSvc(retErr bool) accountssvc.AccountsService {
if retErr {
return &proto.MockAccountsService{
GetFunc: func(ctx context.Context, in *proto.GetAccountRequest, opts ...client.CallOption) (record *proto.Account, err error) {
return &accountssvc.MockAccountsService{
GetFunc: func(ctx context.Context, in *accountssvc.GetAccountRequest, opts ...client.CallOption) (record *accountsmsg.Account, err error) {
return nil, fmt.Errorf("error returned by mockAccountsService GET")
},
}
}
return &proto.MockAccountsService{
GetFunc: func(ctx context.Context, in *proto.GetAccountRequest, opts ...client.CallOption) (record *proto.Account, err error) {
return &proto.Account{}, nil
return &accountssvc.MockAccountsService{
GetFunc: func(ctx context.Context, in *accountssvc.GetAccountRequest, opts ...client.CallOption) (record *accountsmsg.Account, err error) {
return &accountsmsg.Account{}, nil
},
}

View File

@@ -6,17 +6,18 @@ import (
userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
"github.com/cs3org/reva/pkg/token/manager/jwt"
accounts "github.com/owncloud/ocis/accounts/pkg/proto/v0"
"github.com/owncloud/ocis/ocis-pkg/log"
"github.com/owncloud/ocis/ocis-pkg/oidc"
accountsmsg "github.com/owncloud/ocis/protogen/gen/ocis/messages/accounts/v1"
settingsmsg "github.com/owncloud/ocis/protogen/gen/ocis/messages/settings/v1"
accountssvc "github.com/owncloud/ocis/protogen/gen/ocis/services/accounts/v1"
settingssvc "github.com/owncloud/ocis/protogen/gen/ocis/services/settings/v1"
"github.com/rs/zerolog"
"github.com/stretchr/testify/assert"
"go-micro.dev/v4/client"
)
var mockAccResp = []*accounts.Account{
var mockAccResp = []*accountsmsg.Account{
{
Id: "1234",
AccountEnabled: true,
@@ -26,7 +27,7 @@ var mockAccResp = []*accounts.Account{
GidNumber: 2,
Mail: "foo@example.org",
OnPremisesSamAccountName: "samaccount",
MemberOf: []*accounts.Group{
MemberOf: []*accountsmsg.Group{
{OnPremisesSamAccountName: "g1"},
{OnPremisesSamAccountName: "g2"},
},
@@ -64,7 +65,7 @@ func TestGetUserByClaimsFound(t *testing.T) {
}
func TestGetUserByClaimsNotFound(t *testing.T) {
accBackend := newAccountsBackend([]*accounts.Account{}, expectedRoles)
accBackend := newAccountsBackend([]*accountsmsg.Account{}, expectedRoles)
u, _, err := accBackend.GetUserByClaims(context.Background(), "mail", "foo@example.com", true)
@@ -74,7 +75,7 @@ func TestGetUserByClaimsNotFound(t *testing.T) {
}
func TestGetUserByClaimsInvalidClaim(t *testing.T) {
accBackend := newAccountsBackend([]*accounts.Account{}, expectedRoles)
accBackend := newAccountsBackend([]*accountsmsg.Account{}, expectedRoles)
u, _, err := accBackend.GetUserByClaims(context.Background(), "invalidClaimName", "efwfwfwfe", true)
assert.Nil(t, u)
@@ -82,7 +83,7 @@ func TestGetUserByClaimsInvalidClaim(t *testing.T) {
}
func TestGetUserByClaimsDisabledAccount(t *testing.T) {
accBackend := newAccountsBackend([]*accounts.Account{{AccountEnabled: false}}, expectedRoles)
accBackend := newAccountsBackend([]*accountsmsg.Account{{AccountEnabled: false}}, expectedRoles)
u, _, err := accBackend.GetUserByClaims(context.Background(), "mail", "foo@example.com", true)
assert.Nil(t, u)
@@ -100,7 +101,7 @@ func TestAuthenticate(t *testing.T) {
}
func TestAuthenticateFailed(t *testing.T) {
accBackend := newAccountsBackend([]*accounts.Account{}, expectedRoles)
accBackend := newAccountsBackend([]*accountsmsg.Account{}, expectedRoles)
u, _, err := accBackend.Authenticate(context.Background(), "foo", "secret")
assert.Nil(t, u)
@@ -109,7 +110,7 @@ func TestAuthenticateFailed(t *testing.T) {
func TestCreateUserFromClaims(t *testing.T) {
exp := mockAccResp[0]
accBackend := newAccountsBackend([]*accounts.Account{}, expectedRoles)
accBackend := newAccountsBackend([]*accountsmsg.Account{}, expectedRoles)
act, _ := accBackend.CreateUserFromClaims(context.Background(), map[string]interface{}{
oidc.Name: mockAccResp[0].DisplayName,
oidc.PreferredUsername: mockAccResp[0].OnPremisesSamAccountName,
@@ -127,11 +128,11 @@ func TestCreateUserFromClaims(t *testing.T) {
}
func TestGetUserGroupsUnimplemented(t *testing.T) {
accBackend := newAccountsBackend([]*accounts.Account{}, expectedRoles)
accBackend := newAccountsBackend([]*accountsmsg.Account{}, expectedRoles)
assert.Panics(t, func() { accBackend.GetUserGroups(context.Background(), "foo") })
}
func assertUserMatchesAccount(t *testing.T, exp *accounts.Account, act *userv1beta1.User) {
func assertUserMatchesAccount(t *testing.T, exp *accountsmsg.Account, act *userv1beta1.User) {
// User
assert.NotNil(t, act.Id)
assert.Equal(t, exp.Id, act.Id.OpaqueId)
@@ -151,7 +152,7 @@ func assertUserMatchesAccount(t *testing.T, exp *accounts.Account, act *userv1be
assert.Equal(t, int64(2), act.GidNumber)
}
func newAccountsBackend(mockAccounts []*accounts.Account, mockRoles []*settingsmsg.UserRoleAssignment) UserBackend {
func newAccountsBackend(mockAccounts []*accountsmsg.Account, mockRoles []*settingsmsg.UserRoleAssignment) UserBackend {
accSvc, roleSvc := getAccountService(mockAccounts, nil), getRoleService(mockRoles, nil)
tokenManager, _ := jwt.New(map[string]interface{}{
"secret": "change-me",
@@ -162,12 +163,12 @@ func newAccountsBackend(mockAccounts []*accounts.Account, mockRoles []*settingsm
return accBackend
}
func getAccountService(expectedResponse []*accounts.Account, err error) *accounts.MockAccountsService {
return &accounts.MockAccountsService{
ListFunc: func(ctx context.Context, in *accounts.ListAccountsRequest, opts ...client.CallOption) (*accounts.ListAccountsResponse, error) {
return &accounts.ListAccountsResponse{Accounts: expectedResponse}, err
func getAccountService(expectedResponse []*accountsmsg.Account, err error) *accountssvc.MockAccountsService {
return &accountssvc.MockAccountsService{
ListFunc: func(ctx context.Context, in *accountssvc.ListAccountsRequest, opts ...client.CallOption) (*accountssvc.ListAccountsResponse, error) {
return &accountssvc.ListAccountsResponse{Accounts: expectedResponse}, err
},
CreateFunc: func(ctx context.Context, in *accounts.CreateAccountRequest, opts ...client.CallOption) (*accounts.Account, error) {
CreateFunc: func(ctx context.Context, in *accountssvc.CreateAccountRequest, opts ...client.CallOption) (*accountsmsg.Account, error) {
a := in.Account
a.Id = "1234"
return a, nil