Documentation ¶
Index ¶
- Constants
- func CheckJSON(data interface{}, excluded *Exclusion) (interface{}, error)
- func CheckResponsePayload(data []byte) ([]byte, error)
- func DeriveURLValsFromJSONMap(payload []byte) (url.Values, error)
- func GetFilteredHeader(res *http.Response) (http.Header, error)
- func GetFilteredURLVals(vals url.Values) (string, error)
- func HTTPRecord(res *http.Response, service string, respContents []byte) error
- func IsExcluded(key string, excludedVars []string) bool
- func MatchAndGetResponse(mockData []HTTPResponse, requestVals url.Values, isQueryData bool) (json.RawMessage, error)
- func MatchURLVals(v1, v2 url.Values) bool
- func MessageWriteJSON(w http.ResponseWriter, status int, data interface{})
- func NewVCRServer(path string) (string, *http.Client, error)
- func RegisterHandler(pattern string, mock map[string][]HTTPResponse, mux *http.ServeMux)
- type Exclusion
- type HTTPResponse
- type VCRMock
Constants ¶
const ( Int64 = "int64" Float64 = "float64" Slice = "slice" String = "string" Bool = "bool" Invalid = "invalid" )
Reflection consts
const DefaultDirectory = "../../testdata/http_mock/"
DefaultDirectory defines the main mock directory
Variables ¶
This section is empty.
Functions ¶
func CheckResponsePayload ¶
CheckResponsePayload checks to see if there are any response body variables that should not be there.
func DeriveURLValsFromJSONMap ¶
DeriveURLValsFromJSONMap gets url vals from a map[string]string encoded JSON body
func GetFilteredHeader ¶
GetFilteredHeader filters excluded http headers for insertion into a mock test file
func GetFilteredURLVals ¶
GetFilteredURLVals filters excluded url value variables for insertion into a mock test file
func HTTPRecord ¶
HTTPRecord will record the request and response to a default JSON file for mocking purposes
func IsExcluded ¶
IsExcluded cross references the key with the excluded variables
func MatchAndGetResponse ¶
func MatchAndGetResponse(mockData []HTTPResponse, requestVals url.Values, isQueryData bool) (json.RawMessage, error)
MatchAndGetResponse matches incoming request values with mockdata response values and returns the payload
func MatchURLVals ¶
MatchURLVals matches url.Value query strings
func MessageWriteJSON ¶
func MessageWriteJSON(w http.ResponseWriter, status int, data interface{})
MessageWriteJSON writes JSON to a connection
func NewVCRServer ¶
NewVCRServer starts a new VCR server for replaying HTTP requests for testing purposes and returns the server connection details
func RegisterHandler ¶
func RegisterHandler(pattern string, mock map[string][]HTTPResponse, mux *http.ServeMux)
RegisterHandler registers a generalised mock response logic for specific routes
Types ¶
type Exclusion ¶
Exclusion defines a list of items to be excluded from the main mock output this attempts a catch all approach and needs to be updated per exchange basis
func GetExcludedItems ¶
GetExcludedItems checks to see if the variable is in the exclusion list as to not display secure items in mock file generator output
type HTTPResponse ¶
type HTTPResponse struct { Data json.RawMessage `json:"data"` QueryString string `json:"queryString"` BodyParams string `json:"bodyParams"` Headers map[string][]string `json:"headers"` }
HTTPResponse defines expected response from the end point including request data for pathing on the VCR server
type VCRMock ¶
type VCRMock struct {
Routes map[string]map[string][]HTTPResponse `json:"routes"`
}
VCRMock defines the main mock JSON file and attributes