gopg_mock

package module
v0.0.0-...-58f6829 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2019 License: MIT Imports: 8 Imported by: 0

README

Go-PG Mock

This package is Proof of Concept that if we use https://github.com/go-pg/pg for our DB connection, it still can be tested. Since go-pg package already use abstraction for their DB query (using orm.DB interface), we can create new struct that implement it.

At the same time, instead doing real query we can compare what queries we want to mock and what results will be.

Usage

See in directory examples.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Formatter

type Formatter struct {
}

Formatter implements orm.Formatter

func (*Formatter) FormatQuery

func (f *Formatter) FormatQuery(b []byte, query string, params ...interface{}) []byte

type OrmResult

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

OrmResult struct to implements orm.Result

func NewResult

func NewResult(rowAffected, rowReturned int, model interface{}) *OrmResult

NewResult implements orm.Result in go-pg package

func (*OrmResult) Model

func (o *OrmResult) Model() orm.Model

func (*OrmResult) RowsAffected

func (o *OrmResult) RowsAffected() int

func (*OrmResult) RowsReturned

func (o *OrmResult) RowsReturned() int

type SQLMock

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

func NewGoPGDBTest

func NewGoPGDBTest() (conn orm.DB, mock *SQLMock, err error)

NewGoPGDBTest returns method that already implements orm.DB and mock instance to mocking arguments and results.

func (*SQLMock) ExpectExec

func (sqlMock *SQLMock) ExpectExec(query string) *SQLMock

func (*SQLMock) ExpectQuery

func (sqlMock *SQLMock) ExpectQuery(query string) *SQLMock

func (*SQLMock) FlushAll

func (sqlMock *SQLMock) FlushAll()

func (*SQLMock) Returns

func (sqlMock *SQLMock) Returns(result *OrmResult, err error)

func (*SQLMock) WithArgs

func (sqlMock *SQLMock) WithArgs(params ...interface{}) *SQLMock

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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