frisby: github.com/verdverm/frisby Index | Examples | Files | Directories

package frisby

import "github.com/verdverm/frisby"

Index

Examples

Package Files

doc.go expect.go frisby.go global.go

Constants

const DefaultPathSeparator = "."

Variables

var Global global_data

type AfterContentFunc Uses

type AfterContentFunc func(F *Frisby, content []byte, err error)

function type used as argument to AfterContent()

type AfterJsonFunc Uses

type AfterJsonFunc func(F *Frisby, json *simplejson.Json, err error)

function type used as argument to AfterJson()

type AfterTextFunc Uses

type AfterTextFunc func(F *Frisby, text string, err error)

function type used as argument to AfterText()

type ExpectFunc Uses

type ExpectFunc func(F *Frisby) (bool, string)

ExpectFunc function type used as argument to Expect()

type Frisby Uses

type Frisby struct {
    Name   string
    Url    string
    Method string

    Req           *request.Request
    Resp          *request.Response
    Errs          []error
    ExecutionTime float64
}

func Create Uses

func Create(name string) *Frisby

Creates a new Frisby object with the given name.

The given name will be used if you call PrintReport()

func (*Frisby) AddError Uses

func (F *Frisby) AddError(err_str string) *Frisby

Manually add an error, if you need to

func (*Frisby) AddFile Uses

func (F *Frisby) AddFile(filename string) *Frisby

Add a file to the Form data for the coming request

func (*Frisby) AddFileByKey Uses

func (F *Frisby) AddFileByKey(key, filename string) *Frisby

Add a file to the Form data for the coming request

func (*Frisby) AfterContent Uses

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 Uses

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

Code:

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 Uses

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) BasicAuth Uses

func (F *Frisby) BasicAuth(user, passwd string) *Frisby

Set BasicAuth values for the coming request

func (*Frisby) Delete Uses

func (F *Frisby) Delete(url string) *Frisby

Set the HTTP method to DELETE for the given URL

func (*Frisby) Error Uses

func (F *Frisby) Error() error

Get the most recent error for the Frisby object

This function should be called last

func (*Frisby) Errors Uses

func (F *Frisby) Errors() []error

Get all errors for the Frisby object

This function should be called last

func (*Frisby) Expect Uses

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 Uses

func (F *Frisby) ExpectContent(content string) *Frisby

Checks the response body for the given string

func (*Frisby) ExpectHeader Uses

func (F *Frisby) ExpectHeader(key, value string) *Frisby

Checks for header and if values match

func (*Frisby) ExpectJson Uses

func (F *Frisby) ExpectJson(path string, value interface{}) *Frisby

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'

Code:

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 Uses

func (F *Frisby) ExpectJsonLength(path string, length int) *Frisby

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 Uses

func (F *Frisby) ExpectJsonType(path string, val_type reflect.Kind) *Frisby

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'

Code:

frisby.Create("Test ExpectJsonType").
    Post("http://httpbin.org/post").
    Send().
    ExpectStatus(200).
    ExpectJsonType("url", reflect.String).
    PrintReport()

Output:

Pass  [Test ExpectJsonType]

func (*Frisby) ExpectStatus Uses

func (F *Frisby) ExpectStatus(code int) *Frisby

Checks the response status code

func (*Frisby) Get Uses

func (F *Frisby) Get(url string) *Frisby

Set the HTTP method to GET for the given URL

Code:

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) Head Uses

func (F *Frisby) Head(url string) *Frisby

Set the HTTP method to HEAD for the given URL

func (*Frisby) Options Uses

func (F *Frisby) Options(url string) *Frisby

Set the HTTP method to OPTIONS for the given URL

func (*Frisby) Patch Uses

func (F *Frisby) Patch(url string) *Frisby

Set the HTTP method to PATCH for the given URL

func (*Frisby) PauseTest Uses

func (F *Frisby) PauseTest(t time.Duration) *Frisby

Pause your testrun for a defined amount of seconds

func (*Frisby) Post Uses

func (F *Frisby) Post(url string) *Frisby

Set the HTTP method to POST for the given URL

Code:

frisby.Create("Test POST").
    Post("http://httpbin.org/post").
    SetData("test_key", "test_value").
    Send().
    ExpectStatus(200).
    PrintReport()

Output:

Pass  [Test POST]

func (*Frisby) PrintBody Uses

func (F *Frisby) PrintBody() *Frisby

Prints the body of the response

func (*Frisby) PrintGoTestReport Uses

func (F *Frisby) PrintGoTestReport() *Frisby

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 Uses

func (F *Frisby) PrintReport() *Frisby

Prints a report for the Frisby Object

If there are any errors, they will all be printed as well

Code:

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) Put Uses

func (F *Frisby) Put(url string) *Frisby

Set the HTTP method to PUT for the given URL

func (*Frisby) Send Uses

func (F *Frisby) Send() *Frisby

Send the actual request to the URL

func (*Frisby) SetCookie Uses

func (F *Frisby) SetCookie(key, value string) *Frisby

Set a Cookie value for the coming request

func (*Frisby) SetCookies Uses

func (F *Frisby) SetCookies(cookies map[string]string) *Frisby

Set several Cookie values for the coming request

func (*Frisby) SetData Uses

func (F *Frisby) SetData(key, value string) *Frisby

Set a Form data for the coming request

func (*Frisby) SetDatas Uses

func (F *Frisby) SetDatas(datas map[string]string) *Frisby

Set several Form data for the coming request

func (*Frisby) SetHeader Uses

func (F *Frisby) SetHeader(key, value string) *Frisby

Set a Header value for the coming request

func (*Frisby) SetHeaders Uses

func (F *Frisby) SetHeaders(headers map[string]string) *Frisby

Set several Headers for the coming request

func (*Frisby) SetJson Uses

func (F *Frisby) SetJson(json interface{}) *Frisby

Set the JSON body for the coming request

func (*Frisby) SetParam Uses

func (F *Frisby) SetParam(key, value string) *Frisby

Set a url Param for the coming request

func (*Frisby) SetParams Uses

func (F *Frisby) SetParams(params map[string]string) *Frisby

Set several url Param for the coming request

func (*Frisby) SetProxy Uses

func (F *Frisby) SetProxy(url string) *Frisby

Set Proxy URL for the coming request

Directories

PathSynopsis
example

Package frisby imports 11 packages (graph) and is imported by 2 packages. Updated 2018-05-25. Refresh now. Tools for package owners.