testutil

package
v0.0.0-...-0f89747 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2018 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package testutil provides various methods which we commonly use when writing tests

Index

Constants

View Source
const (
	// GeoIP2IPv4 contains the only IPv4 in the geoip2 test database
	// Location: Milton, Washington, US
	GeoIP2IPv4 = "216.160.83.56"

	// GeoIP2IPv6 contains the only IPv6 in the geoip2 test database
	// Finland, EU
	GeoIP2IPv6 = "2a02:d200::1"
)

Variables

This section is empty.

Functions

func GeoIP2Reader

func GeoIP2Reader() (*geoip2.Reader, error)

GeoIP2Reader returns a city database reader with only 1 ipv4 and 1 ipv6 address

func RandInt64

func RandInt64() int64

RandInt64 returns a random integer. greater than or equal to 0, and less than 1 million. It's not necessary to do any seeding to use this method

func RandStr

func RandStr() string

RandStr returns a random alphanumeric string of arbitrary length. It's not necessary to do any seeding to use this method

func SignedCert

func SignedCert(domain string, parentCertPEM, parentKeyPEM []byte) ([]byte, []byte)

SignedCert generates a PEM encoded certificate/key pair for the given domain. If parentCertPEM/parentKeyPEM are given the certificate will be signed by that parent, otherwise it will be self-signed. If domain is not given, the returned certificate will itself be a signing CA certificate

This function will panic if it receives invalid input or can't read from rand.Reader for some reason

Types

type RoundTripper

type RoundTripper map[string]RoundTripperResponse

RoundTripper is an instance of a RoundTripper that allows you to pass the responses ahead of time per domain

func (RoundTripper) RoundTrip

func (rt RoundTripper) RoundTrip(r *http.Request) (*http.Response, error)

RoundTrip is needed to implement the RoundTripper interface It checks for an existing response for the domain first, and then falls back to looking for an existing response for the full uri

type RoundTripperResponse

type RoundTripperResponse struct {
	Resp *http.Response
	Err  error
}

Response is a response for a specific domain

Jump to

Keyboard shortcuts

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