Documentation ¶
Overview ¶
Package aphtest provides common constants and functions for unit testing
Index ¶
- Constants
- func APIServer() string
- func IndentJSON(b []byte) []byte
- func MatchJSON(actual []byte, data interface{}) error
- type ExpectBuilder
- type HTTPExpectBuilder
- type HTTPRequestBuilder
- func (b *HTTPRequestBuilder) AddFieldSets(resource string, relationship bool, fields ...string) RequestBuilder
- func (b *HTTPRequestBuilder) AddFilter(column, text string) RequestBuilder
- func (b *HTTPRequestBuilder) AddIncludes(relationships ...string) RequestBuilder
- func (b *HTTPRequestBuilder) AddPagination(page, entries int) RequestBuilder
- func (b *HTTPRequestBuilder) AddRouterParam(key, value string) RequestBuilder
- func (b *HTTPRequestBuilder) Expect() ResponseBuilder
- type HTTPResponseBuilder
- type Reporter
- type RequestBuilder
- type Resource
- type ResponseBuilder
- type TestAPIInfo
Constants ¶
const ( // APIHost is the default http host for testing APIHost = "https://api.dictybase.org" // PathPrefix is the default prefix for appending to the API host PathPrefix = "1.0" // PubID is publication id for testing PubID = "99" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ExpectBuilder ¶
type ExpectBuilder interface { Get(string) RequestBuilder GetAll(string) RequestBuilder }
ExpectBuilder interface is for incremental building of http configuration
func NewHTTPExpectBuilder ¶
func NewHTTPExpectBuilder(rep Reporter, host string, rs Resource) ExpectBuilder
NewHTTPExpectBuilder is the constructor for HTTPExpectBuilder
type HTTPExpectBuilder ¶
type HTTPExpectBuilder struct {
// contains filtered or unexported fields
}
HTTPExpectBuilder implements ExpectBuilder interface
func (*HTTPExpectBuilder) Get ¶
func (b *HTTPExpectBuilder) Get(path string) RequestBuilder
Get configures Request to execute a http GET request
func (*HTTPExpectBuilder) GetAll ¶
func (b *HTTPExpectBuilder) GetAll(path string) RequestBuilder
GetAll configures Request to execute a http GET request to a collection resource
type HTTPRequestBuilder ¶
type HTTPRequestBuilder struct {
// contains filtered or unexported fields
}
HTTPRequestBuilder implements RequestBuilder interface
func (*HTTPRequestBuilder) AddFieldSets ¶
func (b *HTTPRequestBuilder) AddFieldSets(resource string, relationship bool, fields ...string) RequestBuilder
AddFieldSets adds sparse fieldsets of JSONAPI in the http request context
func (*HTTPRequestBuilder) AddFilter ¶
func (b *HTTPRequestBuilder) AddFilter(column, text string) RequestBuilder
AddFilter adds JSONAPI filter query parameters in the http request context
func (*HTTPRequestBuilder) AddIncludes ¶
func (b *HTTPRequestBuilder) AddIncludes(relationships ...string) RequestBuilder
AddIncludes adds relationships includes of JSONAPI in the http request context
func (*HTTPRequestBuilder) AddPagination ¶
func (b *HTTPRequestBuilder) AddPagination(page, entries int) RequestBuilder
AddPagination adds two pagination properties, current page and entries per page in the request context. If the overwrites the existing value
func (*HTTPRequestBuilder) AddRouterParam ¶
func (b *HTTPRequestBuilder) AddRouterParam(key, value string) RequestBuilder
AddRouterParam add key and value to httprouter's parameters
func (*HTTPRequestBuilder) Expect ¶
func (b *HTTPRequestBuilder) Expect() ResponseBuilder
Expect gets the Response object for further testing
type HTTPResponseBuilder ¶
type HTTPResponseBuilder struct {
// contains filtered or unexported fields
}
HTTPResponseBuilder implements ResponseBuilder interface
func (*HTTPResponseBuilder) DumpJSON ¶
func (b *HTTPResponseBuilder) DumpJSON() string
DumpJSON returns the JSON string from the response
func (*HTTPResponseBuilder) JSON ¶
func (b *HTTPResponseBuilder) JSON() *gabs.Container
JSON return a container type for introspecting json response
func (*HTTPResponseBuilder) Status ¶
func (b *HTTPResponseBuilder) Status(status int) ResponseBuilder
Status matches the expected and actual http status
type Reporter ¶
type Reporter interface { Error(...interface{}) Errorf(string, ...interface{}) Fatal(...interface{}) Fatalf(string, ...interface{}) Log(...interface{}) Logf(string, ...interface{}) }
Reporter interface is used for reporting test failures
type RequestBuilder ¶
type RequestBuilder interface { AddRouterParam(string, string) RequestBuilder AddIncludes(...string) RequestBuilder AddPagination(int, int) RequestBuilder AddFieldSets(string, bool, ...string) RequestBuilder AddFilter(string, string) RequestBuilder Expect() ResponseBuilder }
RequestBuilder interface is for incremental building of RequestBuilder to receive a ResponseBuilder object
func NewHTTPRequestBuilder ¶
func NewHTTPRequestBuilder(rep Reporter, req *http.Request, fn http.HandlerFunc) RequestBuilder
NewHTTPRequestBuilder is the constructor for HTTPRequestBuilder
type Resource ¶
type Resource interface { // Gets the database handler GetDbh() *dbr.Connection // Handles the http GET for singular resource Get(http.ResponseWriter, *http.Request) // Handles the http GET for collection resource GetAll(http.ResponseWriter, *http.Request) // Handles the http POST Create(http.ResponseWriter, *http.Request) // Handles the http PATCH Update(http.ResponseWriter, *http.Request) // Handles the http DELETE Delete(http.ResponseWriter, *http.Request) }
Resource is the interface that every http handler have to implement
type ResponseBuilder ¶
type ResponseBuilder interface { JSON() *gabs.Container Status(int) ResponseBuilder DumpJSON() string }
ResponseBuilder interface is for incremental testing of http response and json object.
func NewHTTPResponseBuilder ¶
func NewHTTPResponseBuilder(rep Reporter, w *httptest.ResponseRecorder) ResponseBuilder
NewHTTPResponseBuilder is the constructor for HTTPResponseBuilder
type TestAPIInfo ¶
TestAPIInfo implements jsonapi.ServerInformation
func NewTestApiInfo ¶
func NewTestApiInfo() *TestAPIInfo
NewTestApiInfo is a constructor for TestAPIInfo
func (*TestAPIInfo) GetBaseURL ¶
func (server *TestAPIInfo) GetBaseURL() string
GetBaseURL returns the base path of the api
func (*TestAPIInfo) GetPrefix ¶
func (server *TestAPIInfo) GetPrefix() string
GetPrefix returns generic prefix for each api path