Documentation ¶
Index ¶
- func FakeDial(network, addr string) (net.Conn, error)
- func GetFakeTransport() http.RoundTripper
- type MockDatastore
- func (ds *MockDatastore) ClaimNewHost() string
- func (ds *MockDatastore) LinksForHost(domain string) <-chan *walker.URL
- func (ds *MockDatastore) StoreParsedURL(u *walker.URL, fr *walker.FetchResults)
- func (ds *MockDatastore) StoreURLFetchResults(fr *walker.FetchResults)
- func (ds *MockDatastore) UnclaimHost(host string)
- type MockDispatcher
- type MockHTTPHandler
- type MockHandler
- type MockRemoteServer
- type MockResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetFakeTransport ¶
func GetFakeTransport() http.RoundTripper
GetFakeTransport gets a http.RoundTripper that uses FakeDial
Types ¶
type MockDatastore ¶
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 ¶
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 ¶
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.