Add TestGetBlocks

pull/9/head
178inaba 2017-04-15 02:30:47 +09:00
parent 70efe09ff4
commit dde3686355
1 changed files with 32 additions and 0 deletions

View File

@ -7,6 +7,38 @@ import (
"testing" "testing"
) )
func TestGetBlocks(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/api/v1/blocks" {
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
return
}
fmt.Fprintln(w, `[{"Username": "foo"}, {"Username": "bar"}]`)
return
}))
defer ts.Close()
client := NewClient(&Config{
Server: ts.URL,
ClientID: "foo",
ClientSecret: "bar",
AccessToken: "zoo",
})
bl, err := client.GetBlocks()
if err != nil {
t.Fatalf("should not be fail: %v", err)
}
if len(bl) != 2 {
t.Fatalf("result should be two: %d", len(bl))
}
if bl[0].Username != "foo" {
t.Fatalf("want %q but %q", "foo", bl[0].Username)
}
if bl[1].Username != "bar" {
t.Fatalf("want %q but %q", "bar", bl[0].Username)
}
}
func TestAccountFollow(t *testing.T) { func TestAccountFollow(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) {
if r.URL.Path != "/api/v1/accounts/1234567/follow" { if r.URL.Path != "/api/v1/accounts/1234567/follow" {