fix test for search command

pull/37/head
Yasuhiro Matsumoto 2017-04-21 00:50:39 +09:00
parent cc593fd21e
commit 6c3b27aa4e
3 changed files with 27 additions and 10 deletions

View File

@ -15,18 +15,33 @@ func cmdSearch(c *cli.Context) error {
} }
client := c.App.Metadata["client"].(*mastodon.Client) client := c.App.Metadata["client"].(*mastodon.Client)
config := c.App.Metadata["config"].(*mastodon.Config)
results, err := client.Search(context.Background(), argstr(c), false) results, err := client.Search(context.Background(), argstr(c), false)
if err != nil { if err != nil {
return err return err
} }
for _, result := range results.Accounts { s := newScreen(config)
fmt.Fprintln(c.App.Writer, result) 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 { if len(results.Statuses) > 0 {
fmt.Fprintln(c.App.Writer, result) 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 { if len(results.Hashtags) > 0 {
fmt.Fprintln(c.App.Writer, result) 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 return nil
} }

View File

@ -14,7 +14,7 @@ func TestCmdSearch(t *testing.T) {
func(w http.ResponseWriter, r *http.Request) { func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path { switch r.URL.Path {
case "/api/v1/search": 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 return
} }
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
@ -24,7 +24,9 @@ func TestCmdSearch(t *testing.T) {
app.Run([]string{"mstdn", "search", "zzz"}) app.Run([]string{"mstdn", "search", "zzz"})
}, },
) )
if !strings.Contains(out, "zzz") { for _, s := range []string{"zzz", "yyy", "www", "わろす"} {
t.Fatalf("%q should be contained in output of command: %v", "zzz", out) if !strings.Contains(out, s) {
t.Fatalf("%q should be contained in output of command: %v", s, out)
}
} }
} }

View File

@ -28,7 +28,7 @@ func testWithServer(h http.HandlerFunc, testFunc func(*cli.App)) string {
app.Metadata = map[string]interface{}{ app.Metadata = map[string]interface{}{
"client": client, "client": client,
"config": &mastodon.Config{ "config": &mastodon.Config{
Server: "example.com", Server: "https://example.com",
}, },
} }
testFunc(app) testFunc(app)