https://github.com/accelbyte/http-test-caller
Go wrapper for testing HTTP handler
https://github.com/accelbyte/http-test-caller
Last synced: 5 months ago
JSON representation
Go wrapper for testing HTTP handler
- Host: GitHub
- URL: https://github.com/accelbyte/http-test-caller
- Owner: AccelByte
- License: apache-2.0
- Created: 2018-09-18T08:04:37.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-09-18T08:21:14.000Z (over 7 years ago)
- Last Synced: 2025-08-14T09:10:56.538Z (8 months ago)
- Language: Go
- Size: 5.86 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# HTTP Test Caller
This project is a wrapper for testing HTTP handler, it will pass the request to the handler and record the response using `httptest.ResponseRecorder`. If the response type is set, it will try to unmarshal the response body to the type.
## Usage
### Importing
```go
import "github.com/AccelByte/http-test-caller"
```
### Make a request
```go
resp, body, err :=
caller.Call(handler).
To(gorequest.New(). // using gorequest to construct the request
Post("/example"). // we are testing handler locally, doesn't need full URL
Type(restful.MIME_JSON).
SendString(`{"Example": "test"}`).
MakeRequest()).
Read(&models.ExampleResponse{}).
Execute()
// we can assert the resp.Code & unmarshaled body
```