Documentation ¶
Overview ¶
Package gofight offers simple API http handler testing for Golang framework.
Details about the gofight project are found in github page:
https://github.com/appleboy/gofight
Installation:
$ go get -u github.com/appleboy/gofight
Set Header: You can add custom header via SetHeader func.
SetHeader(gofight.H{ "X-Version": version, })
Set Cookie: You can add custom cookie via SetCookie func.
SetCookie(gofight.H{ "foo": "bar", })
Set query string: Using SetQuery to generate query string data.
SetQuery(gofight.H{ "a": "1", "b": "2", })
POST FORM Data: Using SetForm to generate form data.
SetForm(gofight.H{ "a": "1", "b": "2", })
POST JSON Data: Using SetJSON to generate json data.
SetJSON(gofight.H{ "a": "1", "b": "2", })
POST RAW Data: Using SetBody to generate raw data.
SetBody("a=1&b=1")
For more details, see the documentation and example.
Index ¶
- Constants
- func TestRequest(t *testing.T, url string)
- type D
- type H
- type HTTPRequest
- type HTTPResponse
- type RequestConfig
- func (rc *RequestConfig) DELETE(path string) *RequestConfig
- func (rc *RequestConfig) GET(path string) *RequestConfig
- func (rc *RequestConfig) HEAD(path string) *RequestConfig
- func (rc *RequestConfig) OPTIONS(path string) *RequestConfig
- func (rc *RequestConfig) PATCH(path string) *RequestConfig
- func (rc *RequestConfig) POST(path string) *RequestConfig
- func (rc *RequestConfig) PUT(path string) *RequestConfig
- func (rc *RequestConfig) Run(r http.Handler, response ResponseFunc)
- func (rc *RequestConfig) SetBody(body string) *RequestConfig
- func (rc *RequestConfig) SetCookie(cookies H) *RequestConfig
- func (rc *RequestConfig) SetDebug(enable bool) *RequestConfig
- func (rc *RequestConfig) SetForm(body H) *RequestConfig
- func (rc *RequestConfig) SetHeader(headers H) *RequestConfig
- func (rc *RequestConfig) SetJSON(body D) *RequestConfig
- func (rc *RequestConfig) SetQuery(query H) *RequestConfig
- type ResponseFunc
Constants ¶
const ( Version = "1.0" UserAgent = "User-Agent" ContentType = "Content-Type" ApplicationJSON = "application/json" ApplicationForm = "application/x-www-form-urlencoded" )
Media types
Variables ¶
This section is empty.
Functions ¶
func TestRequest ¶
TestRequest is testing url string if server is running
Types ¶
type HTTPResponse ¶
type HTTPResponse *httptest.ResponseRecorder
HTTPResponse is basic HTTP response type
type RequestConfig ¶
RequestConfig provide user input request structure
func (*RequestConfig) DELETE ¶
func (rc *RequestConfig) DELETE(path string) *RequestConfig
DELETE is request method.
func (*RequestConfig) GET ¶
func (rc *RequestConfig) GET(path string) *RequestConfig
GET is request method.
func (*RequestConfig) HEAD ¶
func (rc *RequestConfig) HEAD(path string) *RequestConfig
HEAD is request method.
func (*RequestConfig) OPTIONS ¶
func (rc *RequestConfig) OPTIONS(path string) *RequestConfig
OPTIONS is request method.
func (*RequestConfig) PATCH ¶
func (rc *RequestConfig) PATCH(path string) *RequestConfig
PATCH is request method.
func (*RequestConfig) POST ¶
func (rc *RequestConfig) POST(path string) *RequestConfig
POST is request method.
func (*RequestConfig) PUT ¶
func (rc *RequestConfig) PUT(path string) *RequestConfig
PUT is request method.
func (*RequestConfig) Run ¶
func (rc *RequestConfig) Run(r http.Handler, response ResponseFunc)
Run execute http request
func (*RequestConfig) SetBody ¶
func (rc *RequestConfig) SetBody(body string) *RequestConfig
SetBody supply raw body.
func (*RequestConfig) SetCookie ¶ added in v1.0.4
func (rc *RequestConfig) SetCookie(cookies H) *RequestConfig
SetCookie supply cookies what you defined.
func (*RequestConfig) SetDebug ¶
func (rc *RequestConfig) SetDebug(enable bool) *RequestConfig
SetDebug supply enable debug mode.
func (*RequestConfig) SetForm ¶ added in v1.0.3
func (rc *RequestConfig) SetForm(body H) *RequestConfig
SetForm supply form body.
func (*RequestConfig) SetHeader ¶
func (rc *RequestConfig) SetHeader(headers H) *RequestConfig
SetHeader supply http header what you defined.
func (*RequestConfig) SetJSON ¶
func (rc *RequestConfig) SetJSON(body D) *RequestConfig
SetJSON supply JSON body.
func (*RequestConfig) SetQuery ¶ added in v1.0.3
func (rc *RequestConfig) SetQuery(query H) *RequestConfig
SetQuery supply query string.
type ResponseFunc ¶
type ResponseFunc func(HTTPResponse, HTTPRequest)
ResponseFunc response handling func type