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
- Variables
- 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) SetFileFromPath(uploads []UploadFile, params ...H) *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) SetJSONInterface(body interface{}) *RequestConfig
- func (rc *RequestConfig) SetQuery(query H) *RequestConfig
- type ResponseFunc
- type UploadFile
Constants ¶
const ( Version = "1.0" UserAgent = "User-Agent" ContentType = "Content-Type" ApplicationJSON = "application/json" ApplicationForm = "application/x-www-form-urlencoded" )
Media types
Variables ¶
var Timeout = time.Second * 10
Timeout for http client see https://medium.com/@nate510/don-t-use-go-s-default-http-client-4804cb19f779
Functions ¶
This section is empty.
Types ¶
type HTTPResponse ¶
type HTTPResponse *httptest.ResponseRecorder
HTTPResponse is basic HTTP response type
type RequestConfig ¶
type RequestConfig struct { Method string Path string Body string Headers H Cookies H Debug bool ContentType string }
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 ¶
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) SetFileFromPath ¶
func (rc *RequestConfig) SetFileFromPath(uploads []UploadFile, params ...H) *RequestConfig
SetFileFromPath upload new file.
func (*RequestConfig) SetForm ¶
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) SetJSONInterface ¶
func (rc *RequestConfig) SetJSONInterface(body interface{}) *RequestConfig
SetJSONInterface supply JSON body
func (*RequestConfig) SetQuery ¶
func (rc *RequestConfig) SetQuery(query H) *RequestConfig
SetQuery supply query string.
type ResponseFunc ¶
type ResponseFunc func(HTTPResponse, HTTPRequest)
ResponseFunc response handling func type
type UploadFile ¶
UploadFile for upload file struct