test

package
v0.0.0-...-6b20280 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2014 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FakeDial

func FakeDial(network, addr string) (net.Conn, error)

FakeDial makes connections to localhost, no matter what addr was given.

func GetFakeTransport

func GetFakeTransport() http.RoundTripper

GetFakeTransport gets a http.RoundTripper that uses FakeDial

Types

type MockDatastore

type MockDatastore struct {
	mock.Mock
}

func (*MockDatastore) ClaimNewHost

func (ds *MockDatastore) ClaimNewHost() string

func (*MockDatastore) LinksForHost

func (ds *MockDatastore) LinksForHost(domain string) <-chan *walker.URL

func (*MockDatastore) StoreParsedURL

func (ds *MockDatastore) StoreParsedURL(u *walker.URL, fr *walker.FetchResults)

func (*MockDatastore) StoreURLFetchResults

func (ds *MockDatastore) StoreURLFetchResults(fr *walker.FetchResults)

func (*MockDatastore) UnclaimHost

func (ds *MockDatastore) UnclaimHost(host string)

type MockDispatcher

type MockDispatcher struct {
	mock.Mock
}

func (*MockDispatcher) StartDispatcher

func (d *MockDispatcher) StartDispatcher() error

func (*MockDispatcher) StopDispatcher

func (d *MockDispatcher) StopDispatcher() error

type MockHTTPHandler

type MockHTTPHandler struct {
	// contains filtered or unexported fields
}

MockHTTPHandler implements http.Handler to serve mock requests.

It is not a mere mock.Mock object because using `.Return()` to return *http.Response objects is hard to do, and this provides conveniences in our tests.

It should be instantiated with `NewMockRemoteServer()`

func NewMockHTTPHandler

func NewMockHTTPHandler() *MockHTTPHandler

func (*MockHTTPHandler) ServeHTTP

func (s *MockHTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*MockHTTPHandler) SetResponse

func (s *MockHTTPHandler) SetResponse(link string, r *MockResponse)

SetResponse sets a mock response for the server to return when it sees an incoming request matching the given link. The link should have a scheme and host (ex. "http://test.com/stuff"). Empty fields on MockResponse will be filled in with default values (see MockResponse)

type MockHandler

type MockHandler struct {
	mock.Mock
}

func (*MockHandler) HandleResponse

func (h *MockHandler) HandleResponse(fr *walker.FetchResults)

type MockRemoteServer

type MockRemoteServer struct {
	*MockHTTPHandler
	// contains filtered or unexported fields
}

MockRemoteServer wraps MockHTTPHandler to start a fake server for the user. Use `NewMockRemoteServer()`

func NewMockRemoteServer

func NewMockRemoteServer() (*MockRemoteServer, error)

NewMockRemoteServer starts a server listening on port 80. It wraps MockHTTPHandler so mock return values can be set. Stop should be called at the end of the test to stop the server.

func (*MockRemoteServer) Stop

func (rs *MockRemoteServer) Stop()

type MockResponse

type MockResponse struct {
	// Status defaults to 200
	Status int

	// Status defaults to "GET"
	Method string

	// Body defaults to nil (no response body)
	Body string

	//ContentType defaults to "text/html"
	ContentType string
}

MockResponse is the source object used to build fake responses in MockHTTPHandler.

Jump to

Keyboard shortcuts

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