You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cache_test.go 709B

12345678910111213141516171819202122232425262728293031
  1. package middleware
  2. import (
  3. "io"
  4. "net/http"
  5. "net/http/httptest"
  6. "testing"
  7. "github.com/goanywhere/rex"
  8. . "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestNoCache(t *testing.T) {
  11. app := rex.New()
  12. app.Use(NoCache)
  13. app.Get("/", func(w http.ResponseWriter, r *http.Request) {
  14. io.WriteString(w, "app")
  15. })
  16. Convey("rex.middleware.NoCache", t, func() {
  17. request, _ := http.NewRequest("GET", "/", nil)
  18. response := httptest.NewRecorder()
  19. app.ServeHTTP(response, request)
  20. header := response.Header()
  21. So(header.Get("Cache-Control"), ShouldEqual, "no-cache, no-store, must-revalidate")
  22. So(header.Get("Pragma"), ShouldEqual, "no-cache")
  23. So(header.Get("Expires"), ShouldEqual, "0")
  24. })
  25. }