1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-05-02 22:17:10 +08:00
Dejan Mijic 481b5b230d Validate incoming requests
All validation has been moved to the API resources layer, i.e. the
domain objects provide validation method, but the service itself assumes
no corrupted values are passed to it.

Signed-off-by: Dejan Mijic <dejan@mainflux.com>
2017-10-01 01:12:06 +02:00

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.ErrUnauthorizedAccess
}