test

package
v0.0.0-...-39e06ca Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDatabaseWithMockConnection

func NewDatabaseWithMockConnection(t *testing.T) (db.Database, sqlmock.Sqlmock, func())

NewDatabaseWithMockConnection creates a real db.Database instance with mocked driver using github.com/DATA-DOG/go-sqlmock

Types

type MockDatabase

type MockDatabase struct {

	// GetConnection
	GetConnectionReturn db.Connection

	// Close
	CloseCalled bool

	// CreateOne
	CreateOneCommand    string
	CreateOneArgs       []interface{}
	CreateOneQuery      string
	CreateOneDestWriter func([]interface{})
	CreateOneError      db.Error

	// LookupOne
	LookupOneQuery      string
	LookupOneArgs       []interface{}
	LookupOneDestWriter func([]interface{})
	LookupOneError      db.Error

	// UpdateOne
	UpdateOneID         interface{}
	UpdateOneCommand    string
	UpdateOneArgs       []interface{}
	UpdateOneQuery      string
	UpdateOneDestWriter func([]interface{})
	UpdateOneError      db.Error

	// DeleteOne
	DeleteOneID         interface{}
	DeleteOneCommand    string
	DeleteOneQuery      string
	DeleteOneDestWriter func([]interface{})
	DeleteOneError      db.Error
}

MockDatabase is a test friendly implementation of db.Database Use this struct to mock out the basic CRUD methods bound to db.Database. To test transactions or mock out the underlying db.Connection, use NewDatabaseWithMockConnection and github.com/DATA-DOG/go-sqlmock methods

func (*MockDatabase) Close

func (database *MockDatabase) Close()

Close the database handle gracefully

func (*MockDatabase) CreateOne

func (database *MockDatabase) CreateOne(command string, args []interface{}, query string, dest []interface{}) db.Error

CreateOne row in DB

func (*MockDatabase) DeleteOne

func (database *MockDatabase) DeleteOne(id interface{}, deleteCommand string, query string, dest []interface{}) db.Error

DeleteOne row in DB

func (*MockDatabase) GetConnection

func (database *MockDatabase) GetConnection() db.Connection

GetConnection to run database commands directly

func (*MockDatabase) LookupOne

func (database *MockDatabase) LookupOne(query string, args []interface{}, dest []interface{}) db.Error

LookupOne row in DB

func (*MockDatabase) UpdateOne

func (database *MockDatabase) UpdateOne(id interface{}, updateCommand string, updateArgs []interface{}, query string, dest []interface{}) db.Error

UpdateOne row in DB

func (*MockDatabase) WithTransaction

func (database *MockDatabase) WithTransaction(wrapped func(db.Connection) db.Error) (txExecError db.Error)

WithTransaction creates a new transaction and handles rollback/commit based on the error object returned by the wrapped code

Jump to

Keyboard shortcuts

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