Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

middleware_test.go 954B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package rex
  2. import (
  3. "net/http"
  4. "net/http/httptest"
  5. "testing"
  6. . "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestMiddleware(t *testing.T) {
  9. env := func(next http.Handler) http.Handler {
  10. return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  11. w.Header().Set("X-Powered-By", "rex")
  12. next.ServeHTTP(w, r)
  13. })
  14. }
  15. json := func(next http.Handler) http.Handler {
  16. return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  17. next.ServeHTTP(w, r)
  18. w.Header().Set("Content-Type", "application/json")
  19. })
  20. }
  21. mw := new(middleware)
  22. mw.stack = append(mw.stack, env)
  23. mw.stack = append(mw.stack, json)
  24. Convey("rex.middleware", t, func() {
  25. request, _ := http.NewRequest("GET", "/", nil)
  26. response := httptest.NewRecorder()
  27. mw.ServeHTTP(response, request)
  28. So(response.Header().Get("X-Powered-By"), ShouldEqual, "rex")
  29. So(response.Header().Get("Content-Type"), ShouldEqual, "application/json")
  30. })
  31. }