Files
server/test/asserts.go
饺子w (Yumechi) ad977d3d9c feat: EdDSA token for database leakage/index mitigation (#971)
* feat: EdDSA token for database leakage/index mitigation

* [skip ci]: remove token from api output

* fix: e2e tests

* fixup! fix: e2e tests

* doc: document tokens are now optional fields for app and aclient

* fixup(doc): swagger version again

* address review comments

* address review comments
2026-06-28 14:58:20 +00:00

35 lines
905 B
Go

package test
import (
"encoding/json"
"errors"
"io"
"net/http/httptest"
"testing/iotest"
"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 any, 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 any, expected string) {
bytes, err := json.Marshal(obj)
assert.Nil(t, err)
objJSON := string(bytes)
assert.JSONEq(t, expected, objJSON)
}
// UnreadableReader returns an unreadable reader, used to mock IO issues.
func UnreadableReader() io.Reader {
return iotest.ErrReader(errors.New("this reader cannot be read"))
}