Documentation ¶
Overview ¶
This package is a library for testing http requests Inspired by supertest on JavaScript ecosystem
Index ¶
- type Tester
- func (tt *Tester) Body(bt []byte) TesterInterface
- func (tt *Tester) Build(t *testing.T) *Tester
- func (tt *Tester) GetBody() interface{}
- func (tt *Tester) GetHeaders() map[string]string
- func (tt *Tester) GetResponse() *http.Response
- func (tt *Tester) GetStatus() int
- func (tt *Tester) GetUrl() string
- func (tt *Tester) Headers(h map[string]string) TesterInterface
- func (tt *Tester) Json(i interface{}) TesterInterface
- func (tt *Tester) Method(m string) TesterInterface
- func (tt *Tester) Query(q map[string]string) TesterInterface
- func (tt *Tester) Status(s int) TesterInterface
- func (tt *Tester) Url(url string) TesterInterface
- func (tt *Tester) ValidateBody() TesterInterface
- type TesterInterface
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Tester ¶
type Tester struct {
// contains filtered or unexported fields
}
func (*Tester) Body ¶
func (tt *Tester) Body(bt []byte) TesterInterface
Using the function from set body from http request
instance.Body([]byte(`{"title": "foo", "body": "bar", "userId": 1}`))
This return an instance of Tester
func (*Tester) Build ¶
This return an instance of Tester expected testing
instance.Method("GET").Url("http://httpbin.org/status/404").Status(404).Build(t)
This return an instance of Tester
func (*Tester) GetHeaders ¶
func (*Tester) GetResponse ¶
func (*Tester) GetUrl ¶
GetUrl return the url of http request
instance.GetUrl() == "http://httpbin.org/get"
func (*Tester) Headers ¶
func (tt *Tester) Headers(h map[string]string) TesterInterface
Using the function from set headers from http request the default header as ben set is Content-Type: application/json instance.Headers(map[string]string{"Content-Type": "application/json"}) This return an instance of Tester
func (*Tester) Json ¶
func (tt *Tester) Json(i interface{}) TesterInterface
Using the function from set body return from http request
instance.Json(&body)
This return an instance of Tester
func (*Tester) Method ¶
func (tt *Tester) Method(m string) TesterInterface
Using the function from set method from http request
instance.Method(http.MethodGet)
This return an instance of Tester
func (*Tester) Query ¶
func (tt *Tester) Query(q map[string]string) TesterInterface
Using the function from set query from http request
instance.Query(map[string]string{"foo": "bar", "baz": "qux", "key": "value"})
This return an instance of Tester
func (*Tester) Status ¶
func (tt *Tester) Status(s int) TesterInterface
Using the function from set status expected from http request
instance.Status(http.StatusOK)
This return an instance of Tester
func (*Tester) Url ¶
func (tt *Tester) Url(url string) TesterInterface
Using the function from set url from http request
instance.Url("http://httpbin.org/get")
This return an instance of Tester
func (*Tester) ValidateBody ¶
func (tt *Tester) ValidateBody() TesterInterface
type TesterInterface ¶
type TesterInterface interface { Method(string) TesterInterface Url(string) TesterInterface Json(interface{}) TesterInterface Headers(map[string]string) TesterInterface Query(map[string]string) TesterInterface Body([]byte) TesterInterface Status(int) TesterInterface ValidateBody() TesterInterface GetUrl() string Build(*testing.T) *Tester }
func New ¶
func New() TesterInterface
This method return an instance of Tester
instance := supertest.NewHttpTester()
The snapshot is used to create a test builder