Documentation ¶
Index ¶
- Variables
- func Connect(schema string) db.DB
- func GetConfig(logger log.Logger, host string) *config.Store
- func GetConfigForMiddleware(logger log.Logger) *config.Store
- func GetLogger() log.Logger
- func Hop(setup SetupFunc) (string, func() *TestClient)
- func HopMock(setup SetupFunc) (string, func() *TestClient)
- func NewRequest(method, url string, body io.Reader) (*http.Request, error)
- func SetupConfigMiddleware() (log.Logger, *config.Store, *configmw.ConfigMiddleware)
- func TestMiddleware(stack *middleware.Stack, handler http.HandlerFunc) *httptest.ResponseRecorder
- type DataMockerFunc
- type HTTPClientDelegate
- type MockDelegate
- type SchemaInfo
- type SchemaMiddleware
- type SetupFunc
- type TestClient
- func (tc *TestClient) AssertFile(resp *http.Response, path string)
- func (tc *TestClient) AssertJSON(resp *http.Response, v interface{}, matcher types.GomegaMatcher)
- func (tc *TestClient) ConsumePrefix(r *http.Response) bool
- func (tc *TestClient) GetToken()
- func (tc *TestClient) JSONBuffer(v interface{}) io.Reader
- func (tc *TestClient) ReadBody(r *http.Response, JSONPrefix bool) string
- func (tc *TestClient) Request(method, endpoint string, body io.Reader, processReq func(*http.Request), ...)
- type TestClientDelegate
- type TestServer
Constants ¶
This section is empty.
Variables ¶
var ( FakeKey = []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2} FakeAdminKey = "00000000000000000000000000000000" LoggerWriter = ioutil.Discard )
Functions ¶
func Connect ¶
Connect connects to the test database.
If schema is specified, then it sets the search_path. If you want to leave the search_path on its default value, pass an empty string as the schema.
func Hop ¶
func Hop(setup SetupFunc) (string, func() *TestClient)
func HopMock ¶
func HopMock(setup SetupFunc) (string, func() *TestClient)
func SetupConfigMiddleware ¶
func TestMiddleware ¶
func TestMiddleware(stack *middleware.Stack, handler http.HandlerFunc) *httptest.ResponseRecorder
Types ¶
type DataMockerFunc ¶
type HTTPClientDelegate ¶
func (*HTTPClientDelegate) NewRequest ¶
type MockDelegate ¶
type MockDelegate struct {
// contains filtered or unexported fields
}
func NewMockDelegate ¶
func NewMockDelegate(base string, handler http.Handler) *MockDelegate
func (*MockDelegate) NewRequest ¶
type SchemaInfo ¶
func GetSchemaMiddleware ¶
func GetSchemaMiddleware(r *http.Request) SchemaInfo
type SchemaMiddleware ¶
type SchemaMiddleware struct {
// contains filtered or unexported fields
}
func NewSchemaMiddleware ¶
func NewSchemaMiddleware() *SchemaMiddleware
func (*SchemaMiddleware) Dependencies ¶
func (m *SchemaMiddleware) Dependencies() []string
func (*SchemaMiddleware) GetSchemaName ¶
func (m *SchemaMiddleware) GetSchemaName() string
func (*SchemaMiddleware) SetSearchPath ¶
func (m *SchemaMiddleware) SetSearchPath(conn db.DB)
type SetupFunc ¶
type SetupFunc func(conf *config.Store, s *server.Server, dispatcher *event.Dispatcher, base, schema string) (DataMockerFunc, error)
type TestClient ¶
type TestClient struct { Delegate TestClientDelegate Token string // contains filtered or unexported fields }
TestClient is a wrapper on the top of http.Client for integration tests.
func NewHTTPTestClient ¶
func NewHTTPTestClient(base string) *TestClient
NewHTTPTestClient initializes TestClient with *http.Client.
The wrapped http.Client will get an empty cookie jar.
func NewHTTPTestClientWithToken ¶
func NewHTTPTestClientWithToken(base string) *TestClient
NewHTTPTestClientWithToken initializes a TestClient and retrieves a CSRF token.
func NewMockTestClient ¶
func NewMockTestClient(base string, handler http.Handler) *TestClient
func NewMockTestClientWithToken ¶
func NewMockTestClientWithToken(base string, handler http.Handler) *TestClient
func (*TestClient) AssertFile ¶
func (tc *TestClient) AssertFile(resp *http.Response, path string)
AssertFile asserts that the response body is equal to a file.
func (*TestClient) AssertJSON ¶
func (tc *TestClient) AssertJSON(resp *http.Response, v interface{}, matcher types.GomegaMatcher)
AssertJSON decodes the JSON body of the response into v, and matches it with matcher.
Example:
c.Request("GET", "/api/endpoint", nil, nil, func(r *http.Response) { data := &dataType{} c.AssertJSON(resp, data, PointTo(MatchAllFields(Fields{ "Fields": Not(BeZero()), }))) }, http.StatusOK)
func (*TestClient) ConsumePrefix ¶
func (tc *TestClient) ConsumePrefix(r *http.Response) bool
ConsumePrefix consumes the JSONPrefix from the response body.
func (*TestClient) GetToken ¶
func (tc *TestClient) GetToken()
GetToken retrieves the token from the TestServer for TestClient.
func (*TestClient) JSONBuffer ¶
func (tc *TestClient) JSONBuffer(v interface{}) io.Reader
JSONBuffer creates an in-memory buffer of a serialized JSON value.
func (*TestClient) ReadBody ¶
func (tc *TestClient) ReadBody(r *http.Response, JSONPrefix bool) string
ReadBody reads the response body into a string.
func (*TestClient) Request ¶
func (tc *TestClient) Request(method, endpoint string, body io.Reader, processReq func(*http.Request), processResp func(*http.Response), statusCode int)
Request sends a request to a TestServer.
The method and endpoint parameters are mandatory. The body can be nil if the request does not have a body. The prcessReq function can modify the request, but it can be nil. The processResp function can deal with the response, but it can be nil as well. The statusCode parameter is the expected status code.
type TestClientDelegate ¶
type TestServer ¶
type TestServer struct {
Addr string
}
TestServer is a temporary Server for integration tests.
func NewTestServer ¶
func NewTestServer() *TestServer
func (*TestServer) Setup ¶
func (s *TestServer) Setup(setup SetupFunc) (*server.Server, func())
Setup sets up a mock server.
Returns a server and a mocker function. Run the mocker function after installing the schemas.
func (*TestServer) Start ¶
func (s *TestServer) Start(setup SetupFunc) (string, func())
Start starts a Server with test-optimized settings.