diff --git a/accounts_test.go b/accounts_test.go index 9f99a8d..0461bae 100644 --- a/accounts_test.go +++ b/accounts_test.go @@ -140,8 +140,12 @@ func TestGetAccountStatuses(t *testing.T) { } } -func TestGetBlocks(t *testing.T) { +func TestGetAccountFollowers(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.URL.Path != "/api/v1/accounts/1234567/followers" { + http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) + return + } fmt.Fprintln(w, `[{"Username": "foo"}, {"Username": "bar"}]`) return })) @@ -153,6 +157,84 @@ func TestGetBlocks(t *testing.T) { ClientSecret: "bar", AccessToken: "zoo", }) + _, err := client.GetAccountFollowers(context.Background(), 123) + if err == nil { + t.Fatalf("should be fail: %v", err) + } + fl, err := client.GetAccountFollowers(context.Background(), 1234567) + if err != nil { + t.Fatalf("should not be fail: %v", err) + } + if len(fl) != 2 { + t.Fatalf("result should be two: %d", len(fl)) + } + if fl[0].Username != "foo" { + t.Fatalf("want %q but %q", "foo", fl[0].Username) + } + if fl[1].Username != "bar" { + t.Fatalf("want %q but %q", "bar", fl[1].Username) + } +} + +func TestGetAccountFollowing(t *testing.T) { + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.URL.Path != "/api/v1/accounts/1234567/following" { + 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", + }) + fl, err := client.GetAccountFollowing(context.Background(), 123) + if err == nil { + t.Fatalf("should be fail: %v", err) + } + fl, err = client.GetAccountFollowing(context.Background(), 1234567) + if err != nil { + t.Fatalf("should not be fail: %v", err) + } + if len(fl) != 2 { + t.Fatalf("result should be two: %d", len(fl)) + } + if fl[0].Username != "foo" { + t.Fatalf("want %q but %q", "foo", fl[0].Username) + } + if fl[1].Username != "bar" { + t.Fatalf("want %q but %q", "bar", fl[1].Username) + } +} + +func TestGetBlocks(t *testing.T) { + canErr := true + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if canErr { + canErr = false + http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) + return + } + fmt.Fprintln(w, `[{"Username": "foo"}, {"Username": "bar"}]`) + return + })) + defer ts.Close() + + client := NewClient(&Config{ + Server: ts.URL, + ClientID: "foo", + ClientSecret: "bar", + AccessToken: "zoo", + }) + _, err := client.GetBlocks(context.Background()) + if err == nil { + t.Fatalf("should be fail: %v", err) + } bl, err := client.GetBlocks(context.Background()) if err != nil { t.Fatalf("should not be fail: %v", err) diff --git a/mastodon_test.go b/mastodon_test.go index abde791..8005b75 100644 --- a/mastodon_test.go +++ b/mastodon_test.go @@ -125,39 +125,3 @@ func TestForTheCoverages(t *testing.T) { (*ErrorEvent)(nil).event() _ = (&ErrorEvent{io.EOF}).Error() } - -func TestGetAccountFollowing(t *testing.T) { - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.URL.Path != "/api/v1/accounts/1234567/following" { - 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", - }) - fl, err := client.GetAccountFollowing(context.Background(), 123) - if err == nil { - t.Fatalf("should not be fail: %v", err) - } - fl, err = client.GetAccountFollowing(context.Background(), 1234567) - if err != nil { - t.Fatalf("should not be fail: %v", err) - } - if len(fl) != 2 { - t.Fatalf("result should be two: %d", len(fl)) - } - if fl[0].Username != "foo" { - t.Fatalf("want %q but %q", "foo", fl[0].Username) - } - if fl[1].Username != "bar" { - t.Fatalf("want %q but %q", "bar", fl[1].Username) - } -}