testutils

package
v0.0.0-...-7112df6 Latest Latest
Warning

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

Go to latest
Published: May 25, 2019 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package testutils provides utilities for testing purposes

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExpectedRequest

type ExpectedRequest struct {
	HttpMethod string
	Url        string
	Payload    interface{}
}

An ExpectedRequest represents the expected request that will be matched against the incoming http request

type Response

type Response struct {
	HttpStatusCode int
	Payload        interface{}
	RawContent     bool
}

A Response represents the response to return when the incoming request matches the ExpectedRequest

type TestClientServer

type TestClientServer struct {
	RequestMatcher TestRequestMatcher
}

TestClientServer represents a mock server configured with a matcher and a working client that is able to send requests to the server

func (*TestClientServer) TestClientServer

func (t *TestClientServer) TestClientServer() (*http.Client, *httptest.Server)

TestClientServer creates a client and a server that the user can then use in unit tests. The server returned will serve a response only if the incoming request matches the configured expected request.

type TestRequestMatcher

type TestRequestMatcher struct {
	ExpectedRequest ExpectedRequest
	Response        Response
}

A TestRequestMatcher represents the expected behaviour of the mock server

func NewRequestMatcher

func NewRequestMatcher(expectedHttpMethod, expectedPath string, expectedPayload interface{}, responseStatusCode int, response interface{}) TestRequestMatcher

NewRequestMatcher constructs a TestRequestMatcher used to match an http.Request with the expected configured request and returns the configured response in JSON and status code

func NewRequestMatcherWithOptions

func NewRequestMatcherWithOptions(expectedHttpMethod, expectedPath string, expectedPayload interface{}, responseStatusCode int, response interface{}, responseRawContent bool) TestRequestMatcher

NewRequestMatcher constructs a TestRequestMatcher used to match an http.Request with the expected configured request and return the configured response (either in JSON or RAW depending on the value provided for responseRawContent) and status code

Jump to

Keyboard shortcuts

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