mirror of
https://github.com/mainflux/mainflux.git
synced 2025-05-01 13:48:56 +08:00

Setup top-level glide dependencies file. Migrated all of the manager service code into this repository. Fixed docker build procedure. Extracted executable to the top-level. Signed-off-by: Dejan Mijic <dejan@mainflux.com>
45 lines
841 B
Go
45 lines
841 B
Go
package mocks
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/mainflux/mainflux/manager"
|
|
)
|
|
|
|
var _ manager.UserRepository = (*userRepositoryMock)(nil)
|
|
|
|
type userRepositoryMock struct {
|
|
mu sync.Mutex
|
|
users map[string]manager.User
|
|
}
|
|
|
|
// NewUserRepository creates in-memory user repository.
|
|
func NewUserRepository() manager.UserRepository {
|
|
return &userRepositoryMock{
|
|
users: make(map[string]manager.User),
|
|
}
|
|
}
|
|
|
|
func (ur *userRepositoryMock) Save(user manager.User) error {
|
|
ur.mu.Lock()
|
|
defer ur.mu.Unlock()
|
|
|
|
if _, ok := ur.users[user.Email]; ok {
|
|
return manager.ErrConflict
|
|
}
|
|
|
|
ur.users[user.Email] = user
|
|
return nil
|
|
}
|
|
|
|
func (ur *userRepositoryMock) One(email string) (manager.User, error) {
|
|
ur.mu.Lock()
|
|
defer ur.mu.Unlock()
|
|
|
|
if val, ok := ur.users[email]; ok {
|
|
return val, nil
|
|
}
|
|
|
|
return manager.User{}, manager.ErrInvalidCredentials
|
|
}
|