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)
config := c.App.Metadata["config"].(*mastodon.Config)
results, err := client.Search(context.Background(), argstr(c), false)
if err != nil {
return err
}
s := newScreen(config)
if len(results.Accounts) > 0 {
fmt.Fprintln(c.App.Writer, "===ACCOUNT===")
for _, result := range results.Accounts {
fmt.Fprintln(c.App.Writer, result)
fmt.Fprintf(c.App.Writer, "%v,%v\n", result.ID, s.acct(result.Acct))
}
fmt.Fprintln(c.App.Writer)
}
if len(results.Statuses) > 0 {
fmt.Fprintln(c.App.Writer, "===STATUS===")
for _, result := range results.Statuses {
fmt.Fprintln(c.App.Writer, result)
s.displayStatus(c.App.Writer, result)
}
fmt.Fprintln(c.App.Writer)
}
if len(results.Hashtags) > 0 {
fmt.Fprintln(c.App.Writer, "===HASHTAG===")
for _, result := range results.Hashtags {
fmt.Fprintln(c.App.Writer, result)
fmt.Fprintf(c.App.Writer, "#%v\n", result)
}
fmt.Fprintln(c.App.Writer)
}
return nil
}

View File

@ -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)
}
}
}

View File

@ -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)