diff --git a/pkg/proto/v0/accounts.pb.micro_test.go b/pkg/proto/v0/accounts.pb.micro_test.go index 5e8e810..596d5e5 100644 --- a/pkg/proto/v0/accounts.pb.micro_test.go +++ b/pkg/proto/v0/accounts.pb.micro_test.go @@ -4,6 +4,7 @@ import ( context "context" "errors" "fmt" + "github.com/micro/go-micro/v2/client" "google.golang.org/genproto/protobuf/field_mask" "google.golang.org/protobuf/types/known/timestamppb" "log" @@ -168,6 +169,8 @@ func init() { log.Fatalf("Could not create new service") } + hdlr.Client = mockClient{} + err = proto.RegisterAccountsServiceHandler(service.Server(), hdlr) if err != nil { log.Fatal("could not register the Accounts handler") @@ -488,7 +491,7 @@ func TestUpdateAccount(t *testing.T) { GidNumber: 1000, // No email validation // https://github.com/owncloud/ocis-accounts/issues/77 - Mail: "1.2@3.c_@", + Mail: "1.2@3.c_@", }, }, } @@ -1169,3 +1172,37 @@ func TestAccountUpdateReadOnlyField(t *testing.T) { cleanUp(t) } + +type mockClient struct{} + +func (c mockClient) Init(option ...client.Option) error { + return nil +} + +func (c mockClient) Options() client.Options { + return client.Options{} +} + +func (c mockClient) NewMessage(topic string, msg interface{}, opts ...client.MessageOption) client.Message { + return nil +} + +func (c mockClient) NewRequest(service, endpoint string, req interface{}, reqOpts ...client.RequestOption) client.Request { + return nil +} + +func (c mockClient) Call(ctx context.Context, req client.Request, rsp interface{}, opts ...client.CallOption) error { + return nil +} + +func (c mockClient) Stream(ctx context.Context, req client.Request, opts ...client.CallOption) (client.Stream, error) { + return nil, nil +} + +func (c mockClient) Publish(ctx context.Context, msg client.Message, opts ...client.PublishOption) error { + return nil +} + +func (c mockClient) String() string { + return "ClientMock" +} diff --git a/pkg/service/v0/accounts.go b/pkg/service/v0/accounts.go index c64991d..c00e9bd 100644 --- a/pkg/service/v0/accounts.go +++ b/pkg/service/v0/accounts.go @@ -19,7 +19,6 @@ import ( "github.com/blevesearch/bleve" "github.com/gofrs/uuid" "github.com/golang/protobuf/ptypes/empty" - mgrpc "github.com/micro/go-micro/v2/client/grpc" merrors "github.com/micro/go-micro/v2/errors" "github.com/owncloud/ocis-accounts/pkg/proto/v0" "github.com/owncloud/ocis-accounts/pkg/provider" @@ -324,7 +323,7 @@ func (s Service) CreateAccount(c context.Context, in *proto.CreateAccountRequest } // TODO: All users for now as create Account request does not have any role field - rs := settings.NewRoleService("com.owncloud.api.settings", mgrpc.NewClient()) + rs := settings.NewRoleService("com.owncloud.api.settings", s.Client) _, err = rs.AssignRoleToUser(c, &settings.AssignRoleToUserRequest{ AccountUuid: acc.Id, RoleId: settings_svc.BundleUUIDRoleUser, diff --git a/pkg/service/v0/service.go b/pkg/service/v0/service.go index 2660450..8c8eaee 100644 --- a/pkg/service/v0/service.go +++ b/pkg/service/v0/service.go @@ -4,6 +4,8 @@ import ( "encoding/json" "errors" "fmt" + mclient "github.com/micro/go-micro/v2/client" + mgrpc "github.com/micro/go-micro/v2/client/grpc" "io/ioutil" "os" "path/filepath" @@ -287,6 +289,7 @@ func New(opts ...Option) (s *Service, err error) { id: cfg.GRPC.Namespace + "." + cfg.Server.Name, log: logger, Config: cfg, + Client: mgrpc.NewClient(), } indexDir := filepath.Join(cfg.Server.AccountsDataPath, "index.bleve") @@ -315,6 +318,7 @@ type Service struct { log log.Logger Config *config.Config index bleve.Index + Client mclient.Client } func cleanupID(id string) (string, error) {