From c3ca0792f59a75e78c11d2243a0a5ec5f5abb7bb Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Fri, 14 Apr 2017 17:26:22 +0900 Subject: [PATCH] add test --- mastodon_test.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/mastodon_test.go b/mastodon_test.go index 3212543..dd5fc27 100644 --- a/mastodon_test.go +++ b/mastodon_test.go @@ -76,6 +76,46 @@ func TestPostStatus(t *testing.T) { } } +func TestGetTimelineHome(t *testing.T) { + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + fmt.Fprintln(w, `[{"Content": "foo"}, {"Content": "bar"}]`) + return + })) + defer ts.Close() + + client := NewClient(&Config{ + Server: ts.URL, + ClientID: "foo", + ClientSecret: "bar", + }) + _, err := client.PostStatus(&Toot{ + Status: "foobar", + }) + if err == nil { + t.Fatalf("should be fail: %v", err) + } + + client = NewClient(&Config{ + Server: ts.URL, + ClientID: "foo", + ClientSecret: "bar", + AccessToken: "zoo", + }) + tl, err := client.GetTimelineHome() + if err != nil { + t.Fatalf("should not be fail: %v", err) + } + if len(tl) != 2 { + t.Fatalf("result should be two: %d", len(tl)) + } + if tl[0].Content != "foo" { + t.Fatalf("want %q but %q", "foo", tl[0].Content) + } + if tl[1].Content != "bar" { + t.Fatalf("want %q but %q", "bar", tl[0].Content) + } +} + func TestForTheCoverages(t *testing.T) { (*UpdateEvent)(nil).event() (*NotificationEvent)(nil).event()