test

package
v1.7.0-rc8 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2023 License: MPL-2.0 Imports: 31 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DomainsToAddresses = map[string][]string{
		"host1.": {"127.0.0.1"},
		"host2.": {"127.0.0.1"},
		"host3.": {"127.0.0.1"},
	}
	DomainsToIgnore = []string{
		"redis.",
		"tyk-redis.",
		"mongo.",
		"tyk-mongo.",
	}
)

Functions

func AssertResponse

func AssertResponse(resp *http.Response, tc *TestCase) error

func CI

func CI() bool

CI returns true when a non-empty CI env is present

func Cert

func Cert(domain string) tls.Certificate

Generate cert

func Flaky

func Flaky(t *testing.T, fake ...func() (bool, func(...interface{})))

Flaky skips a flaky test in a CI environment

func GetPythonVersion

func GetPythonVersion() string

func HttpHandlerRunner

func HttpHandlerRunner(handler http.HandlerFunc) func(*http.Request, *TestCase) (*http.Response, error)

func HttpServerRequestBuilder

func HttpServerRequestBuilder(baseURL string) func(tc *TestCase) (*http.Request, error)

func HttpServerRunner

func HttpServerRunner() func(*http.Request, *TestCase) (*http.Response, error)

func IsDnsRecordsAddrsEqualsTo

func IsDnsRecordsAddrsEqualsTo(itemAddrs, addrs []string) bool

func LocalDialer

func LocalDialer() func(context.Context, string, string) (net.Conn, error)

LocalDialer provides a function to use to dial to localhost

func NewClient

func NewClient(opts ...ClientOption) *http.Client

NewClient creates a http.Client with options

func NewClientLocal

func NewClientLocal(opts ...ClientOption) *http.Client

NewClientLocal returns a http.Client that can connect only to localhost. See: `WithLocalDialer`.

func NewMonitor

func NewMonitor(duration int)

func NewRequest

func NewRequest(tc *TestCase) (req *http.Request, err error)

func NewTransport

func NewTransport(opts ...TransportOption) *http.Transport

NewTransport creates a http.Transport with options

func Racy

func Racy(t *testing.T, fake ...func() (bool, func(...interface{})))

Racy skips a racy test in a CI environment

func ReqBodyReader

func ReqBodyReader(body interface{}) io.Reader

func TcpMock

func TcpMock(useSSL bool, cb func(in []byte, err error) (out []byte)) net.Listener

func TestHttpHandler

func TestHttpHandler(t testing.TB, handle http.HandlerFunc, testCases ...TestCase)

func TestHttpServer

func TestHttpServer(t testing.TB, baseURL string, testCases ...TestCase)

Types

type ClientOption

type ClientOption func(*http.Client)

Options for populating a http.Client

func WithTransport

func WithTransport(transport http.RoundTripper) ClientOption

WithTransport sets a http.RoundTripper to a http.Client

type DialContext

type DialContext func(ctx context.Context, network, addr string) (net.Conn, error)

DialContext function signature

type DnsMockHandle

type DnsMockHandle struct {
	ShutdownDnsMock func() error
	// contains filtered or unexported fields
}

func InitDNSMock

func InitDNSMock(domainsMap map[string][]string, domainsErrorMap map[string]int) (*DnsMockHandle, error)

InitDNSMock initializes dns server on udp:0 address and replaces net.DefaultResolver in order to route all dns queries within tests to this server. InitDNSMock returns handle, which can be used to add/remove dns query mock responses or initialization error.

func (*DnsMockHandle) PushDomains

func (h *DnsMockHandle) PushDomains(domainsMap map[string][]string, domainsErrorMap map[string]int) func()

type HTTPTestRunner

type HTTPTestRunner struct {
	Do             func(*http.Request, *TestCase) (*http.Response, error)
	Assert         func(*http.Response, *TestCase) error
	RequestBuilder func(*TestCase) (*http.Request, error)
}

func (HTTPTestRunner) Run

func (r HTTPTestRunner) Run(t testing.TB, testCases ...TestCase) (*http.Response, error)

type Monitor

type Monitor struct {
	Alloc,
	TotalAlloc,
	Sys,
	Mallocs,
	Frees,
	LiveObjects,
	PauseTotalNs uint64

	NumGC        uint32
	NumGoroutine int
}

type TCPTestCase

type TCPTestCase struct {
	Action     string //read or write
	Payload    string
	ErrorMatch string
}

type TCPTestRunner

type TCPTestRunner struct {
	UseSSL          bool
	Target          string
	Hostname        string
	TLSClientConfig *tls.Config
}

func (TCPTestRunner) Run

func (r TCPTestRunner) Run(t testing.TB, testCases ...TCPTestCase) error

type TestCase

type TestCase struct {
	Method  string `json:",omitempty"`
	Path    string `json:",omitempty"`
	BaseURL string `json:",omitempty"`
	Domain  string `json:",omitempty"`
	Proto   string `json:",omitempty"`

	// Code is the expected HTTP response status code.
	Code int `json:",omitempty"`

	Data            interface{}       `json:",omitempty"`
	Headers         map[string]string `json:",omitempty"`
	PathParams      map[string]string `json:",omitempty"`
	FormParams      map[string]string `json:",omitempty"`
	QueryParams     map[string]string `json:",omitempty"`
	Cookies         []*http.Cookie    `json:",omitempty"`
	Delay           time.Duration     `json:",omitempty"`
	BodyMatch       string            `json:",omitempty"` // regex
	BodyMatchFunc   func([]byte) bool `json:",omitempty"`
	BodyNotMatch    string            `json:",omitempty"`
	HeadersMatch    map[string]string `json:",omitempty"`
	HeadersNotMatch map[string]string `json:",omitempty"`
	JSONMatch       map[string]string `json:",omitempty"`
	ErrorMatch      string            `json:",omitempty"`
	BeforeFn        func()            `json:"-"`
	Client          *http.Client      `json:"-"`

	AdminAuth      bool `json:",omitempty"`
	ControlRequest bool `json:",omitempty"`
}

type TransportOption

type TransportOption func(*http.Transport)

Options for populating a http.Transport

func WithDialer

func WithDialer(dialer DialContext) TransportOption

WithDialer sets transport.DialContext

func WithLocalDialer

func WithLocalDialer() TransportOption

WithLocalDialer sets a http.Transport DialContext, which only connects to 127.0.0.1.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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