testutils

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithLogger

func ContextWithLogger(t *testing.T) context.Context

func ContextWithVerboseLogger

func ContextWithVerboseLogger(t *testing.T) context.Context

Types

type ErrorTransport

type ErrorTransport struct{}

ErrorTransport is custom transport that always produces a simulated network error.

func (*ErrorTransport) RoundTrip

func (t *ErrorTransport) RoundTrip(_ *http.Request) (*http.Response, error)

RoundTrip implements the RoundTripper interface and returns a simulated network error.

type HTTPMethod

type HTTPMethod = string

HTTPMethod is an alias for string, representing an HTTP method.

type ServerResponses

type ServerResponses map[HTTPMethod]struct {
	ResponseCode        int                 // HTTP response status code.
	ResponseBody        string              // HTTP response body.
	ValidateRequestFunc func(*http.Request) // Function to validate incoming requests.
}

ServerResponses is a map of HTTP methods to expected responses for testing.

type TestServer

type TestServer struct {
	*httptest.Server // Embedded httptest.Server for underlying server functionality.
}

TestServer is a wrapper around httptest.Server that provides utility methods for testing.

func NewHTTPTestServer

func NewHTTPTestServer(t *testing.T, arg ServerResponses) *TestServer

NewHTTPTestServer creates a new HTTP test server with the specified responses for each HTTP method.

func (TestServer) Client

func (t TestServer) Client() *http.Client

Client returns an HTTP client associated with the test server.

func (TestServer) FaultyClient

func (t TestServer) FaultyClient() *http.Client

FaultyClient returns an HTTP client associated with the test server that always produces a network error.

func (TestServer) URL

func (t TestServer) URL() *url.URL

URL returns the URL of the test server.

Jump to

Keyboard shortcuts

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