testutil

package
v0.0.0-...-3975a26 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package testutil implements helper functions for more convenient testing and may be imported in '_test.go' files only. Usage of some of these functions would have to be replaced by the ones provided by the official testing toolkit packages, should they decide to include helper functions of similar logic and kind.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertEqualError

func AssertEqualError(t *testing.T, exp, err error)

AssertEqualError uses testify's assert package to check if errors are equal or, if assert.AnError is expected, whether an error exists or not.

func AssertFilterEqual

func AssertFilterEqual(t *testing.T, v1, v2 interface{}, ignoreTypes []interface{})

AssertFilterEqual asserts that two objects are equal. All ignored types found on any of the provided objects will not be compared.

func MockHTTP

func MockHTTP() (*http.Client, *httpmock.MockTransport)

MockHTTP returns mocked http environment.

func QueryResponder

func QueryResponder(t *testing.T, resp httpmock.Responder, q url.Values) httpmock.Responder

QueryResponder asserts the required query values are present in the request.

func RequireEqualError

func RequireEqualError(t *testing.T, exp, err error)

RequireEqualError uses testify's require package to check if errors are equal or, if assert.AnError is expected, whether an error exists or not.

func RequireFilterEqual

func RequireFilterEqual(t *testing.T, v1, v2 interface{}, ignoreTypes []interface{})

RequireFilterEqual asserts that two objects are equal. All ignored types found on any of the provided objects will not be compared.

Types

type RoundTripperMock

type RoundTripperMock struct {
	// RoundTripFunc mocks the RoundTrip method.
	RoundTripFunc func(in1 *http.Request) (*http.Response, error)
	// contains filtered or unexported fields
}

RoundTripperMock is a mock implementation of http.RoundTripper.

    func TestSomethingThatUsesRoundTripper(t *testing.T) {

        // make and configure a mocked http.RoundTripper
        mockedRoundTripper := &RoundTripperMock{
            RoundTripFunc: func(in1 *http.Request) (*http.Response, error) {
	               panic("mock out the RoundTrip method")
            },
        }

        // use mockedRoundTripper in code that requires RoundTripper
        // and then make assertions.

    }

func (*RoundTripperMock) RoundTrip

func (mock *RoundTripperMock) RoundTrip(in1 *http.Request) (*http.Response, error)

RoundTrip calls RoundTripFunc.

func (*RoundTripperMock) RoundTripCalls

func (mock *RoundTripperMock) RoundTripCalls() []struct {
	In1 *http.Request
}

RoundTripCalls gets all the calls that were made to RoundTrip. Check the length with:

len(mockedRoundTripper.RoundTripCalls())

Jump to

Keyboard shortcuts

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