generic: provide configured encoder
This encoder emits data identical to upstream API response body. Signed-off-by: Yonah <contrib@gensokyo.uk>
This commit is contained in:
parent
bb1164d081
commit
343a8c5f45
@ -75,3 +75,10 @@ func (i *StringInt) UnmarshalJSON(data []byte) (err error) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// NewEncoder returns a new encoder that writes to w, configured to match upstream API behaviour.
|
||||
func NewEncoder(w io.Writer) *json.Encoder {
|
||||
e := json.NewEncoder(w)
|
||||
e.SetEscapeHTML(false)
|
||||
return e
|
||||
}
|
||||
|
@ -84,10 +84,7 @@ func checkJSONRoundTrip[T any](t *testing.T, v T, data []byte) {
|
||||
t.Run("marshal", func(t *testing.T) {
|
||||
buf := new(bytes.Buffer)
|
||||
buf.Grow(len(data))
|
||||
e := json.NewEncoder(buf)
|
||||
// to match upstream behaviour
|
||||
e.SetEscapeHTML(false)
|
||||
err := e.Encode(&v)
|
||||
err := NewEncoder(buf).Encode(&v)
|
||||
if err != nil {
|
||||
t.Fatalf("Marshal: error = %v", err)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user