From 3b4b2ce7949770e3355235059f6f882361e3638b Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Sun, 16 Apr 2017 20:06:54 +0900 Subject: [PATCH] separate test files --- apps_test.go | 42 ++++++++++++++++++++++++++++++++++++++++++ mastodon_test.go | 34 ---------------------------------- 2 files changed, 42 insertions(+), 34 deletions(-) create mode 100644 apps_test.go diff --git a/apps_test.go b/apps_test.go new file mode 100644 index 0000000..64be57b --- /dev/null +++ b/apps_test.go @@ -0,0 +1,42 @@ +package mastodon + +import ( + "fmt" + "net/http" + "net/http/httptest" + "testing" +) + +func TestRegisterApp(t *testing.T) { + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != http.MethodPost { + 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) + } +} diff --git a/mastodon_test.go b/mastodon_test.go index c5bbf58..1fbcf64 100644 --- a/mastodon_test.go +++ b/mastodon_test.go @@ -190,37 +190,3 @@ func TestGetAccountFollowing(t *testing.T) { 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 != http.MethodPost { - 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) - } -}