test

package
v0.0.0-...-7ea5fdf Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const ErrCouldNotHydrateTestData = "could not hydrate test data"

Variables

View Source
var (
	//ErrBrokenHTTPClient represents error message from test issues with Request
	ErrBrokenHTTPClient = fmt.Errorf("broken http connection")
)

Functions

func DuplicateAccountErrorResponse

func DuplicateAccountErrorResponse() *data.ErrorResponse

DuplicateAccountErrorResponse returns valid static ErrorResponse for existing Account error.

func NewAccountDataFromFile

func NewAccountDataFromFile(filename string) *data.Data

NewAccountDataFromFile reads relative file path and returns Data (Account).

func NewAccountsFromFile

func NewAccountsFromFile(filename string) *data.AccountsData

NewAccountsFromFile reads relative file path and returns AccountsData ([]Account).

func NewErrorMessageFromFile

func NewErrorMessageFromFile(filename string, statusCode int) *data.ErrorResponse

NewErrorMessageFromFile reads relative file path and http.StatusCode and returns ErrorResponse.

func NewRequestMock

func NewRequestMock(response *internalhttp.Response, err error) internalhttp.IRequest

NewRequestMock returns Request based on a given test Response. could improve by getting correct urls instead of any.

func NewTestClient

func NewTestClient(request http.IRequest) *accountsClient.Client

NewTestClient is used to inject a mocked Request during tests.

func ReadJSON

func ReadJSON(path string) []byte

ReadJSON returns byte array based on relative file path.

func ServerErrorResponse

func ServerErrorResponse() *data.ErrorResponse

ServerErrorResponse returns valid static ErrorResponse for generic 500 Server Error.

Types

type RequestMock

type RequestMock struct {
	mock.Mock
	internalhttp.IRequest
}

RequestMock to be able to mock net/http looked into using Pact but with only an external Provider it would be too much to force it to use e2e tests looked into using Sling but had to keep all third party libraries out of the client.

func (*RequestMock) Do

Do should be mocked to wrap http.Client, and returns http.Response byte array already read in Response.

Jump to

Keyboard shortcuts

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