Documentation ¶
Index ¶
- Variables
- func AssertResponse(resp *http.Response, tc *TestCase) error
- func CI() bool
- func Cert(domain string) tls.Certificate
- func Flaky(t *testing.T, fake ...func() (bool, func(...interface{})))
- func GetPythonVersion() string
- func HttpHandlerRunner(handler http.HandlerFunc) func(*http.Request, *TestCase) (*http.Response, error)
- func HttpServerRequestBuilder(baseURL string) func(tc *TestCase) (*http.Request, error)
- func HttpServerRunner() func(*http.Request, *TestCase) (*http.Response, error)
- func IsDnsRecordsAddrsEqualsTo(itemAddrs, addrs []string) bool
- func LocalDialer() func(context.Context, string, string) (net.Conn, error)
- func NewClient(opts ...ClientOption) *http.Client
- func NewClientLocal(opts ...ClientOption) *http.Client
- func NewMonitor(duration int)
- func NewRequest(tc *TestCase) (req *http.Request, err error)
- func NewTransport(opts ...TransportOption) *http.Transport
- func Racy(t *testing.T, fake ...func() (bool, func(...interface{})))
- func ReqBodyReader(body interface{}) io.Reader
- func TcpMock(useSSL bool, cb func(in []byte, err error) (out []byte)) net.Listener
- func TestHttpHandler(t testing.TB, handle http.HandlerFunc, testCases ...TestCase)
- func TestHttpServer(t testing.TB, baseURL string, testCases ...TestCase)
- type ClientOption
- type DialContext
- type DnsMockHandle
- type HTTPTestRunner
- type Monitor
- type TCPTestCase
- type TCPTestRunner
- type TestCase
- type TransportOption
Constants ¶
This section is empty.
Variables ¶
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 GetPythonVersion ¶
func GetPythonVersion() string
func HttpHandlerRunner ¶
func HttpServerRunner ¶
func LocalDialer ¶
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 NewTransport ¶
func NewTransport(opts ...TransportOption) *http.Transport
NewTransport creates a http.Transport with options
func ReqBodyReader ¶
func TestHttpHandler ¶
func TestHttpHandler(t testing.TB, handle http.HandlerFunc, testCases ...TestCase)
Types ¶
type ClientOption ¶
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 ¶
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 TCPTestCase ¶
type TCPTestRunner ¶
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 ¶
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.