dbtest

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cleanup

func Cleanup(t *testing.T, database db.DB)

Cleanup cleans up after a test.

func Setup

func Setup(t *testing.T) db.DB

Setup sets up a new in-memory database.

Types

type ByID

type ByID []*domain.User

ByID implements sort.Interface for []*domain.User based on the ID field.

func (ByID) Len

func (a ByID) Len() int

func (ByID) Less

func (a ByID) Less(i, j int) bool

func (ByID) Swap

func (a ByID) Swap(i, j int)

type InMemoryDB

type InMemoryDB struct {
	// contains filtered or unexported fields
}

InMemoryDB is an in-memory implementation of DB. This is mainly useful for testing.

func NewInMemoryDB

func NewInMemoryDB() *InMemoryDB

NewInMemoryDB creates a new in-memory DB.

func (*InMemoryDB) Close

func (database *InMemoryDB) Close() error

Close is a no-op, but present so that we implement the DB interface.

func (*InMemoryDB) CreateUser

func (database *InMemoryDB) CreateUser(_ context.Context, user *domain.User) (int, error)

CreateUser stores the provided user.

func (*InMemoryDB) Ping

func (database *InMemoryDB) Ping(ctx context.Context) error

Ping ensures this database client can reach the database.

func (*InMemoryDB) ReadUserByID

func (database *InMemoryDB) ReadUserByID(_ context.Context, id int) (*domain.User, error)

ReadUserByID return the stored user corresponding to the provided ID.

func (*InMemoryDB) ReadUsers

func (database *InMemoryDB) ReadUsers(_ context.Context) ([]*domain.User, error)

ReadUsers returns all stored users.

Jump to

Keyboard shortcuts

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