Added tests for list API calls

This commit is contained in:
Christian Muehlhaeuser 2019-05-12 16:32:17 +02:00
parent 5ff4ecfd52
commit f9fc8ad95d
No known key found for this signature in database
GPG key ID: 3CF9FA45CA1EBB7E
3 changed files with 366 additions and 1 deletions

View file

@ -5,8 +5,8 @@ import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
"os"
"testing"
)
func TestGetFavourites(t *testing.T) {
@ -406,6 +406,42 @@ func TestGetTimelineHashtag(t *testing.T) {
}
}
func TestGetTimelineList(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/api/v1/timelines/list/1" {
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
return
}
fmt.Fprintln(w, `[{"content": "zzz"},{"content": "yyy"}]`)
return
}))
defer ts.Close()
client := NewClient(&Config{
Server: ts.URL,
ClientID: "foo",
ClientSecret: "bar",
AccessToken: "zoo",
})
_, err := client.GetTimelineList(context.Background(), "notfound", nil)
if err == nil {
t.Fatalf("should be fail: %v", err)
}
tags, err := client.GetTimelineList(context.Background(), "1", nil)
if err != nil {
t.Fatalf("should not be fail: %v", err)
}
if len(tags) != 2 {
t.Fatalf("should have %q entries but %q", "2", len(tags))
}
if tags[0].Content != "zzz" {
t.Fatalf("want %q but %q", "zzz", tags[0].Content)
}
if tags[1].Content != "yyy" {
t.Fatalf("want %q but %q", "zzz", tags[1].Content)
}
}
func TestGetTimelineMedia(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Query().Get("local") == "" {