user

package
v0.0.0-...-19f3120 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2020 License: MIT Imports: 10 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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

func NewBoltStorage(fileName string, options bolt.Options) (*Bolt, error)

NewBoltStorage creates buckets and initial data processing

func (*Bolt) AddUser

func (b *Bolt) AddUser(user store.User, pwd string, ignoreIfExists bool) (string, error)

AddUser to the storage

func (*Bolt) GetPasswordHash

func (b *Bolt) GetPasswordHash(id string) (pwd string, err error)

GetPasswordHash of the user by its email

func (*Bolt) GetUser

func (b *Bolt) GetUser(id string) (store.User, error)

GetUser by its id

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

func NewPostgres(connPool *pgx.ConnPool, connConf pgx.ConnConfig) (*Postgres, error)

NewPostgres returns the new instance of Postgres

func (*Postgres) AddUser

func (p *Postgres) AddUser(u store.User, pwd string, ignoreIfExists bool) (id string, err error)

AddUser to the database

func (*Postgres) GetPasswordHash

func (p *Postgres) GetPasswordHash(id string) (pwd string, err error)

GetPasswordHash of user by its email

func (*Postgres) GetUser

func (p *Postgres) GetUser(id string) (u store.User, err error)

GetUser from the database by its ID

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL