test

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2021 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// The header to be expected to be received from the API.
	JSONHeader = "application/json; charset=utf-8"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DBAny

type DBAny struct{}

Any for mock args.

func (DBAny) Match

func (a DBAny) Match(v driver.Value) bool

Match satisfies sqlmock.Argument interface for any arg.

type DBAnyJSONMessage

type DBAnyJSONMessage struct{}

Any string for mock string args.

func (DBAnyJSONMessage) Match

func (a DBAnyJSONMessage) Match(v driver.Value) bool

Match satisfies sqlmock.Argument interface for any json raw messages.

type DBAnyString

type DBAnyString struct{}

Any string for mock string args.

func (DBAnyString) Match

func (a DBAnyString) Match(v driver.Value) bool

Match satisfies sqlmock.Argument interface for any strings.

type DBSuite

type DBSuite struct {
	suite.Suite
	DB     *sqlx.DB
	Driver *mocks.Driver
	Mock   sqlMock.Sqlmock
	Logger *bytes.Buffer
	// contains filtered or unexported fields
}

HandlerSuite represents the suite of testing methods for controllers.

func NewDBSuite

func NewDBSuite(t *testing.T) DBSuite

NewDBSuite

New recorder for testing controllers, initialises gin & sets gin mode.

func (*DBSuite) Reset

func (t *DBSuite) Reset()

Reset

Sets up a new mock, driver and database upon test completion.

func (*DBSuite) RunExpectationsT added in v0.0.3

func (t *DBSuite) RunExpectationsT(want, actual interface{})

RunExpectationsT runs the DB test and asserts the expectations were met.

func (*DBSuite) RunT

func (t *DBSuite) RunT(want, actual interface{}, times ...int)

RunT runs the the DB test for the store with Schema being tested.

type HandlerSuite

type HandlerSuite struct {
	suite.Suite
	Recorder *httptest.ResponseRecorder
	Context  *gin.Context
	Engine   *gin.Engine
}

HandlerSuite represents the suite of testing methods for controllers.

func NewHandlerSuite

func NewHandlerSuite() HandlerSuite

NewHandlerSuite

New recorder for testing controllers, initialises gin & sets gin mode.

func (*HandlerSuite) ContentType

func (t *HandlerSuite) ContentType() string

ContentType

Returns the recorder's content type.

func (*HandlerSuite) NewRequest

func (t *HandlerSuite) NewRequest(method, url string, body io.Reader)

NewRequest

Creates a new http.Request and assigns the gin testing the request.

func (*HandlerSuite) RequestAndServe

func (t *HandlerSuite) RequestAndServe(method, url, engineURL string, body interface{}, handler func(ctx *gin.Context))

RequestAndServe

Makes a new http.Request and assigns the gin testing the request, serves HTTP.

func (*HandlerSuite) Reset

func (t *HandlerSuite) Reset()

Reset

Sets up a new recorder, engine and context upon test completion.

func (*HandlerSuite) RespondData

func (t *HandlerSuite) RespondData() (RespondJSON, string)

RespondData

Returns the RespondJSON and the data decoded in string form.

func (*HandlerSuite) RunT

func (t *HandlerSuite) RunT(want interface{}, status int, message string)

RunT

Run the API test.

func (*HandlerSuite) ServeHTTP

func (t *HandlerSuite) ServeHTTP()

func (*HandlerSuite) Status

func (t *HandlerSuite) Status() int

Status

Returns the recorder's status code.

type RespondJSON

type RespondJSON struct {
	Status  int    `json:"status"`
	Error   bool   `json:"error"`
	Message string `json:"message"`
	Meta    struct {
		RequestTime  string      `json:"request_time"`
		ResponseTime string      `json:"response_time"`
		LatencyTime  string      `json:"latency_time"`
		Pagination   interface{} `json:"pagination,omitempty"`
	} `json:"meta"`
	Data interface{} `json:"data"`
}

RespondJSON is an abstraction of the api.RespondJSON

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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