https://github.com/dfirebaugh/httptester
a library for building simple httptests
https://github.com/dfirebaugh/httptester
Last synced: 11 months ago
JSON representation
a library for building simple httptests
- Host: GitHub
- URL: https://github.com/dfirebaugh/httptester
- Owner: dfirebaugh
- License: mit
- Created: 2023-02-12T15:07:53.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-02-12T15:20:30.000Z (over 3 years ago)
- Last Synced: 2025-07-05T03:13:40.899Z (12 months ago)
- Language: Go
- Size: 1.95 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# httptester
`httptester` provides a format for running related tests in a loop. This encourages negative testing and can help facilitate better coverage.
## Add to your project
```bash
go get github.com/dfirebaugh/httptester
```
## Example
```go
func TestGetEntity(t *testing.T) {
comicRepo := in_memory.Repo[entity.Comic]{}
comicService := service.New[entity.Comic](&comicRepo)
comicHandler := v1.EntityHandler[entity.Comic]{
comicService,
responder.Responder{},
}
tests := []httptester.HTTPTest{
{
Method: http.MethodGet,
URL: "/v1/user",
Body: nil,
Tests: []httptester.TestCase{
{
Post: func(res *httptest.ResponseRecorder) {
// should respond with latest
},
},
},
},
{
Method: http.MethodGet,
URL: "/v1/user?latest",
Body: nil,
Tests: []httptester.TestCase{
{
Post: func(res *httptest.ResponseRecorder) {
// should respond with latest
},
},
},
},
{
Method: http.MethodGet,
URL: "/v1/user?first",
Body: nil,
Tests: []httptester.TestCase{
{
Post: func(res *httptest.ResponseRecorder) {
// should respond with first
},
},
},
},
{
Method: http.MethodGet,
URL: "/v1/user?start=01-02-1988",
Body: nil,
Tests: []httptester.TestCase{
{
Post: func(res *httptest.ResponseRecorder) {
// should fail because end is require
},
},
},
},
{
Method: http.MethodGet,
URL: "/v1/user?end=01-02-1988",
Body: nil,
Tests: []httptester.TestCase{
{
Post: func(res *httptest.ResponseRecorder) {
// should fail because start is require
},
},
},
},
{
Method: http.MethodGet,
URL: "/v1/user?start=01-02-1988end=02-29-2022",
Body: nil,
Tests: []httptester.TestCase{
{
Post: func(res *httptest.ResponseRecorder) {
// should fail because it's an invalid date
},
},
},
},
{
Method: http.MethodGet,
URL: "/v1/user?start=01-02-1988end=02-29-2022",
Body: nil,
Tests: []httptester.TestCase{
{
Post: func(res *httptest.ResponseRecorder) {
// should respond with comics in the valid range
},
},
},
},
}
for _, el := range tests {
el.Execute(t, comicHandler.Get)
}
}
```