From bfa6468c736aa44d96860591e33463e0067e2f1d Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Fri, 14 Apr 2017 17:37:59 +0900 Subject: [PATCH] add test --- mastodon_test.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/mastodon_test.go b/mastodon_test.go index e634d27..e41e287 100644 --- a/mastodon_test.go +++ b/mastodon_test.go @@ -124,3 +124,45 @@ func TestForTheCoverages(t *testing.T) { (*ErrorEvent)(nil).event() (&ErrorEvent{io.EOF}).Error() } + +func TestGetAccount(t *testing.T) { + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.URL.Path != "/api/v1/accounts/1234567" { + http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) + return + } + fmt.Fprintln(w, `{"Username": "zzz"}`) + 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", + }) + a, err := client.GetAccount(1) + if err == nil { + t.Fatalf("should not be fail: %v", err) + } + a, err = client.GetAccount(1234567) + if err != nil { + t.Fatalf("should not be fail: %v", err) + } + if a.Username != "zzz" { + t.Fatalf("want %q but %q", "zzz", a.Username) + } +}