go-mastodon/cmd/mstdn/cmd_follow_test.go

71 lines
1.5 KiB
Go
Raw Normal View History

2017-04-19 11:25:01 +02:00
package main
import (
"fmt"
"net/http"
"testing"
2022-11-27 05:24:42 +01:00
"github.com/urfave/cli/v2"
2017-04-19 11:25:01 +02:00
)
func TestCmdFollow(t *testing.T) {
ok := false
testWithServer(
func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/api/v1/accounts/search":
2017-04-23 18:13:08 +02:00
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
}
2017-04-19 11:25:01 +02:00
case "/api/v1/accounts/123/follow":
fmt.Fprintln(w, `{"id": 123}`)
ok = true
return
}
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
return
},
func(app *cli.App) {
2017-04-23 18:13:08 +02:00
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 {
2017-04-24 10:33:45 +02:00
t.Fatalf("should be fail: %v", err)
2017-04-23 18:13:08 +02:00
}
2017-04-19 11:25:01 +02:00
},
)
if !ok {
t.Fatal("something wrong to sequence to follow account")
}
}