testserver

package
v0.0.0-...-a420e69 Latest Latest
Warning

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

Go to latest
Published: May 24, 2016 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TestServer

type TestServer struct {
	URL string
	// contains filtered or unexported fields
}

TestServer wraps around httptest.Server to support expectations and timeout tests. Use ExpectAndRespond and ExpectAndHang methods to indicate expected requests in the order they should arrive.

Currently, parallel requests are not supported.

func NewTestServer

func NewTestServer(t *testing.T) *TestServer

NewTestServer creates a new TestServer associate with given testing.T instance

func (*TestServer) CloseAndAssertExpectations

func (ts *TestServer) CloseAndAssertExpectations()

CloseAndAssertExpectations will stop any hanging requests and shutdown the test server. Any remaining expectations will flag a test error.

func (*TestServer) ExpectAndHang

func (ts *TestServer) ExpectAndHang(method string, url string) *TestServer

ExpectAndHang specifies the next request expected, the server hangs and the request will not be responded to. This is useful to test client timeouts. To stop the hanging server, call CloseAndAssertExpectations.

func (*TestServer) ExpectAndRespond

func (ts *TestServer) ExpectAndRespond(method string, url string, responseCode int, responseBytes string) *TestServer

ExpectAndRespond specifies the next request to be expected (using request method and url) and specifies what response needs to be provided.

Jump to

Keyboard shortcuts

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