A simple test for retained JSON
This commit is contained in:
parent
63cf193a13
commit
333d71452a
1 changed files with 40 additions and 0 deletions
|
@ -7,6 +7,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -37,6 +38,45 @@ func TestGetFavourites(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetFavouritesSavedJSON(t *testing.T) {
|
||||||
|
ourJSON := `[{"content": "foo"}, {"content": "bar"}]`
|
||||||
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
fmt.Fprintln(w, ourJSON)
|
||||||
|
}))
|
||||||
|
defer ts.Close()
|
||||||
|
|
||||||
|
client := NewClient(&Config{
|
||||||
|
Server: ts.URL,
|
||||||
|
ClientID: "foo",
|
||||||
|
ClientSecret: "bar",
|
||||||
|
AccessToken: "zoo",
|
||||||
|
})
|
||||||
|
|
||||||
|
client.SaveJSON = true
|
||||||
|
|
||||||
|
favs, err := client.GetFavourites(context.Background(), nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("should not be fail: %v", err)
|
||||||
|
}
|
||||||
|
if len(favs) != 2 {
|
||||||
|
t.Fatalf("result should be two: %d", len(favs))
|
||||||
|
}
|
||||||
|
if favs[0].Content != "foo" {
|
||||||
|
t.Fatalf("want %q but %q", "foo", favs[0].Content)
|
||||||
|
}
|
||||||
|
if favs[1].Content != "bar" {
|
||||||
|
t.Fatalf("want %q but %q", "bar", favs[1].Content)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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))
|
||||||
|
|
||||||
|
if theirJSON != ourJSON {
|
||||||
|
t.Fatalf("want %q but %q", ourJSON, theirJSON)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestGetBookmarks(t *testing.T) {
|
func TestGetBookmarks(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
fmt.Fprintln(w, `[{"content": "foo"}, {"content": "bar"}]`)
|
fmt.Fprintln(w, `[{"content": "foo"}, {"content": "bar"}]`)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue