app_test.go 980 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package feed
  2. import (
  3. "html/template"
  4. "net/http"
  5. "testing"
  6. "github.com/cryptix/go/http/render"
  7. "github.com/cryptix/go/http/tester"
  8. "github.com/cryptix/go/logging/logtest"
  9. "github.com/pkg/errors"
  10. "github.com/cryptix/exp/multiModulePage"
  11. "github.com/cryptix/exp/multiModulePage/router"
  12. )
  13. var (
  14. testMux *http.ServeMux
  15. testClient *tester.Tester
  16. testRouter = router.FeedApp(nil)
  17. )
  18. func setup(t *testing.T) {
  19. log := logtest.KitLogger("feed", t)
  20. r, err := render.New(multiModulePage.Assets,
  21. render.SetLogger(log),
  22. render.BaseTemplates("/testing/base.tmpl"),
  23. render.AddTemplates(append(HTMLTemplates, "/error.tmpl")...),
  24. render.FuncMap(template.FuncMap{
  25. "urlTo": multiModulePage.NewURLTo(testRouter),
  26. }),
  27. )
  28. if err != nil {
  29. t.Fatal(errors.Wrap(err, "setup: render init failed"))
  30. }
  31. testMux = http.NewServeMux()
  32. testMux.Handle("/", Handler(testRouter, r))
  33. testClient = tester.New(testMux, t)
  34. }
  35. func teardown() {
  36. testMux = nil
  37. testClient = nil
  38. }