abtest

package
v0.0.0-...-83625b3 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2018 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func Connect(schema string) db.DB

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 GetConfig

func GetConfig(logger log.Logger, host string) *config.Store

func GetConfigForMiddleware

func GetConfigForMiddleware(logger log.Logger) *config.Store

func GetLogger

func GetLogger() log.Logger

func Hop

func Hop(setup SetupFunc) (string, func() *TestClient)

func HopMock

func HopMock(setup SetupFunc) (string, func() *TestClient)

func NewRequest

func NewRequest(method, url string, body io.Reader) (*http.Request, error)

func SetupConfigMiddleware

func SetupConfigMiddleware() (log.Logger, *config.Store, *configmw.ConfigMiddleware)

func TestMiddleware

func TestMiddleware(stack *middleware.Stack, handler http.HandlerFunc) *httptest.ResponseRecorder

Types

type DataMockerFunc

type DataMockerFunc func(db.DB) error

type HTTPClientDelegate

type HTTPClientDelegate struct {
	*http.Client
}

func (*HTTPClientDelegate) NewRequest

func (d *HTTPClientDelegate) NewRequest(method, target string, body io.Reader) *http.Request

type MockDelegate

type MockDelegate struct {
	// contains filtered or unexported fields
}

func NewMockDelegate

func NewMockDelegate(base string, handler http.Handler) *MockDelegate

func (*MockDelegate) Do

func (c *MockDelegate) Do(r *http.Request) (*http.Response, error)

func (*MockDelegate) NewRequest

func (c *MockDelegate) NewRequest(method, target string, body io.Reader) *http.Request

type SchemaInfo

type SchemaInfo interface {
	SetSearchPath(db.DB)
	GetSchemaName() string
}

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)

func (*SchemaMiddleware) Wrap

func (m *SchemaMiddleware) Wrap(next http.Handler) http.Handler

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 TestClientDelegate interface {
	Do(*http.Request) (*http.Response, error)
	NewRequest(method, target string, body io.Reader) *http.Request
}

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.

Jump to

Keyboard shortcuts

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