Files
atlantis/testing/http.go
Eng Zer Jun 38cf7b0141 refactor: move from io/ioutil to io and os package (#1843)
The io/ioutil package has been deprecated as of Go 1.16, see
https://golang.org/doc/go1.16#ioutil. This commit replaces the existing
io/ioutil functions with their new definitions in io and os packages.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2021-10-07 00:37:42 -04:00

17 lines
474 B
Go

package testing
import (
"io"
"net/http/httptest"
"strings"
"testing"
)
func ResponseContains(t *testing.T, r *httptest.ResponseRecorder, status int, bodySubstr string) {
t.Helper()
body, err := io.ReadAll(r.Result().Body)
Ok(t, err)
Assert(t, status == r.Result().StatusCode, "exp %d got %d, body: %s", status, r.Result().StatusCode, string(body))
Assert(t, strings.Contains(string(body), bodySubstr), "exp %q to be contained in %q", bodySubstr, string(body))
}