From dde3686355d4e2f1f6e189fc8bba3e7019b9b669 Mon Sep 17 00:00:00 2001 From: 178inaba <178inaba@users.noreply.github.com> Date: Sat, 15 Apr 2017 02:30:47 +0900 Subject: [PATCH] Add TestGetBlocks --- accounts_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/accounts_test.go b/accounts_test.go index 4ee715b..7c2dbe2 100644 --- a/accounts_test.go +++ b/accounts_test.go @@ -7,6 +7,38 @@ import ( "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) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.URL.Path != "/api/v1/accounts/1234567/follow" {