Documentation ¶
Overview ¶
Package user provides implementations for Interface for the database user repository. All consumers should be using service.DataStore and not the naked repositories!
Index ¶
- Variables
- type Bolt
- type Interface
- type InterfaceMock
- func (mock *InterfaceMock) AddUser(user store.User, pwd string, ignoreIfExists bool) (string, error)
- func (mock *InterfaceMock) AddUserCalls() []struct{ ... }
- func (mock *InterfaceMock) GetPasswordHash(email string) (string, error)
- func (mock *InterfaceMock) GetPasswordHashCalls() []struct{ ... }
- func (mock *InterfaceMock) GetUser(id string) (store.User, error)
- func (mock *InterfaceMock) GetUserCalls() []struct{ ... }
- type Postgres
Constants ¶
This section is empty.
Variables ¶
var (
ErrNotFound = errors.New("user not found")
)
Store-defined errors
Functions ¶
This section is empty.
Types ¶
type Bolt ¶
type Bolt struct {
// contains filtered or unexported fields
}
Bolt implements Interface to contain, fetch and update users there is one top-level bucket: - users with the k:v pair as userID:user - user passwords with the k:v pair as userID:password
func NewBoltStorage ¶
NewBoltStorage creates buckets and initial data processing
func (*Bolt) GetPasswordHash ¶
GetPasswordHash of the user by its email
type Interface ¶
type Interface interface { GetUser(id string) (u store.User, err error) GetPasswordHash(email string) (pwd string, err error) AddUser(user store.User, pwd string, ignoreIfExists bool) (id string, err error) }
Interface defines methods to repository, and fetch models
type InterfaceMock ¶
type InterfaceMock struct { // AddUserFunc mocks the AddUser method. AddUserFunc func(user store.User, pwd string, ignoreIfExists bool) (string, error) // GetPasswordHashFunc mocks the GetPasswordHash method. GetPasswordHashFunc func(email string) (string, error) // GetUserFunc mocks the GetUser method. GetUserFunc func(id string) (store.User, error) // contains filtered or unexported fields }
InterfaceMock is a mock implementation of Interface.
func TestSomethingThatUsesInterface(t *testing.T) { // make and configure a mocked Interface mockedInterface := &InterfaceMock{ AddUserFunc: func(user store.User, pwd string, ignoreIfExists bool) (string, error) { panic("mock out the AddUser method") }, GetPasswordHashFunc: func(email string) (string, error) { panic("mock out the GetPasswordHash method") }, GetUserFunc: func(id string) (store.User, error) { panic("mock out the GetUser method") }, } // use mockedInterface in code that requires Interface // and then make assertions. }
func (*InterfaceMock) AddUser ¶
func (mock *InterfaceMock) AddUser(user store.User, pwd string, ignoreIfExists bool) (string, error)
AddUser calls AddUserFunc.
func (*InterfaceMock) AddUserCalls ¶
func (mock *InterfaceMock) AddUserCalls() []struct { User store.User Pwd string IgnoreIfExists bool }
AddUserCalls gets all the calls that were made to AddUser. Check the length with:
len(mockedInterface.AddUserCalls())
func (*InterfaceMock) GetPasswordHash ¶
func (mock *InterfaceMock) GetPasswordHash(email string) (string, error)
GetPasswordHash calls GetPasswordHashFunc.
func (*InterfaceMock) GetPasswordHashCalls ¶
func (mock *InterfaceMock) GetPasswordHashCalls() []struct { Email string }
GetPasswordHashCalls gets all the calls that were made to GetPasswordHash. Check the length with:
len(mockedInterface.GetPasswordHashCalls())
func (*InterfaceMock) GetUser ¶
func (mock *InterfaceMock) GetUser(id string) (store.User, error)
GetUser calls GetUserFunc.
func (*InterfaceMock) GetUserCalls ¶
func (mock *InterfaceMock) GetUserCalls() []struct { ID string }
GetUserCalls gets all the calls that were made to GetUser. Check the length with:
len(mockedInterface.GetUserCalls())
type Postgres ¶
type Postgres struct {
// contains filtered or unexported fields
}
Postgres implements Interface with postgres queries
func NewPostgres ¶
NewPostgres returns the new instance of Postgres
func (*Postgres) GetPasswordHash ¶
GetPasswordHash of user by its email