asserter - Package for oneline assertions
NO LONGER MAINTAINED!!!
After some consideration and reading Assert Libraries I've decided to stop using this package and advise you the same.
go get github.com/gregoryv/asserter
In your tests
func Test_something(t *testing.T) {
got, err := something()
assert := asserter.New(t)
assert(err == nil).Fatal(err)
assert(got == exp).Errorf("%v, expected %v", got, exp)
// same as
assert().Equals(got, exp)
assert().Contains(got, "text")
assert().Contains(got, 1)
// Check readers content
resp, err := http.Get("http://example.com")
assert(err == nil).Fatal(err)
assert().Contains(resp.Body, "<title>")
}
HTTP handler specific
assert := asserter.New(t)
exp := assert().ResponseFrom(handler)
// io.Reader option means body
exp.StatusCode(200, "POST", "/", strings.NewReader("the body"))
// string option means error message
exp.StatusCode(200, "GET", "/", "should be ok")
// http.Header additional headers
exp.StatusCode(200, "GET", "/", http.Header{
"Content-Type": []string{"text/plain"},
})