Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

35 lines
726B

  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. }