http

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AwaitConvergence added in v0.6.1

func AwaitConvergence(t *testing.T, threshold int, maxTimeToConsistency time.Duration, fn func(elapsed time.Duration) bool)

AwaitConvergence runs the given function until it returns 'true' `threshold` times in a row. Each failed attempt has a 1s delay; successful attempts have no delay.

func CalculateHost added in v0.8.1

func CalculateHost(t *testing.T, gwAddr, scheme string) string

CalculateHost will calculate the Host header as per HTTP spec. To summarize, host will not include any port if it is implied from the scheme. In case of any error, the input gwAddr will be returned as the default.

func ExpectMirroredRequest added in v0.7.1

func ExpectMirroredRequest(t *testing.T, client client.Client, clientset clientset.Interface, mirrorPods []BackendRef, path string)

func Ipv6SafeHost added in v1.1.0

func Ipv6SafeHost(host string) string

Ipv6SafeHost returns a safe representation for an ipv6 address to be used with a port We assume that host is a literal IPv6 address if host has colons. Per https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2. This is like net.JoinHostPort, but we don't need a port.

func MakeRequest added in v0.6.1

func MakeRequest(t *testing.T, expected *ExpectedResponse, gwAddr, protocol, scheme string) roundtripper.Request

func MakeRequestAndExpectEventuallyConsistentResponse

func MakeRequestAndExpectEventuallyConsistentResponse(t *testing.T, r roundtripper.RoundTripper, timeoutConfig config.TimeoutConfig, gwAddr string, expected ExpectedResponse)

MakeRequestAndExpectEventuallyConsistentResponse makes a request with the given parameters, understanding that the request may fail for some amount of time.

Once the request succeeds consistently with the response having the expected status code, make additional assertions on the response body using the provided ExpectedResponse.

func WaitForConsistentResponse

func WaitForConsistentResponse(t *testing.T, r roundtripper.RoundTripper, req roundtripper.Request, expected ExpectedResponse, threshold int, maxTimeToConsistency time.Duration)

WaitForConsistentResponse repeats the provided request until it completes with a response having the expected response consistently. The provided threshold determines how many times in a row this must occur to be considered "consistent".

Types

type BackendRef added in v0.8.1

type BackendRef struct {
	Name      string
	Namespace string
}

type ExpectedRequest

type ExpectedRequest struct {
	Request

	// AbsentHeaders are names of headers that are expected
	// *not* to be present on the request.
	AbsentHeaders []string
}

ExpectedRequest defines expected properties of a request that reaches a backend.

type ExpectedResponse

type ExpectedResponse struct {
	// Request defines the request to make.
	Request Request

	// ExpectedRequest defines the request that
	// is expected to arrive at the backend. If
	// not specified, the backend request will be
	// expected to match Request.
	ExpectedRequest *ExpectedRequest

	RedirectRequest *roundtripper.RedirectRequest

	// BackendSetResponseHeaders is a set of headers
	// the echoserver should set in its response.
	BackendSetResponseHeaders map[string]string

	// Response defines what response the test case
	// should receive.
	Response Response

	Backend   string
	Namespace string

	// MirroredTo is the destination BackendRefs of the mirrored request.
	MirroredTo []BackendRef

	// User Given TestCase name
	TestCaseName string
}

ExpectedResponse defines the response expected for a given request.

func (*ExpectedResponse) GetTestCaseName added in v0.6.0

func (er *ExpectedResponse) GetTestCaseName(i int) string

GetTestCaseName gets the user-defined test case name or generates one from expected response to a given request.

type Request

type Request struct {
	Host             string
	Method           string
	Path             string
	Headers          map[string]string
	UnfollowRedirect bool
	Protocol         string
}

Request can be used as both the request to make and a means to verify that echoserver received the expected request. Note that multiple header values can be provided, as a comma-separated value.

type Response added in v0.6.0

type Response struct {
	StatusCode    int
	Headers       map[string]string
	AbsentHeaders []string
}

Response defines expected properties of a response from a backend.

Jump to

Keyboard shortcuts

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