use switch/case

pull/19/head
Yasuhiro Matsumoto 2017-04-16 23:49:04 +09:00
parent f2ab559a02
commit 88c2fecca2
4 changed files with 17 additions and 13 deletions

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {