go-ssb-room/web/handlers/news/app_test.go

48 lines
1019 B
Go
Raw Normal View History

2021-02-09 11:53:33 +00:00
// SPDX-License-Identifier: MIT
2021-02-04 11:00:12 +00:00
package news
import (
"net/http"
"testing"
"github.com/pkg/errors"
"go.mindeco.de/http/render"
"go.mindeco.de/http/tester"
"go.mindeco.de/logging/logtest"
"github.com/ssb-ngi-pointer/go-ssb-room/web"
"github.com/ssb-ngi-pointer/go-ssb-room/web/router"
2021-02-04 11:00:12 +00:00
)
var (
testMux *http.ServeMux
testClient *tester.Tester
testRouter = router.News(nil)
)
func setup(t *testing.T) {
2021-02-04 16:21:21 +00:00
testFuncs := web.TemplateFuncs(testRouter)
testFuncs["i18n"] = func(msgID string) string { return msgID }
2021-02-04 11:00:12 +00:00
log, _ := logtest.KitLogger("feed", t)
2021-02-08 11:57:14 +00:00
r, err := render.New(web.Templates,
2021-02-04 11:00:12 +00:00
render.SetLogger(log),
render.BaseTemplates("/testing/base.tmpl"),
render.AddTemplates(append(HTMLTemplates, "/error.tmpl")...),
2021-02-04 16:21:21 +00:00
render.FuncMap(testFuncs),
2021-02-04 11:00:12 +00:00
)
if err != nil {
t.Fatal(errors.Wrap(err, "setup: render init failed"))
}
testMux = http.NewServeMux()
testMux.Handle("/", Handler(testRouter, r))
testClient = tester.New(testMux, t)
}
func teardown() {
testMux = nil
testClient = nil
}