test

package
v2.9.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2019 License: MPL-2.0 Imports: 25 Imported by: 0

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 Cert

func Cert(domain string) tls.Certificate

Generate cert

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 NewRequest

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

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 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 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            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"`
	Cookies         []*http.Cookie    `json:",omitempty"`
	Delay           time.Duration     `json:",omitempty"`
	BodyMatch       string            `json:",omitempty"`
	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"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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