Documentation ¶
Overview ¶
Copyright 2019 ascendsoftware, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- func RegisterResponseHandler(mime string, handler ResponseHandler)
- type CompletedRequest
- type RequestBuilder
- func (r *RequestBuilder) Delete(path string) *RequestBuilder
- func (r *RequestBuilder) Get(path string) *RequestBuilder
- func (r *RequestBuilder) Go(t *testing.T, e *echo.Echo) *CompletedRequest
- func (r *RequestBuilder) GoWithHTTPHandler(t *testing.T, handler http.Handler) *CompletedRequest
- func (r *RequestBuilder) Patch(path string) *RequestBuilder
- func (r *RequestBuilder) Post(path string) *RequestBuilder
- func (r *RequestBuilder) Put(path string) *RequestBuilder
- func (r *RequestBuilder) WithAccept(value string) *RequestBuilder
- func (r *RequestBuilder) WithAcceptJson() *RequestBuilder
- func (r *RequestBuilder) WithBody(body []byte) *RequestBuilder
- func (r *RequestBuilder) WithContentType(value string) *RequestBuilder
- func (r *RequestBuilder) WithCookie(c *http.Cookie) *RequestBuilder
- func (r *RequestBuilder) WithCookieNameValue(name, value string) *RequestBuilder
- func (r *RequestBuilder) WithHeader(header, value string) *RequestBuilder
- func (r *RequestBuilder) WithHost(value string) *RequestBuilder
- func (r *RequestBuilder) WithJWSAuth(jws string) *RequestBuilder
- func (r *RequestBuilder) WithJsonBody(obj interface{}) *RequestBuilder
- func (r *RequestBuilder) WithJsonContentType() *RequestBuilder
- func (r *RequestBuilder) WithMethod(method string, path string) *RequestBuilder
- type ResponseHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterResponseHandler ¶
func RegisterResponseHandler(mime string, handler ResponseHandler)
Types ¶
type CompletedRequest ¶
type CompletedRequest struct { Recorder *httptest.ResponseRecorder // When set to true, decoders will be more strict. In the default JSON // recorder, unknown fields will cause errors. Strict bool }
CompletedRequest is the result of calling Go() on the request builder. We're wrapping the ResponseRecorder with some nice helper functions.
func (*CompletedRequest) Code ¶
func (c *CompletedRequest) Code() int
Code is a shortcut for response code
func (*CompletedRequest) DisallowUnknownFields ¶
func (c *CompletedRequest) DisallowUnknownFields()
func (*CompletedRequest) UnmarshalBodyToObject ¶
func (c *CompletedRequest) UnmarshalBodyToObject(obj interface{}) error
UnmarshalBodyToObject takes a destination object as input, and unmarshals the object in the response based on the Content-Type header.
func (*CompletedRequest) UnmarshalJsonToObject ¶
func (c *CompletedRequest) UnmarshalJsonToObject(obj interface{}) error
UnmarshalJsonToObject assumes that the response contains JSON and unmarshals it into the specified object.
type RequestBuilder ¶
type RequestBuilder struct { Method string Path string Headers map[string]string Body []byte Error error Cookies []*http.Cookie }
RequestBuilder caches request settings as we build up the request.
func NewRequest ¶
func NewRequest() *RequestBuilder
func (*RequestBuilder) Delete ¶
func (r *RequestBuilder) Delete(path string) *RequestBuilder
func (*RequestBuilder) Get ¶
func (r *RequestBuilder) Get(path string) *RequestBuilder
func (*RequestBuilder) Go ¶
func (r *RequestBuilder) Go(t *testing.T, e *echo.Echo) *CompletedRequest
Go performs the request, it takes a pointer to a testing context to print messages, and a pointer to an echo context for request handling.
func (*RequestBuilder) GoWithHTTPHandler ¶
func (r *RequestBuilder) GoWithHTTPHandler(t *testing.T, handler http.Handler) *CompletedRequest
GoWithHTTPHandler performs the request, it takes a pointer to a testing context to print messages, and a http handler for request handling.
func (*RequestBuilder) Patch ¶
func (r *RequestBuilder) Patch(path string) *RequestBuilder
func (*RequestBuilder) Post ¶
func (r *RequestBuilder) Post(path string) *RequestBuilder
func (*RequestBuilder) Put ¶
func (r *RequestBuilder) Put(path string) *RequestBuilder
func (*RequestBuilder) WithAccept ¶
func (r *RequestBuilder) WithAccept(value string) *RequestBuilder
func (*RequestBuilder) WithAcceptJson ¶
func (r *RequestBuilder) WithAcceptJson() *RequestBuilder
func (*RequestBuilder) WithBody ¶
func (r *RequestBuilder) WithBody(body []byte) *RequestBuilder
func (*RequestBuilder) WithContentType ¶
func (r *RequestBuilder) WithContentType(value string) *RequestBuilder
func (*RequestBuilder) WithCookie ¶
func (r *RequestBuilder) WithCookie(c *http.Cookie) *RequestBuilder
WithCookie sets a cookie
func (*RequestBuilder) WithCookieNameValue ¶
func (r *RequestBuilder) WithCookieNameValue(name, value string) *RequestBuilder
func (*RequestBuilder) WithHeader ¶
func (r *RequestBuilder) WithHeader(header, value string) *RequestBuilder
WithHeader sets a header
func (*RequestBuilder) WithHost ¶
func (r *RequestBuilder) WithHost(value string) *RequestBuilder
func (*RequestBuilder) WithJWSAuth ¶
func (r *RequestBuilder) WithJWSAuth(jws string) *RequestBuilder
func (*RequestBuilder) WithJsonBody ¶
func (r *RequestBuilder) WithJsonBody(obj interface{}) *RequestBuilder
WithJsonBody takes an object as input, marshals it to JSON, and sends it as the body with Content-Type: application/json
func (*RequestBuilder) WithJsonContentType ¶
func (r *RequestBuilder) WithJsonContentType() *RequestBuilder
func (*RequestBuilder) WithMethod ¶
func (r *RequestBuilder) WithMethod(method string, path string) *RequestBuilder
WithMethod sets the method and path