2017-04-16 15:27:43 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
|
|
|
|
"github.com/mattn/go-mastodon"
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
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()
|
|
|
|
}
|