testing

package
v0.0.0-...-f19ae85 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2015 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

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

func (s *APIHTTPClientSuite) SetResponse(c *gc.C, status int, data []byte, ctype string)

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

func (f *FakeClient) SendHTTPRequest(path string, args interface{}) (*http.Request, *http.Response, error)

func (*FakeClient) SendHTTPRequestReader

func (f *FakeClient) SendHTTPRequestReader(path string, attached io.Reader, meta interface{}, name string) (*http.Request, *http.Response, error)

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

func (f *FakeHTTPClient) CheckCalled(c *gc.C, req *http.Request, resp *http.Response)

CheckCalled checks that the Do was called once with the request and returned the correct value.

func (*FakeHTTPClient) Do

func (f *FakeHTTPClient) Do(req *http.Request) (*http.Response, error)

Do fakes the behavior of http.Client.Do().

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

func (s *HTTPSuite) CheckRequest(c *gc.C, req *http.Request, method, path string)

CheckRequest verifies that the HTTP request matches the args as an API request should. We only check API-related request fields.

func (*HTTPSuite) SetUpTest

func (s *HTTPSuite) SetUpTest(c *gc.C)

Jump to

Keyboard shortcuts

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