Documentation ¶
Index ¶
- Constants
- Variables
- type AfterContentFunc
- type AfterJSONFunc
- type AfterTextFunc
- type ExpectFunc
- type Frisby
- func (F *Frisby) AddError(errStr string) *Frisby
- func (F *Frisby) AddFile(filename string) *Frisby
- func (F *Frisby) AddFileByKey(key, filename string) *Frisby
- func (F *Frisby) AfterContent(foo AfterContentFunc) *Frisby
- func (F *Frisby) AfterJSON(foo AfterJSONFunc) *Frisby
- func (F *Frisby) AfterText(foo AfterTextFunc) *Frisby
- func (F *Frisby) BasicAuth(user, passwd string) *Frisby
- func (F *Frisby) Delete(url string) *Frisby
- func (F *Frisby) Error() error
- func (F *Frisby) Errors() []error
- func (F *Frisby) Expect(foo ExpectFunc) *Frisby
- func (F *Frisby) ExpectContent(content string) *Frisby
- func (F *Frisby) ExpectHeader(key, value string) *Frisby
- func (F *Frisby) ExpectJSON(path string, value interface{}) *Frisby
- func (F *Frisby) ExpectJSONLength(path string, length int) *Frisby
- func (F *Frisby) ExpectJSONType(path string, valType reflect.Kind) *Frisby
- func (F *Frisby) ExpectStatus(code int) *Frisby
- func (F *Frisby) Get(url string) *Frisby
- func (F *Frisby) Head(url string) *Frisby
- func (F *Frisby) Options(url string) *Frisby
- func (F *Frisby) Patch(url string) *Frisby
- func (F *Frisby) PauseTest(t time.Duration) *Frisby
- func (F *Frisby) Post(url string) *Frisby
- func (F *Frisby) PrintBody() *Frisby
- func (F *Frisby) PrintGoTestReport() *Frisby
- func (F *Frisby) PrintReport() *Frisby
- func (F *Frisby) Put(url string) *Frisby
- func (F *Frisby) Send() *Frisby
- func (F *Frisby) SetCookie(key, value string) *Frisby
- func (F *Frisby) SetCookies(cookies map[string]string) *Frisby
- func (F *Frisby) SetData(key, value string) *Frisby
- func (F *Frisby) SetDatas(datas map[string]string) *Frisby
- func (F *Frisby) SetHeader(key, value string) *Frisby
- func (F *Frisby) SetHeaders(headers map[string]string) *Frisby
- func (F *Frisby) SetJSON(json interface{}) *Frisby
- func (F *Frisby) SetParam(key, value string) *Frisby
- func (F *Frisby) SetParams(params map[string]string) *Frisby
- func (F *Frisby) SetProxy(url string) *Frisby
Examples ¶
Constants ¶
const DefaultPathSeparator = "."
DefaultPathSeparator is the default path separator
Variables ¶
var Global globalData
Global stores information used in multiple requests
Functions ¶
This section is empty.
Types ¶
type AfterContentFunc ¶
AfterContentFunc function type used as argument to AfterContent()
type AfterJSONFunc ¶
AfterJSONFunc function type used as argument to AfterJSON()
type AfterTextFunc ¶
AfterTextFunc function type used as argument to AfterText()
type ExpectFunc ¶
ExpectFunc function type used as argument to Expect()
type Frisby ¶
type Frisby struct { Name string URL string Method string Req *request.Request Resp *request.Response Errs []error ExecutionTime float64 }
Frisby holds request/response
func Create ¶
Create creates a new Frisby object with the given name.
The given name will be used if you call PrintReport()
func (*Frisby) AddFileByKey ¶
AddFileByKey adds a file to the Form data for the coming request
func (*Frisby) AfterContent ¶
func (F *Frisby) AfterContent(foo AfterContentFunc) *Frisby
AfterContent allows you to write your own functions for inspecting the body of the response. You are also provided with the Frisby object.
The function signiture is AfterContentFunc
type AfterContentFunc func(F *Frisby, content []byte, err error)
func (*Frisby) AfterJSON ¶
func (F *Frisby) AfterJSON(foo AfterJSONFunc) *Frisby
AfterJSON allows you to write your own functions for inspecting the body of the response. You are also provided with the Frisby object.
The function signiture is AfterJSONFunc
type AfterJSONFunc func(F *Frisby, json *simplejson.Json, err error)
simplejson docs: https://github.com/bitly/go-simplejson
Example ¶
frisby.Create("Test AfterJSON"). Post("http://httpbin.org/post"). Send(). ExpectStatus(200). AfterJSON(func(F *frisby.Frisby, json *simplejson.Json, err error) { val, _ := json.Get("url").String() fmt.Println("url =", val) })
Output: url = http://httpbin.org/post
func (*Frisby) AfterText ¶
func (F *Frisby) AfterText(foo AfterTextFunc) *Frisby
AfterText allows you to write your own functions for inspecting the body of the response. You are also provided with the Frisby object.
The function signiture is AfterTextFunc
type AfterTextFunc func(F *Frisby, text string, err error)
func (*Frisby) Error ¶
Error gets the most recent error for the Frisby object
This function should be called last
func (*Frisby) Errors ¶
Errors gets all errors for the Frisby object
This function should be called last
func (*Frisby) Expect ¶
func (F *Frisby) Expect(foo ExpectFunc) *Frisby
Expect checks according to the given function, which allows you to describe any kind of assertion.
func (*Frisby) ExpectContent ¶
ExpectContent checks the response body for the given string
func (*Frisby) ExpectHeader ¶
ExpectHeader checks for header and if values match
func (*Frisby) ExpectJSON ¶
ExpectJSON uses the reflect.DeepEqual to compare the response JSON and the supplied JSON for structural and value equality
path can be a dot joined field names. ex: 'path.to.subobject.field'
Example ¶
package main import ( "github.com/EducationPlannerBC/frisby" ) func main() { frisby.Create("Test ExpectJSON"). Post("http://httpbin.org/post"). Send(). ExpectStatus(200). ExpectJSON("url", "http://httpbin.org/post"). ExpectJSON("headers.Accept", "*/*"). PrintReport() }
Output: Pass [Test ExpectJSON]
func (*Frisby) ExpectJSONLength ¶
ExpectJSONLength checks if the JSON at path is an array and has the correct length
path can be a dot joined field names. ex: 'path.to.subobject.field'
func (*Frisby) ExpectJSONType ¶
ExpectJSONType checks if the types of the response JSON and the supplied JSON match
path can be a dot joined field names. ex: 'path.to.subobject.field'
Example ¶
package main import ( "reflect" "github.com/EducationPlannerBC/frisby" ) func main() { frisby.Create("Test ExpectJSONType"). Post("http://httpbin.org/post"). Send(). ExpectStatus(200). ExpectJSONType("url", reflect.String). PrintReport() }
Output: Pass [Test ExpectJSONType]
func (*Frisby) ExpectStatus ¶
ExpectStatus checks the response status code
func (*Frisby) Get ¶
Get sets the HTTP method to GET for the given URL
Example ¶
package main import ( "github.com/EducationPlannerBC/frisby" ) func main() { frisby.Create("Test GET Go homepage"). Get("http://golang.org"). Send(). ExpectStatus(200). ExpectContent("The Go Programming Language"). PrintReport() }
Output: Pass [Test GET Go homepage]
func (*Frisby) Post ¶
Post sets the HTTP method to POST for the given URL
Example ¶
package main import ( "github.com/EducationPlannerBC/frisby" ) func main() { frisby.Create("Test POST"). Post("http://httpbin.org/post"). SetData("test_key", "test_value"). Send(). ExpectStatus(200). PrintReport() }
Output: Pass [Test POST]
func (*Frisby) PrintGoTestReport ¶
PrintGoTestReport prints a report for the Frisby Object in go_test format
If there are any errors, they will all be printed as well
func (*Frisby) PrintReport ¶
PrintReport prints a report for the Frisby Object
If there are any errors, they will all be printed as well
Example ¶
package main import ( "github.com/EducationPlannerBC/frisby" ) func main() { frisby.Create("Test GET Go homepage"). Get("http://golang.org"). Send(). ExpectStatus(400). ExpectContent("A string which won't be found"). AddError("Manually Added Error"). PrintReport() }
Output: FAIL [Test GET Go homepage] - Expected Status 400, but got 200: "200 OK" - Expected Body to contain "A string which won't be found", but it was missing - Manually Added Error
func (*Frisby) SetCookies ¶
SetCookies sets several Cookie values for the coming request
func (*Frisby) SetHeaders ¶
SetHeaders sets several Headers for the coming request