supertest inspired library for testing HTTP servers.
go get github.com/ivpusic/httpcheck
package main
import (
"github.com/ivpusic/httpcheck"
)
func TestExample(t *testing.T) {
// testHandler should be instance of http.Handler
checker := httpcheck.New(t, &testHandler{})
checker.Test("GET", "/some/url").
WithHeader("key", "value").
WithCookie("key", "value").
Check().
HasStatus(200).
HasCookie("key", "expectedValue").
HasHeader("key", "expectedValue").
HasJson(&someType{})
}
package main
import (
"github.com/ivpusic/httpcheck"
)
func TestExample(t *testing.T) {
checker := httpcheck.New(t, &testHandler{})
checker.Test("GET", "/some/url").
WithString("Hello!")
Check().
HasStatus(200)
}
package main
import (
"github.com/ivpusic/httpcheck"
)
func TestExample(t *testing.T) {
checker := httpcheck.New(t, &testHandler{})
data := &someStruct{
field1: "hi",
}
checker.Test("GET", "/some/url").
WithJson(data)
Check().
HasStatus(200)
}
package main
import (
"github.com/ivpusic/httpcheck"
)
func TestExample(t *testing.T) {
checker := httpcheck.New(t, &testHandler{})
data := &someStruct{
field1: "hi",
}
checker.Test("GET", "/some/url").
WithXml(data)
Check().
HasStatus(200)
}
package main
import (
"net/http"
"github.com/ivpusic/httpcheck"
)
func TestExample(t *testing.T) {
checker := httpcheck.New(t, &testHandler{})
checker.TestRequest(&http.Request{ /* fields */ }).
Check().
HasStatus(200)
}
package main
import (
"net/http"
"github.com/ivpusic/httpcheck"
)
func TestExample(t *testing.T) {
checker := httpcheck.New(t, &testHandler{})
checker.Test("GET", "/some/url").
Check().
HasStatus(200).
HasBody([]byte("some body")).
Cb(func(response *http.Response) { /* do something */ })
}
- Implement fix/feature
- Write tests for fix/feature
- Make sure all tests are passing
- Send Pull Request
MIT