2018-08-26 19:15:48 +08:00
|
|
|
//
|
|
|
|
// Copyright (c) 2018
|
|
|
|
// Mainflux
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
//
|
|
|
|
|
2018-05-11 05:53:25 +08:00
|
|
|
package mocks
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/mainflux/mainflux"
|
|
|
|
"github.com/mainflux/mainflux/users"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ mainflux.UsersServiceClient = (*usersServiceMock)(nil)
|
|
|
|
|
|
|
|
type usersServiceMock struct {
|
|
|
|
users map[string]string
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewUsersService creates mock of users service.
|
|
|
|
func NewUsersService(users map[string]string) mainflux.UsersServiceClient {
|
|
|
|
return &usersServiceMock{users}
|
|
|
|
}
|
|
|
|
|
2018-05-21 18:51:46 +08:00
|
|
|
func (svc usersServiceMock) Identify(ctx context.Context, in *mainflux.Token, opts ...grpc.CallOption) (*mainflux.UserID, error) {
|
2018-05-11 05:53:25 +08:00
|
|
|
if id, ok := svc.users[in.Value]; ok {
|
2018-05-21 18:51:46 +08:00
|
|
|
return &mainflux.UserID{Value: id}, nil
|
2018-05-11 05:53:25 +08:00
|
|
|
}
|
|
|
|
return nil, users.ErrUnauthorizedAccess
|
|
|
|
}
|