Documentation
¶
Overview ¶
Package clienttest provides mock servers for testing.
Index ¶
- func NewMockResolutionClient(t *testing.T, universeYAML string) client.DependencyClient
- type MockHTTPServer
- func (m *MockHTTPServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (m *MockHTTPServer) SetAuthorization(t *testing.T, auth string)
- func (m *MockHTTPServer) SetResponse(t *testing.T, path string, response []byte)
- func (m *MockHTTPServer) SetResponseFromFile(t *testing.T, path string, filename string)
- type ResolutionUniverse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewMockResolutionClient ¶
func NewMockResolutionClient(t *testing.T, universeYAML string) client.DependencyClient
NewMockResolutionClient creates a new mock resolution client from the given universe YAML.
Types ¶
type MockHTTPServer ¶
MockHTTPServer is a simple HTTP Server for mocking basic requests.
func NewMockHTTPServer ¶
func NewMockHTTPServer(t *testing.T) *MockHTTPServer
NewMockHTTPServer starts and returns a new simple HTTP Server for mocking basic requests. The Server will automatically be shut down with Close() in the test Cleanup function.
Use the SetResponse / SetResponseFromFile to set the responses for specific URL paths.
func (*MockHTTPServer) ServeHTTP ¶
func (m *MockHTTPServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP is the http.Handler for the underlying httptest.Server.
func (*MockHTTPServer) SetAuthorization ¶
func (m *MockHTTPServer) SetAuthorization(t *testing.T, auth string)
SetAuthorization sets the contents of the 'Authorization' header the server expects for all endpoints.
The incoming requests' headers must match the auth string exactly, otherwise the server will response with 401 Unauthorized. If authorization is unset or empty, the server will not require authorization.
func (*MockHTTPServer) SetResponse ¶
func (m *MockHTTPServer) SetResponse(t *testing.T, path string, response []byte)
SetResponse sets the Server's response for the URL path to be response bytes.
func (*MockHTTPServer) SetResponseFromFile ¶
func (m *MockHTTPServer) SetResponseFromFile(t *testing.T, path string, filename string)
SetResponseFromFile sets the Server's response for the URL path to be the contents of the file at filename.
type ResolutionUniverse ¶
ResolutionUniverse defines a mock resolution universe.