Add TestGetInstance

pull/35/head
178inaba 2017-04-20 22:09:11 +09:00
parent c417db5189
commit 4be3a42d3c
1 changed files with 40 additions and 0 deletions

40
instance_test.go 100644
View File

@ -0,0 +1,40 @@
package mastodon
import (
"context"
"fmt"
"net/http"
"net/http/httptest"
"testing"
)
func TestGetInstance(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, `{"title": "mastodon"}`)
}))
defer ts.Close()
client := NewClient(&Config{
Server: ts.URL,
ClientID: "foo",
ClientSecret: "bar",
AccessToken: "zoo",
})
_, err := client.GetInstance(context.Background())
if err == nil {
t.Fatalf("should be fail: %v", err)
}
ins, err := client.GetInstance(context.Background())
if err != nil {
t.Fatalf("should not be fail: %v", err)
}
if ins.Title != "mastodon" {
t.Fatalf("want %q but %q", "mastodon", ins.Title)
}
}