Files
server/test/asserts.go
renovate[bot] a0bad7bd5a chore(deps): update bump go dependencies (#751)
* chore(deps): update bump go dependencies

* Update golangci-lint

Signed-off-by: eternal-flame-AD <yume@yumechi.jp>

* Update golangci config to reflect new format

Signed-off-by: eternal-flame-AD <yume@yumechi.jp>

* remove deprecated ioutil package

Signed-off-by: eternal-flame-AD <yume@yumechi.jp>

---------

Signed-off-by: eternal-flame-AD <yume@yumechi.jp>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: eternal-flame-AD <yume@yumechi.jp>
2025-01-17 05:51:08 +00:00

40 lines
1004 B
Go

package test
import (
"encoding/json"
"errors"
"io"
"net/http/httptest"
"github.com/stretchr/testify/assert"
)
// BodyEquals asserts the content from the response recorder with the encoded json of the provided instance.
func BodyEquals(t assert.TestingT, obj interface{}, recorder *httptest.ResponseRecorder) {
bytes, err := io.ReadAll(recorder.Body)
assert.Nil(t, err)
actual := string(bytes)
JSONEquals(t, obj, actual)
}
// JSONEquals asserts the content of the string with the encoded json of the provided instance.
func JSONEquals(t assert.TestingT, obj interface{}, expected string) {
bytes, err := json.Marshal(obj)
assert.Nil(t, err)
objJSON := string(bytes)
assert.JSONEq(t, expected, objJSON)
}
type unreadableReader struct{}
func (c unreadableReader) Read([]byte) (int, error) {
return 0, errors.New("this reader cannot be read")
}
// UnreadableReader returns an unreadable reader, used to mock IO issues.
func UnreadableReader() io.Reader {
return unreadableReader{}
}