go-mastodon/cmd/mstdn/cmd_test.go

42 lines
717 B
Go
Raw Normal View History

2017-04-16 15:27:43 +02:00
package main
import (
"bytes"
"net/http"
"net/http/httptest"
"github.com/mattn/go-mastodon"
2022-11-27 05:24:42 +01:00
"github.com/urfave/cli/v2"
2017-04-16 15:27:43 +02:00
)
2017-04-23 18:13:08 +02:00
func testWithServer(h http.HandlerFunc, testFuncs ...func(*cli.App)) string {
2017-04-16 15:27:43 +02:00
ts := httptest.NewServer(h)
defer ts.Close()
2017-04-19 19:04:20 +02:00
cli.OsExiter = func(n int) {}
2017-04-16 15:27:43 +02:00
client := mastodon.NewClient(&mastodon.Config{
Server: ts.URL,
ClientID: "foo",
ClientSecret: "bar",
AccessToken: "zoo",
})
var buf bytes.Buffer
app := makeApp()
app.Writer = &buf
app.Metadata = map[string]interface{}{
"client": client,
2017-04-19 16:24:36 +02:00
"config": &mastodon.Config{
2017-04-20 17:50:39 +02:00
Server: "https://example.com",
2017-04-19 16:24:36 +02:00
},
2017-05-02 20:05:36 +02:00
"xsearch_url": ts.URL,
2017-04-16 15:27:43 +02:00
}
2017-04-23 18:13:08 +02:00
for _, f := range testFuncs {
f(app)
}
2017-04-16 15:27:43 +02:00
return buf.String()
}