mirror of
https://github.com/gotify/server.git
synced 2026-09-06 15:57:32 +08:00
* 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
35 lines
905 B
Go
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"))
|
|
}
|