gofight: github.com/appleboy/gofight Index | Files | Directories

package gofight

import "github.com/appleboy/gofight"

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

Package Files

gofight.go

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

func TestRequest Uses

func TestRequest(t *testing.T, url string)

TestRequest is testing url string if server is running

type D Uses

type D map[string]interface{}

D is HTTP Data Type

type H Uses

type H map[string]string

H is HTTP Header Type

type HTTPRequest Uses

type HTTPRequest *http.Request

HTTPRequest is basic HTTP request type

type HTTPResponse Uses

type HTTPResponse *httptest.ResponseRecorder

HTTPResponse is basic HTTP response type

type RequestConfig Uses

type RequestConfig struct {
    Method      string
    Path        string
    Body        string
    Headers     H
    Cookies     H
    Debug       bool
    ContentType string
}

RequestConfig provide user input request structure

func New Uses

func New() *RequestConfig

New supply initial structure

func (*RequestConfig) DELETE Uses

func (rc *RequestConfig) DELETE(path string) *RequestConfig

DELETE is request method.

func (*RequestConfig) GET Uses

func (rc *RequestConfig) GET(path string) *RequestConfig

GET is request method.

func (*RequestConfig) HEAD Uses

func (rc *RequestConfig) HEAD(path string) *RequestConfig

HEAD is request method.

func (*RequestConfig) OPTIONS Uses

func (rc *RequestConfig) OPTIONS(path string) *RequestConfig

OPTIONS is request method.

func (*RequestConfig) PATCH Uses

func (rc *RequestConfig) PATCH(path string) *RequestConfig

PATCH is request method.

func (*RequestConfig) POST Uses

func (rc *RequestConfig) POST(path string) *RequestConfig

POST is request method.

func (*RequestConfig) PUT Uses

func (rc *RequestConfig) PUT(path string) *RequestConfig

PUT is request method.

func (*RequestConfig) Run Uses

func (rc *RequestConfig) Run(r http.Handler, response ResponseFunc)

Run execute http request

func (*RequestConfig) SetBody Uses

func (rc *RequestConfig) SetBody(body string) *RequestConfig

SetBody supply raw body.

func (*RequestConfig) SetCookie Uses

func (rc *RequestConfig) SetCookie(cookies H) *RequestConfig

SetCookie supply cookies what you defined.

func (*RequestConfig) SetDebug Uses

func (rc *RequestConfig) SetDebug(enable bool) *RequestConfig

SetDebug supply enable debug mode.

func (*RequestConfig) SetFileFromPath Uses

func (rc *RequestConfig) SetFileFromPath(uploads []UploadFile, params ...H) *RequestConfig

SetFileFromPath upload new file.

func (*RequestConfig) SetForm Uses

func (rc *RequestConfig) SetForm(body H) *RequestConfig

SetForm supply form body.

func (*RequestConfig) SetHeader Uses

func (rc *RequestConfig) SetHeader(headers H) *RequestConfig

SetHeader supply http header what you defined.

func (*RequestConfig) SetJSON Uses

func (rc *RequestConfig) SetJSON(body D) *RequestConfig

SetJSON supply JSON body.

func (*RequestConfig) SetJSONInterface Uses

func (rc *RequestConfig) SetJSONInterface(body interface{}) *RequestConfig

SetJSONInterface supply JSON body

func (*RequestConfig) SetQuery Uses

func (rc *RequestConfig) SetQuery(query H) *RequestConfig

SetQuery supply query string.

type ResponseFunc Uses

type ResponseFunc func(HTTPResponse, HTTPRequest)

ResponseFunc response handling func type

type UploadFile Uses

type UploadFile struct {
    Path    string
    Name    string
    Content []byte
}

UploadFile for upload file struct

Directories

PathSynopsis
example
framework

Package gofight imports 16 packages (graph). Updated 2019-04-17. Refresh now. Tools for package owners.