testutils

package
v0.0.0-...-e78b468 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2015 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package testutils provides utilities for writing gologin tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertBodyString

func AssertBodyString(t *testing.T, rc io.ReadCloser, expected string)

AssertBodyString asserts that a Request Body matches the expected string.

func AssertFailureNotCalled

func AssertFailureNotCalled(t *testing.T) ctxh.ContextHandler

AssertFailureNotCalled is a failure ContextHandler that fails if called.

func AssertSuccessNotCalled

func AssertSuccessNotCalled(t *testing.T) ctxh.ContextHandler

AssertSuccessNotCalled is a success ContextHandler that fails if called.

func NewErrorServer

func NewErrorServer(t *testing.T, message string, code int) *httptest.Server

NewErrorServer returns a new httptest.Server endpoint which responds with the given error message and code. Caller must close the server.

func NewTestServerFunc

func NewTestServerFunc(handler func(w http.ResponseWriter, r *http.Request)) *httptest.Server

NewTestServerFunc is an adapter to allow the use of ordinary functions as httptest.Server's for testing. Caller must close the server.

func TestServer

func TestServer() (*http.Client, *http.ServeMux, *httptest.Server)

TestServer returns an http Client, ServeMux, and Server. The client proxies requests to the server and handlers can be registered on the mux to handle requests. The caller must close the test server.

func UnauthorizedTestServer

func UnauthorizedTestServer() (*http.Client, *httptest.Server)

UnauthorizedTestServer returns a http.Server which always returns a 401 Unauthorized response and a client which proxies to it. The caller must close the test server.

Types

type RewriteTransport

type RewriteTransport struct {
	Transport http.RoundTripper
}

RewriteTransport rewrites https requests to http to avoid TLS cert issues during testing.

func (*RewriteTransport) RoundTrip

func (t *RewriteTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip rewrites the request scheme to http and calls through to the composed RoundTripper or if it is nil, to the http.DefaultTransport.

Jump to

Keyboard shortcuts

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