go-mastodon/cmd/mstdn/cmd_test.go

37 lines
655 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"
"github.com/urfave/cli"
)
func testWithServer(h http.HandlerFunc, testFunc func(*cli.App)) string {
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-04-16 15:27:43 +02:00
}
testFunc(app)
return buf.String()
}