golib: github.com/levenlabs/golib/testutil Index | Files

package testutil

import "github.com/levenlabs/golib/testutil"

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

Index

Package Files

crypto.go geoip.go round_tripper.go testutil.go

Constants

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"
)

func GeoIP2Reader Uses

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

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

func RandInt64 Uses

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 Uses

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 Uses

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

type RoundTripper Uses

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 Uses

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 Uses

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

Response is a response for a specific domain

Package testutil imports 12 packages (graph). Updated 2018-06-12. Refresh now. Tools for package owners. This is an inactive package (no imports and no commits in at least two years).