mockhttp

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: LGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package mockhttp provides the ability to define mocked routes, specifying request validations to be performed on incoming requests to these routes, and mock responses to be returned for these requests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Route

type Route struct {
	// Method refers to the HTTP Method (http.MethodPost, http.MethodGet, etc).
	Method string
	// Endpoint refers to the route path specified either as an exact path or
	// as a regex prefixed with '=~'.
	// Example:
	//		`/stores`,
	//		`=~/stores/(w+)\z`   (matches '/stores/<store-id>')
	Endpoint string
}

Route represents a callable API endpoint.

type RouteResponder

type RouteResponder struct {
	// Route refers to a callable API endpoint.
	Route Route

	// ExpectedReqBody allows to specify the expected request body for requests
	// that call this Route.
	ExpectedReqBody any
	// ExpectedReqQueryParams allows to specify the expected request query
	// params for requests that call this Route.
	ExpectedReqQueryParams url.Values
	// ExpectedPathParams allows to specify the expected path parameters for
	// requests that call this Route. They should be specified in the order
	// that they are expected to be found in the path.
	ExpectedPathParams []string
	// MockResponse allows to configure a mock response body to be returned.
	MockResponse any
	// MockResponseStatus allows to configure the response status to be used.
	// If not specified, defaults to http.StatusOK.
	MockResponseStatus int
	// contains filtered or unexported fields
}

RouteResponder provides a way to define a mock http responder, wherein a request to a specific route can be validated as per some predefined expectation and mock responses can be configured to be returned when called.

func (*RouteResponder) Finish

func (r *RouteResponder) Finish(c *qt.C)

Finish runs validations for the route, ensuring that the received request matches the predefined expectations.

func (*RouteResponder) Generate

func (r *RouteResponder) Generate() httpmock.Responder

Generate returns a httpmock.Responder function for the Route. This returned function is used by httpmock to Generate a response whenever a http request is made to the configured Route.

Jump to

Keyboard shortcuts

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