test

package
v0.0.0-...-dc45894 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2022 License: Apache-2.0, MIT, Apache-2.0, + 1 more Imports: 16 Imported by: 0

Documentation

Overview

Package test provides utility methods to test APIs based on the common API.

Index

Constants

This section is empty.

Variables

View Source
var (
	// SSLCertFile is the location of the certificate file.
	// Used in HTTPClient to set the right certificate when
	// creating an HTTPs client. Might need adjusting depending
	// on where the tests are running.
	SSLCertFile = "test/server.crt"

	// ClientOrigin sets the Origin header for requests to this.
	ClientOrigin = "myorigin"
)

Functions

func BothEndpoints

func BothEndpoints(t *testing.T, test Func)

BothEndpoints runs a test.Func against the http and p2p endpoints.

func CheckHeaders

func CheckHeaders(t *testing.T, expected map[string][]string, url string, headers http.Header)

CheckHeaders checks that all the headers are set to what is expected.

func HTTPClient

func HTTPClient(t *testing.T, h host.Host, isHTTPS bool) *http.Client

HTTPClient returns a client that supporst both http/https and libp2p-tunneled-http.

func HTTPSEndPoint

func HTTPSEndPoint(t *testing.T, test Func)

HTTPSEndPoint runs the given test.Func against an HTTPs endpoint.

func HTTPURL

func HTTPURL(a API) string

HTTPURL returns the http endpoint of the API.

func IsHTTPS

func IsHTTPS(url string) bool

IsHTTPS returns true if a url string uses HTTPS.

func MakeDelete

func MakeDelete(t *testing.T, api API, url string, resp interface{})

MakeDelete performs a DELETE request against the given API.

func MakeGet

func MakeGet(t *testing.T, api API, url string, resp interface{})

MakeGet performs a GET request against the API.

func MakeHost

func MakeHost(t *testing.T, api API) host.Host

MakeHost makes a libp2p host that knows how to talk to the given API.

func MakeOptions

func MakeOptions(t *testing.T, api API, url string, reqHeaders http.Header) http.Header

MakeOptions performs an OPTIONS request against the given api.

func MakePost

func MakePost(t *testing.T, api API, url string, body []byte, resp interface{})

MakePost performs a POST request against the API with the given body.

func MakePostWithContentType

func MakePostWithContentType(t *testing.T, api API, url string, body []byte, contentType string, resp interface{})

MakePostWithContentType performs a POST with the given body and content-type.

func MakeStreamingGet

func MakeStreamingGet(t *testing.T, api API, url string, resp interface{}, trailerError bool)

MakeStreamingGet performs a GET request and uses ProcessStreamingResp

func MakeStreamingPost

func MakeStreamingPost(t *testing.T, api API, url string, body io.Reader, contentType string, resp interface{})

MakeStreamingPost performs a POST request and uses ProcessStreamingResp

func P2pURL

func P2pURL(a API) string

P2pURL returns the libp2p endpoint of the API.

func ProcessResp

func ProcessResp(t *testing.T, httpResp *http.Response, err error, resp interface{})

ProcessResp puts a response into a given type or fails the test.

func ProcessStreamingResp

func ProcessStreamingResp(t *testing.T, httpResp *http.Response, err error, resp interface{}, trailerError bool)

ProcessStreamingResp decodes a streaming response into the given type and fails the test on error.

Types

type API

type API interface {
	HTTPAddresses() ([]string, error)
	Host() host.Host
	Headers() map[string][]string
}

API represents what an API is to us.

type Func

type Func func(t *testing.T, url URLFunc)

Func is a function that runs a test with a given URL.

type URLFunc

type URLFunc func(a API) string

URLFunc is a function that given an API returns a url string.

Jump to

Keyboard shortcuts

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