Documentation ¶
Index ¶
- type APIHTTPClientSuite
- func (s *APIHTTPClientSuite) SetError(c *gc.C, msg string, status int)
- func (s *APIHTTPClientSuite) SetFailure(c *gc.C, msg string, status int)
- func (s *APIHTTPClientSuite) SetJSONSuccess(c *gc.C, result interface{})
- func (s *APIHTTPClientSuite) SetResponse(c *gc.C, status int, data []byte, ctype string)
- type APIMethodSuite
- type FakeClient
- func (f *FakeClient) CheckCalled(c *gc.C, path string, args interface{}, calls ...string)
- func (f *FakeClient) CheckCalledReader(c *gc.C, path string, attached io.Reader, meta interface{}, name string, ...)
- func (f *FakeClient) SendHTTPRequest(path string, args interface{}) (*http.Request, *http.Response, error)
- func (f *FakeClient) SendHTTPRequestReader(path string, attached io.Reader, meta interface{}, name string) (*http.Request, *http.Response, error)
- type FakeHTTPClient
- type HTTPSuite
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIHTTPClientSuite ¶
type APIHTTPClientSuite struct { testing.BaseSuite // FakeClient is the fake API HTTP Client that may be used in testing. FakeClient FakeClient }
APIHTTPClientSuite wraps a fake API HTTP client (see api/http.go). It provides methods for setting the response the client will return.
func (*APIHTTPClientSuite) SetError ¶
func (s *APIHTTPClientSuite) SetError(c *gc.C, msg string, status int)
SetError sets an error response on the fake client. A content-type of application/octet-stream is used. The provided message is set as the body of the response. Any status code less than 0 is replaced with http.StatusInternalServerError (500).
func (*APIHTTPClientSuite) SetFailure ¶
func (s *APIHTTPClientSuite) SetFailure(c *gc.C, msg string, status int)
SetFailure sets a failure response on the fake client. The provided message is packed into an apiserver/params.Error. That error is then set as the body of the response. The content-type is thus application/json.
func (*APIHTTPClientSuite) SetJSONSuccess ¶
func (s *APIHTTPClientSuite) SetJSONSuccess(c *gc.C, result interface{})
SetJSONSuccess sets a success response on the fake client. The provided result is JSON-encoded and set as the body of the response. The content-type is thus application/json. A status code of http.StatusOK (200) is used.
func (*APIHTTPClientSuite) SetResponse ¶
SetResponse sets the HTTP response on the fake client using the provided values. The data is set as the body of the response.
type APIMethodSuite ¶
type APIMethodSuite struct { HTTPSuite // HTTPMethod is the HTTP method to use for the suite. HTTPMethod string // Name is the name of the API method. Name string }
APIMethodSuite provides testing functionality for specific API methods.
func (*APIMethodSuite) CheckRequest ¶
func (s *APIMethodSuite) CheckRequest(c *gc.C, req *http.Request)
CheckRequest verifies that the HTTP request matches the args as an API request should. We only check API-related request fields.
type FakeClient ¶
type FakeClient struct { // Error is the error that will be returned for any calls. Error error // Request is the request returned from calls. Request *http.Request // Response is the response returned from calls. Response *http.Response // contains filtered or unexported fields }
func (*FakeClient) CheckCalled ¶
func (f *FakeClient) CheckCalled(c *gc.C, path string, args interface{}, calls ...string)
CheckCalled checks that the fake was called properly.
func (*FakeClient) CheckCalledReader ¶
func (f *FakeClient) CheckCalledReader(c *gc.C, path string, attached io.Reader, meta interface{}, name string, calls ...string)
CheckCalledReader checks that the fake was called properly.
func (*FakeClient) SendHTTPRequest ¶
type FakeHTTPClient ¶
type FakeHTTPClient struct { // Error is the error that will be returned for any calls. Error error // Response is the response returned from calls. Response *http.Response // Calls is the record of which methods were called. Calls []string // RequestArg is the request that was passed to a call. RequestArg *http.Request }
FakeHTTPClient is used in testing in place of an actual http.Client.
func NewFakeHTTPClient ¶
func NewFakeHTTPClient() *FakeHTTPClient
NewFakeHTTPClient returns a fake with Response set to an OK status, no headers, and no body.
func (*FakeHTTPClient) CheckCalled ¶
CheckCalled checks that the Do was called once with the request and returned the correct value.
type HTTPSuite ¶
type HTTPSuite struct { testing.BaseSuite // Fake is the fake HTTP client used in tests. Fake *FakeHTTPClient // Hostname is the API server's hostname. Hostname string // Username is the username to use for API connections. Username string // Password is the password to use for API connections. Password string }
HTTPSuite provides basic testing capability for API HTTP tests.
func (*HTTPSuite) CheckRequest ¶
CheckRequest verifies that the HTTP request matches the args as an API request should. We only check API-related request fields.