middleware_test.go 770 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package middleware
  2. import (
  3. "net/http"
  4. "net/http/httptest"
  5. "testing"
  6. "github.com/Unknwon/macaron"
  7. "github.com/macaron-contrib/session"
  8. . "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestMiddlewareContext(t *testing.T) {
  11. Convey("Given grafana context", t, func() {
  12. m := macaron.New()
  13. m.Use(GetContextHandler())
  14. m.Use(Sessioner(&session.Options{}))
  15. var context *Context
  16. m.Get("/", func(c *Context) {
  17. context = c
  18. })
  19. resp := httptest.NewRecorder()
  20. req, err := http.NewRequest("GET", "/", nil)
  21. So(err, ShouldBeNil)
  22. m.ServeHTTP(resp, req)
  23. Convey("Should be able to get grafana context in handlers", func() {
  24. So(context, ShouldNotBeNil)
  25. })
  26. Convey("should return 200", func() {
  27. So(resp.Code, ShouldEqual, 200)
  28. })
  29. })
  30. }