From 6c3b27aa4ea5264583f0b95ae931c02e9de1b400 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Fri, 21 Apr 2017 00:50:39 +0900 Subject: [PATCH] fix test for search command --- cmd/mstdn/cmd_search.go | 27 +++++++++++++++++++++------ cmd/mstdn/cmd_search_test.go | 8 +++++--- cmd/mstdn/cmd_test.go | 2 +- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/cmd/mstdn/cmd_search.go b/cmd/mstdn/cmd_search.go index 5cd754b..6d7e81b 100644 --- a/cmd/mstdn/cmd_search.go +++ b/cmd/mstdn/cmd_search.go @@ -15,18 +15,33 @@ func cmdSearch(c *cli.Context) error { } client := c.App.Metadata["client"].(*mastodon.Client) + config := c.App.Metadata["config"].(*mastodon.Config) + results, err := client.Search(context.Background(), argstr(c), false) if err != nil { return err } - for _, result := range results.Accounts { - fmt.Fprintln(c.App.Writer, result) + s := newScreen(config) + if len(results.Accounts) > 0 { + fmt.Fprintln(c.App.Writer, "===ACCOUNT===") + for _, result := range results.Accounts { + fmt.Fprintf(c.App.Writer, "%v,%v\n", result.ID, s.acct(result.Acct)) + } + fmt.Fprintln(c.App.Writer) } - for _, result := range results.Statuses { - fmt.Fprintln(c.App.Writer, result) + if len(results.Statuses) > 0 { + fmt.Fprintln(c.App.Writer, "===STATUS===") + for _, result := range results.Statuses { + s.displayStatus(c.App.Writer, result) + } + fmt.Fprintln(c.App.Writer) } - for _, result := range results.Hashtags { - fmt.Fprintln(c.App.Writer, result) + if len(results.Hashtags) > 0 { + fmt.Fprintln(c.App.Writer, "===HASHTAG===") + for _, result := range results.Hashtags { + fmt.Fprintf(c.App.Writer, "#%v\n", result) + } + fmt.Fprintln(c.App.Writer) } return nil } diff --git a/cmd/mstdn/cmd_search_test.go b/cmd/mstdn/cmd_search_test.go index f498592..2d00b93 100644 --- a/cmd/mstdn/cmd_search_test.go +++ b/cmd/mstdn/cmd_search_test.go @@ -14,7 +14,7 @@ func TestCmdSearch(t *testing.T) { func(w http.ResponseWriter, r *http.Request) { switch r.URL.Path { case "/api/v1/search": - fmt.Fprintln(w, `{"accounts": [{"id": 234, "username": "zzz"}], "contents":[], "hashtags": []}`) + fmt.Fprintln(w, `{"accounts": [{"id": 234, "acct": "zzz"}], "statuses":[{"id": 345, "content": "yyy"}], "hashtags": ["www", "わろす"]}`) return } http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) @@ -24,7 +24,9 @@ func TestCmdSearch(t *testing.T) { app.Run([]string{"mstdn", "search", "zzz"}) }, ) - if !strings.Contains(out, "zzz") { - t.Fatalf("%q should be contained in output of command: %v", "zzz", out) + for _, s := range []string{"zzz", "yyy", "www", "わろす"} { + if !strings.Contains(out, s) { + t.Fatalf("%q should be contained in output of command: %v", s, out) + } } } diff --git a/cmd/mstdn/cmd_test.go b/cmd/mstdn/cmd_test.go index 37142c0..eb38282 100644 --- a/cmd/mstdn/cmd_test.go +++ b/cmd/mstdn/cmd_test.go @@ -28,7 +28,7 @@ func testWithServer(h http.HandlerFunc, testFunc func(*cli.App)) string { app.Metadata = map[string]interface{}{ "client": client, "config": &mastodon.Config{ - Server: "example.com", + Server: "https://example.com", }, } testFunc(app)