From 86066b95619f366e9630208b4b6ba52af2263813 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Sun, 16 Apr 2017 22:50:09 +0900 Subject: [PATCH] add test for notification command --- cmd/mstdn/cmd_notification.go | 6 +++--- cmd/mstdn/cmd_notification_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 cmd/mstdn/cmd_notification_test.go diff --git a/cmd/mstdn/cmd_notification.go b/cmd/mstdn/cmd_notification.go index 55fc1e5..3b6e5a7 100644 --- a/cmd/mstdn/cmd_notification.go +++ b/cmd/mstdn/cmd_notification.go @@ -17,11 +17,11 @@ func cmdNotification(c *cli.Context) error { for _, n := range notifications { if n.Status != nil { color.Set(color.FgHiRed) - fmt.Print(n.Account.Username) + fmt.Fprint(c.App.Writer, n.Account.Username) color.Set(color.Reset) - fmt.Println(" " + n.Type) + fmt.Fprintln(c.App.Writer, " "+n.Type) s := n.Status - fmt.Println(textContent(s.Content)) + fmt.Fprintln(c.App.Writer, textContent(s.Content)) } } return nil diff --git a/cmd/mstdn/cmd_notification_test.go b/cmd/mstdn/cmd_notification_test.go new file mode 100644 index 0000000..76d8d57 --- /dev/null +++ b/cmd/mstdn/cmd_notification_test.go @@ -0,0 +1,29 @@ +package main + +import ( + "fmt" + "net/http" + "strings" + "testing" + + "github.com/urfave/cli" +) + +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) + return + } + fmt.Fprintln(w, `[{"type": "rebloged", "status": {"content": "foo"}}]`) + return + }, + func(app *cli.App) { + app.Run([]string{"mstdn", "notification"}) + }, + ) + if !strings.Contains(out, "rebloged") { + t.Fatalf("%q should be contained in output of instance command: %v", "rebloged", out) + } +}