From 909a57c5ea4e72491766c033f4b4eb60c53e2ae0 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Wed, 19 Apr 2017 18:25:01 +0900 Subject: [PATCH] add test for follow command --- cmd/mstdn/cmd_follow_test.go | 34 ++++++++++++++++++++++++++++++++++ cmd/mstdn/main.go | 10 +++++----- 2 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 cmd/mstdn/cmd_follow_test.go diff --git a/cmd/mstdn/cmd_follow_test.go b/cmd/mstdn/cmd_follow_test.go new file mode 100644 index 0000000..ea74526 --- /dev/null +++ b/cmd/mstdn/cmd_follow_test.go @@ -0,0 +1,34 @@ +package main + +import ( + "fmt" + "net/http" + "testing" + + "github.com/urfave/cli" +) + +func TestCmdFollow(t *testing.T) { + ok := false + testWithServer( + func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case "/api/v1/accounts/search": + fmt.Fprintln(w, `[{"id": 123}]`) + return + 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) { + app.Run([]string{"mstdn", "follow", "mattn"}) + }, + ) + if !ok { + t.Fatal("something wrong to sequence to follow account") + } +} diff --git a/cmd/mstdn/main.go b/cmd/mstdn/main.go index b9fcbf0..f266911 100644 --- a/cmd/mstdn/main.go +++ b/cmd/mstdn/main.go @@ -239,16 +239,16 @@ func makeApp() *cli.App { Usage: "search content", Action: cmdSearch, }, - { - Name: "followers", - Usage: "show followers", - Action: cmdFollowers, - }, { Name: "follow", Usage: "follow account", Action: cmdFollow, }, + { + Name: "followers", + Usage: "show followers", + Action: cmdFollowers, + }, { Name: "upload", Usage: "upload file",