2018-01-22 11:19:33 +02:00

30 lines
645 B
Go

package examples
import (
"net/http"
"testing"
"github.com/gavv/httpexpect"
)
// fastHTTPTester returns a new Expect instance to test FastHTTPHandler().
func fastHTTPTester(t *testing.T) *httpexpect.Expect {
return httpexpect.WithConfig(httpexpect.Config{
// Pass requests directly to FastHTTPHandler.
Client: &http.Client{
Transport: httpexpect.NewFastBinder(FastHTTPHandler()),
Jar: httpexpect.NewJar(),
},
// Report errors using testify.
Reporter: httpexpect.NewAssertReporter(t),
})
}
func TestFastHTTP(t *testing.T) {
e := fastHTTPTester(t)
e.GET("/ping").Expect().
Status(200).
Text().Equal("pong")
}