Skip to content

Commit

Permalink
Update cases test.
Browse files Browse the repository at this point in the history
  • Loading branch information
googollee committed Apr 11, 2024
1 parent 478233f commit 5f0b05d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions examples_test.go → cases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -84,9 +85,13 @@ func TestEspresso(t *testing.T) {
}
defer resp.Body.Close()

if err := json.NewDecoder(resp.Body).Decode(&book); err != nil {
buf, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)
}
if err := json.NewDecoder(bytes.NewReader(buf)).Decode(&book); err != nil {
t.Fatal(string(buf), err)
}

if got, want := book.Title, books[1].Title; got != want {
t.Errorf("got = %q, want: %q", got, want)
Expand All @@ -107,8 +112,13 @@ func TestEspresso(t *testing.T) {
}
defer resp.Body.Close()

retbuf, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)
}

var ret Book
if err := json.NewDecoder(resp.Body).Decode(&ret); err != nil {
if err := json.NewDecoder(bytes.NewReader(retbuf)).Decode(&ret); err != nil {
panic(err)
}

Expand Down

0 comments on commit 5f0b05d

Please sign in to comment.