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.

12345678910111213141516171819202122232425262728293031323334
  1. package middleware
  2. import (
  3. "io"
  4. "net/http"
  5. "net/http/httptest"
  6. "os"
  7. "path"
  8. "testing"
  9. "git.thevis.us/skepto/rex"
  10. . "github.com/smartystreets/goconvey/convey"
  11. )
  12. func TestStatic(t *testing.T) {
  13. tempdir := os.TempDir()
  14. filename := path.Join(tempdir, "favicon.ico")
  15. app := rex.New()
  16. app.Use(Static(tempdir))
  17. prefix := path.Join("/", path.Base(path.Dir(filename)))
  18. app.Get(prefix, func(w http.ResponseWriter, r *http.Request) {
  19. io.WriteString(w, "app")
  20. })
  21. Convey("rex.middleware.Static", t, func() {
  22. request, _ := http.NewRequest("GET", path.Join(prefix, filename), nil)
  23. response := httptest.NewRecorder()
  24. app.ServeHTTP(response, request)
  25. So(response.Code, ShouldEqual, http.StatusNotFound)
  26. })
  27. }