Revert to simple io.Writer
with client-resetting
After going through several other solutions, there's no clean way to use an `io.Writer` but also be able to call `Reset()` between writes. Filehandles can't `Reset()` and buffers can't `Seek()`. But then if you supplied `os.Stderr`, you'd be expecting appending and a `Seek()` would be nonsense. My own preference would be to make `JSONWriter` a strict `*bytes.Buffer` which lets the library handle the resetting and the client do any outputting if required - I can't see much value in ever supplying a non-`bytes.Buffer` as `JSONWriter`.
This commit is contained in:
parent
51e4324c7a
commit
08be497fae
2 changed files with 5 additions and 9 deletions
|
@ -1,6 +1,7 @@
|
|||
package mastodon
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
@ -52,7 +53,8 @@ func TestGetFavouritesSavedJSON(t *testing.T) {
|
|||
AccessToken: "zoo",
|
||||
})
|
||||
|
||||
client.SaveJSON = true
|
||||
var buf bytes.Buffer
|
||||
client.JSONWriter = &buf
|
||||
|
||||
favs, err := client.GetFavourites(context.Background(), nil)
|
||||
if err != nil {
|
||||
|
@ -70,7 +72,7 @@ func TestGetFavouritesSavedJSON(t *testing.T) {
|
|||
|
||||
// We get a trailing `\n` from the API which we need to trim
|
||||
// off before we compare it with our literal above.
|
||||
theirJSON := strings.TrimSpace(string(client.LastJSON))
|
||||
theirJSON := strings.TrimSpace(string(buf.Bytes()))
|
||||
|
||||
if theirJSON != ourJSON {
|
||||
t.Fatalf("want %q but %q", ourJSON, theirJSON)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue