testnet

package module
v0.0.0-...-05450cd Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2013 License: Apache-2.0 Imports: 7 Imported by: 0

README

Testnet

This package provides helpers for testing interactions with an HTTP API in the Go (#golang) programming language. It allows you to test that the expected HTTP requests are received by the httptest.Server, and return mock responses.

Testnet was imported directly from the CloudFoundry Go CLI's test helpers. The license has been copied exactly from the source (though I attempted to fill in the correct owner in the boilerplate copyright notice).

Documentation

Overview

This package provides helpers for testing interactions with an HTTP API in the Go (#golang) programming language. It allows you to test that the expected HTTP requests are received by the `httptest.Server`, and return mock responses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RemoveWhiteSpaceFromBody

func RemoveWhiteSpaceFromBody(body string) string

Types

type Handler

type Handler struct {
	Requests  []TestRequest
	CallCount int
	T         *testing.T
}

func NewServer

func NewServer(t *testing.T, requests []TestRequest) (s *httptest.Server, h *Handler)

func NewTLSServer

func NewTLSServer(t *testing.T, requests []TestRequest) (s *httptest.Server, h *Handler)

func (*Handler) AllRequestsCalled

func (h *Handler) AllRequestsCalled() bool

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type RequestMatcher

type RequestMatcher func(*testing.T, *http.Request)

func RequestBodyMatcher

func RequestBodyMatcher(expectedBody string) RequestMatcher

func RequestBodyMatcherWithContentType

func RequestBodyMatcherWithContentType(expectedBody, expectedContentType string) RequestMatcher

type TestRequest

type TestRequest struct {
	Method   string
	Path     string
	Header   http.Header
	Matcher  RequestMatcher
	Response TestResponse
}

type TestResponse

type TestResponse struct {
	Body   string
	Status int
	Header http.Header
}

Jump to

Keyboard shortcuts

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