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.

static_test.go 726B

9 yıl önce
9 yıl önce
9 yıl önce
12345678910111213141516171819202122232425262728293031323334
  1. package middleware
  2. import (
  3. "io"
  4. "net/http"
  5. "net/http/httptest"
  6. "os"
  7. "path"
  8. "testing"
  9. "github.com/goanywhere/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. }