pull/7/head
Yasuhiro Matsumoto 2017-04-14 18:19:38 +09:00
parent 44a8f8e593
commit dc7a04a5b5
1 changed files with 34 additions and 0 deletions

View File

@ -190,3 +190,37 @@ func TestGetAccountFollowing(t *testing.T) {
t.Fatalf("want %q but %q", "bar", fl[0].Username) t.Fatalf("want %q but %q", "bar", fl[0].Username)
} }
} }
func TestRegisterApp(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
return
}
if r.URL.Path != "/api/v1/apps" {
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
return
}
if r.FormValue("redirect_uris") != "urn:ietf:wg:oauth:2.0:oob" {
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
return
}
fmt.Fprintln(w, `{"client_id": "foo", "client_secret": "bar"}`)
return
}))
defer ts.Close()
app, err := RegisterApp(&AppConfig{
Server: ts.URL,
Scopes: "read write follow",
})
if err != nil {
t.Fatalf("should not be fail: %v", err)
}
if app.ClientID != "foo" {
t.Fatalf("want %q but %q", "foo", app.ClientID)
}
if app.ClientSecret != "bar" {
t.Fatalf("want %q but %q", "bar", app.ClientSecret)
}
}