go-mastodon/cmd/mstdn/cmd_timeline_test.go

53 lines
1.2 KiB
Go
Raw Normal View History

2017-04-16 16:44:07 +02:00
package main
import (
"fmt"
"net/http"
"strings"
"testing"
"github.com/urfave/cli"
)
func TestCmdTimeline(t *testing.T) {
out := testWithServer(
func(w http.ResponseWriter, r *http.Request) {
2017-04-16 16:49:04 +02:00
switch r.URL.Path {
case "/api/v1/timelines/home":
2019-06-21 18:44:24 +02:00
fmt.Fprintln(w, `[{"content": "home"}]`)
return
case "/api/v1/timelines/public":
fmt.Fprintln(w, `[{"content": "public"}]`)
return
2021-04-15 16:32:27 +02:00
case "/api/v1/conversations":
fmt.Fprintln(w, `[{"id": "4", "unread":false, "last_status" : {"content": "direct"}}]`)
2017-04-16 16:44:07 +02:00
return
}
2017-04-16 16:49:04 +02:00
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
2017-04-16 16:44:07 +02:00
return
},
func(app *cli.App) {
app.Run([]string{"mstdn", "timeline"})
2019-06-21 18:44:24 +02:00
app.Run([]string{"mstdn", "timeline-home"})
app.Run([]string{"mstdn", "timeline-public"})
app.Run([]string{"mstdn", "timeline-local"})
app.Run([]string{"mstdn", "timeline-direct"})
2017-04-16 16:44:07 +02:00
},
)
2019-06-21 18:44:24 +02:00
want := strings.Join([]string{
"@example.com",
"home",
"@example.com",
"home",
"@example.com",
"public",
"@example.com",
"public",
"@example.com",
"direct",
}, "\n") + "\n"
if !strings.Contains(out, want) {
t.Fatalf("%q should be contained in output of command: %v", want, out)
2017-04-16 16:44:07 +02:00
}
}