pull/7/head
Yasuhiro Matsumoto 2017-04-14 17:37:59 +09:00
parent dd7163e01e
commit bfa6468c73
1 changed files with 42 additions and 0 deletions

View File

@ -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)
}
}