fix test for search command
parent
cc593fd21e
commit
6c3b27aa4e
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue