Add TestGetBlocks
This commit is contained in:
parent
70efe09ff4
commit
dde3686355
|
@ -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" {
|
||||
|
|
Loading…
Reference in New Issue
Block a user