From 88c2fecca21ee8686134e72b0b1258b02f4ddc7a Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Sun, 16 Apr 2017 23:49:04 +0900 Subject: [PATCH] use switch/case --- cmd/mstdn/cmd_instance_test.go | 7 ++++--- cmd/mstdn/cmd_notification_test.go | 7 ++++--- cmd/mstdn/cmd_timeline_test.go | 7 ++++--- cmd/mstdn/cmd_toot_test.go | 9 +++++---- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/cmd/mstdn/cmd_instance_test.go b/cmd/mstdn/cmd_instance_test.go index 2a48f95..ed04e07 100644 --- a/cmd/mstdn/cmd_instance_test.go +++ b/cmd/mstdn/cmd_instance_test.go @@ -12,11 +12,12 @@ import ( func TestCmdInstance(t *testing.T) { out := testWithServer( func(w http.ResponseWriter, r *http.Request) { - if r.URL.Path != "/api/v1/instance" { - http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) + switch r.URL.Path { + case "/api/v1/instance": + fmt.Fprintln(w, `{"title": "zzz"}`) return } - fmt.Fprintln(w, `{"title": "zzz"}`) + http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) return }, func(app *cli.App) { diff --git a/cmd/mstdn/cmd_notification_test.go b/cmd/mstdn/cmd_notification_test.go index 76d8d57..3921ff3 100644 --- a/cmd/mstdn/cmd_notification_test.go +++ b/cmd/mstdn/cmd_notification_test.go @@ -12,11 +12,12 @@ import ( func TestCmdNotification(t *testing.T) { out := testWithServer( func(w http.ResponseWriter, r *http.Request) { - if r.URL.Path != "/api/v1/notifications" { - http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) + switch r.URL.Path { + case "/api/v1/notifications": + fmt.Fprintln(w, `[{"type": "rebloged", "status": {"content": "foo"}}]`) return } - fmt.Fprintln(w, `[{"type": "rebloged", "status": {"content": "foo"}}]`) + http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) return }, func(app *cli.App) { diff --git a/cmd/mstdn/cmd_timeline_test.go b/cmd/mstdn/cmd_timeline_test.go index 040e015..105d136 100644 --- a/cmd/mstdn/cmd_timeline_test.go +++ b/cmd/mstdn/cmd_timeline_test.go @@ -12,11 +12,12 @@ import ( func TestCmdTimeline(t *testing.T) { out := testWithServer( func(w http.ResponseWriter, r *http.Request) { - if r.URL.Path != "/api/v1/timelines/home" { - http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) + switch r.URL.Path { + case "/api/v1/timelines/home": + fmt.Fprintln(w, `[{"content": "zzz"}]`) return } - fmt.Fprintln(w, `[{"content": "zzz"}]`) + http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) return }, func(app *cli.App) { diff --git a/cmd/mstdn/cmd_toot_test.go b/cmd/mstdn/cmd_toot_test.go index 2f2f0d3..8821536 100644 --- a/cmd/mstdn/cmd_toot_test.go +++ b/cmd/mstdn/cmd_toot_test.go @@ -12,12 +12,13 @@ func TestCmdToot(t *testing.T) { toot := "" testWithServer( func(w http.ResponseWriter, r *http.Request) { - if r.URL.Path != "/api/v1/statuses" { - http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) + switch r.URL.Path { + case "/api/v1/statuses": + toot = r.FormValue("status") + fmt.Fprintln(w, `{"ID": 2345}`) return } - toot = r.FormValue("status") - fmt.Fprintln(w, `{"ID": 2345}`) + http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) return }, func(app *cli.App) {