be_http

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2025 License: MIT Imports: 9 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

be_http

-- import "."

Package be_http provides matchers for url.Request TODO: more detailed documentation here is required

Usage

var (
	GET     = func() types.BeMatcher { return HavingMethod(http.MethodGet) }
	HEAD    = func() types.BeMatcher { return HavingMethod(http.MethodHead) }
	POST    = func() types.BeMatcher { return HavingMethod(http.MethodPost) }
	PUT     = func() types.BeMatcher { return HavingMethod(http.MethodPut) }
	PATCH   = func() types.BeMatcher { return HavingMethod(http.MethodPatch) }
	DELETE  = func() types.BeMatcher { return HavingMethod(http.MethodDelete) }
	OPTIONS = func() types.BeMatcher { return HavingMethod(http.MethodOptions) }
	CONNECT = func() types.BeMatcher { return HavingMethod(http.MethodConnect) }
	TRACE   = func() types.BeMatcher { return HavingMethod(http.MethodTrace) }
)

HavingMethod: Syntactic sugar

func HavingBody
func HavingBody(args ...any) types.BeMatcher

HavingBody succeeds if the actual value is a *http.Request and its body matches the provided arguments. Note: The body is not re-streamed, so it's not available after matching.

func HavingHeader
func HavingHeader(key string, args ...any) types.BeMatcher

HavingHeader matches requests that have header with a given key. Key is a string key for a header, args can be nil or len(args)==1. Note: Golang's http.Header is map[string][]string, and matching is done on the FIRST value of the header in case if you have multiple-valued header that needs to be matched, use HavingHeaders() instead

These are scenarios that can be handled here: (1) If no args are given, it simply matches a request with existed header by key. (2) If len(args) == 1 && args[0] is a stringish, it matches a request with header Key: Args[0] (3) if len(args) == 1 && args[0] is not stringish, it is considered to be matcher for header's value Examples: - HavingHeader("X-Header") matches request with non-empty X-Header header - HavingHeader("X-Header", "X-Value") matches request with X-Header: X-Value - HavingHeader("X-Header", HavePrefix("Bearer ")) matchers request with header(X-Header)'s value matching given HavePrefix matcher

func HavingHeaders
func HavingHeaders(key string, args ...any) types.BeMatcher

HavingHeaders matches requests that have header with a given key. Key is a string key for a header, args can be nil or len(args)==1. Note: Matching is done on the list of header values. In case if you have single-valued header that needs to be matched, use HavingHeader() instead

These are scenarios that can be handled here: (1) If no args are given, it simply matches a request with existed header by key. (2) If len(args) == 1 && args[0] is a stringish, it matches a request with header Key: Args[0] (3) if len(args) == 1 && args[0] is not stringish, it is considered to be matcher for header's value Examples: - HavingHeader("X-Header") matches request with non-empty X-Header header - HavingHeader("X-Header", "X-Value") matches request with X-Header: X-Value - HavingHeader("X-Header", Dive(HavePrefix("Foo "))) matchers request with multiple X-Header values, each of them having Foo prefix

func HavingHost
func HavingHost(args ...any) types.BeMatcher

HavingHost succeeds if the actual value is a *http.Request and its Host matches the provided arguments.

func HavingMethod
func HavingMethod(args ...any) types.BeMatcher

HavingMethod succeeds if the actual value is a *http.Request and its HTTP method matches the provided arguments.

func HavingProto
func HavingProto(args ...any) types.BeMatcher

HavingProto succeeds if the actual value is a *http.Request and its Proto matches the provided arguments.

func HavingURL
func HavingURL(args ...any) types.BeMatcher

HavingURL succeeds if the actual value is a *http.Request and its URL matches the provided arguments.

func Request
func Request(args ...any) types.BeMatcher

Request matches an actual value to be a valid *http.Request corresponding to given inputs. Possible inputs: 1. Nil args -> so actual value MUST be any valid *http.Request. 2. Single arg . Actual value MUST be a *http.Request, whose .URL.String() is compared against args[0]. 3. List of Omega/Gomock/Psi matchers, that are applied to *http.Request object.

- Supports matching http.Request properties like method, URL, body, host, proto, and headers.
- Additional arguments can be used for matching specific headers, e.g., WithHeader("Content-Type", "application/json").

Documentation

Overview

Package be_http provides matchers for url.Request TODO: more detailed documentation here is required

Index

Constants

This section is empty.

Variables

View Source
var (
	GET     = func() types.BeMatcher { return HavingMethod(http.MethodGet) }
	HEAD    = func() types.BeMatcher { return HavingMethod(http.MethodHead) }
	POST    = func() types.BeMatcher { return HavingMethod(http.MethodPost) }
	PUT     = func() types.BeMatcher { return HavingMethod(http.MethodPut) }
	PATCH   = func() types.BeMatcher { return HavingMethod(http.MethodPatch) }
	DELETE  = func() types.BeMatcher { return HavingMethod(http.MethodDelete) }
	OPTIONS = func() types.BeMatcher { return HavingMethod(http.MethodOptions) }
	CONNECT = func() types.BeMatcher { return HavingMethod(http.MethodConnect) }
	TRACE   = func() types.BeMatcher { return HavingMethod(http.MethodTrace) }
)

HavingMethod: Syntactic sugar

Functions

func HavingBody

func HavingBody(args ...any) types.BeMatcher

HavingBody succeeds if the actual value is a *http.Request and its body matches the provided arguments. Note: The body is not re-streamed, so it's not available after matching.

func HavingHeader

func HavingHeader(key string, args ...any) types.BeMatcher

HavingHeader matches requests that have header with a given key. Key is a string key for a header, args can be nil or len(args)==1. Note: Golang's http.Header is `map[string][]string`, and matching is done on the FIRST value of the header in case if you have multiple-valued header that needs to be matched, use HavingHeaders() instead

These are scenarios that can be handled here: (1) If no args are given, it simply matches a request with existed header by key. (2) If len(args) == 1 && args[0] is a stringish, it matches a request with header `Key: Args[0]` (3) if len(args) == 1 && args[0] is not stringish, it is considered to be matcher for header's value Examples: - HavingHeader("X-Header") matches request with non-empty X-Header header - HavingHeader("X-Header", "X-Value") matches request with X-Header: X-Value - HavingHeader("X-Header", HavePrefix("Bearer ")) matchers request with header(X-Header)'s value matching given HavePrefix matcher

func HavingHeaders added in v0.2.0

func HavingHeaders(key string, args ...any) types.BeMatcher

HavingHeaders matches requests that have header with a given key. Key is a string key for a header, args can be nil or len(args)==1. Note: Matching is done on the list of header values. In case if you have single-valued header that needs to be matched, use HavingHeader() instead

These are scenarios that can be handled here: (1) If no args are given, it simply matches a request with existed header by key. (2) If len(args) == 1 && args[0] is a stringish, it matches a request with header `Key: Args[0]` (3) if len(args) == 1 && args[0] is not stringish, it is considered to be matcher for header's value Examples: - HavingHeader("X-Header") matches request with non-empty X-Header header - HavingHeader("X-Header", "X-Value") matches request with X-Header: X-Value - HavingHeader("X-Header", Dive(HavePrefix("Foo "))) matchers request with multiple X-Header values, each of them having Foo prefix

func HavingHost

func HavingHost(args ...any) types.BeMatcher

HavingHost succeeds if the actual value is a *http.Request and its Host matches the provided arguments.

func HavingMethod

func HavingMethod(args ...any) types.BeMatcher

HavingMethod succeeds if the actual value is a *http.Request and its HTTP method matches the provided arguments.

func HavingProto

func HavingProto(args ...any) types.BeMatcher

HavingProto succeeds if the actual value is a *http.Request and its Proto matches the provided arguments.

func HavingURL

func HavingURL(args ...any) types.BeMatcher

HavingURL succeeds if the actual value is a *http.Request and its URL matches the provided arguments.

func Request

func Request(args ...any) types.BeMatcher

Request matches an actual value to be a valid *http.Request corresponding to given inputs. Possible inputs: 1. Nil args -> so actual value MUST be any valid *http.Request. 2. Single arg <string>. Actual value MUST be a *http.Request, whose .URL.String() is compared against args[0]. 3. List of Omega/Gomock/Psi matchers, that are applied to *http.Request object.

  • Supports matching http.Request properties like method, URL, body, host, proto, and headers.
  • Additional arguments can be used for matching specific headers, e.g., WithHeader("Content-Type", "application/json").

Types

This section is empty.

Jump to

Keyboard shortcuts

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