Documentation ¶
Index ¶
Constants ¶
const ( // TypeText represents golden file text body type (default). TypeText = "text" // TypeJSON represents golden file JSON body type. TypeJSON = "json" )
Golden file body type.
Variables ¶
var ErrUnknownUnmarshaler = errors.New("unknown unmarshaler")
ErrUnknownUnmarshaler represents an error when unmarshaler for golden file body cannot be found.
Functions ¶
Types ¶
type Exchange ¶ added in v0.0.14
type Exchange struct { // HTTP request. Request *Request `yaml:"request"` // HTTP response. Response *Response `yaml:"response"` // contains filtered or unexported fields }
Exchange represents HTTP request / response exchange.
func NewExchange ¶ added in v0.0.17
NewExchange returns new instance of HTTP request / response Exchange.
type File ¶ added in v0.0.14
type File struct { Meta map[string]interface{} `yaml:"meta,omitempty"` BodyType string `yaml:"bodyType"` Body string `yaml:"body"` // contains filtered or unexported fields }
File represents golden file with body and body type.
func (*File) Assert ¶ added in v0.0.17
Assert asserts file body matches data. It chooses the bast way to compare two byte slices based on body type. For example when comparing JSON both byte slices don't have to be identical but they must represent the same data.
type Map ¶ added in v0.0.7
type Map map[string]interface{}
Map is a helper type for constructing template data.
type Request ¶ added in v0.0.2
type Request struct { Scheme string `yaml:"scheme"` Method string `yaml:"method"` Path string `yaml:"path"` Query string `yaml:"query"` Headers []string `yaml:"headers"` BodyType string `yaml:"bodyType"` Body string `yaml:"body"` Meta map[string]interface{} `yaml:"meta,omitempty"` // contains filtered or unexported fields }
Request represents golden file for HTTP request.
func NewRequest ¶ added in v0.0.2
NewRequest returns new instance of Request.
func (*Request) Assert ¶ added in v0.0.8
Assert asserts request matches the golden file.
All headers defined in the golden file must match exactly but passed request may have more headers than defined in the golden file.
To compare request bodies the method best for defined body type is used. For example when comparing JSON bodies both byte slices don't have to be identical, but they must represent the same data.
type Response ¶ added in v0.0.6
type Response struct { StatusCode int `yaml:"statusCode"` Headers []string `yaml:"headers"` BodyType string `yaml:"bodyType"` Body string `yaml:"body"` Meta map[string]interface{} `yaml:"meta,omitempty"` // contains filtered or unexported fields }
Response represents golden file for HTTP response.
func NewResponse ¶ added in v0.2.0
NewResponse returns new instance of Response.
func (*Response) Assert ¶ added in v0.0.8
Assert asserts response matches the golden file.
All headers defined in the golden file must match exactly but passed response may have more headers then defined in the golden file.
To compare response bodies a method best suited for body type is used. For example when comparing JSON bodies both byte slices don't have to be identical but they must represent the same data.
type T ¶ added in v0.0.2
type T interface { // Fatal is equivalent to Log followed by FailNow. Fatal(args ...interface{}) // Fatalf is equivalent to Logf followed by FailNow. Fatalf(format string, args ...interface{}) // Helper marks the calling function as a test helper function. // When printing file and line information, that function will be skipped. // Helper may be called simultaneously from multiple goroutines. Helper() }
T is a subset of testing.TB interface. It's primarily used to test golden package but can be used to implement custom actions to be taken on errors.
func Open ¶ added in v0.0.2
Open reads golden file pointed by pth and returns it as a byte slice.
If data is not nil the golden file pointed by pth is treated as a template and applies a parsed template to the specified data object.
You can set template action delimiters using TplDelims function:
Open(t, "golden.yml", data, TplDelims("[[", "]]"))