Add accounts test

pull/23/head
178inaba 2017-04-17 23:39:47 +09:00
parent 39239ae270
commit a752a1bd6b
2 changed files with 83 additions and 37 deletions

View File

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

View File

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