Add cmd follow test

pull/41/head
178inaba 2017-04-24 01:13:08 +09:00
parent 7a4a84f70f
commit 6f6070b22e
2 changed files with 45 additions and 5 deletions

View File

@ -14,8 +14,17 @@ func TestCmdFollow(t *testing.T) {
func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/api/v1/accounts/search":
fmt.Fprintln(w, `[{"id": 123}]`)
return
q := r.URL.Query().Get("q")
if q == "mattn" {
fmt.Fprintln(w, `[{"id": 123}]`)
return
} else if q == "different_id" {
fmt.Fprintln(w, `[{"id": 1234567}]`)
return
} else if q == "empty" {
fmt.Fprintln(w, `[]`)
return
}
case "/api/v1/accounts/123/follow":
fmt.Fprintln(w, `{"id": 123}`)
ok = true
@ -25,7 +34,34 @@ func TestCmdFollow(t *testing.T) {
return
},
func(app *cli.App) {
app.Run([]string{"mstdn", "follow", "mattn"})
err := app.Run([]string{"mstdn", "follow", "mattn"})
if err != nil {
t.Fatalf("should not be fail: %v", err)
}
},
func(app *cli.App) {
err := app.Run([]string{"mstdn", "follow"})
if err == nil {
t.Fatalf("should be fail: %v", err)
}
},
func(app *cli.App) {
err := app.Run([]string{"mstdn", "follow", "fail"})
if err == nil {
t.Fatalf("should be fail: %v", err)
}
},
func(app *cli.App) {
err := app.Run([]string{"mstdn", "follow", "empty"})
if err != nil {
t.Fatalf("should not be fail: %v", err)
}
},
func(app *cli.App) {
err := app.Run([]string{"mstdn", "follow", "different_id"})
if err == nil {
t.Fatalf("should not be fail: %v", err)
}
},
)
if !ok {

View File

@ -9,7 +9,7 @@ import (
"github.com/urfave/cli"
)
func testWithServer(h http.HandlerFunc, testFunc func(*cli.App)) string {
func testWithServer(h http.HandlerFunc, testFuncs ...func(*cli.App)) string {
ts := httptest.NewServer(h)
defer ts.Close()
@ -31,6 +31,10 @@ func testWithServer(h http.HandlerFunc, testFunc func(*cli.App)) string {
Server: "https://example.com",
},
}
testFunc(app)
for _, f := range testFuncs {
f(app)
}
return buf.String()
}