소스 검색

(mw) NoCache + Header tests

tags/v0.9.0
jimzhan 9 년 전
부모
커밋
adb7893e70
3개의 변경된 파일63개의 추가작업 그리고 0개의 파일을 삭제
  1. +31
    -0
      middleware/cache_test.go
  2. +1
    -0
      middleware/compress_test.go
  3. +31
    -0
      middleware/header_test.go

+ 31
- 0
middleware/cache_test.go 파일 보기

@@ -0,0 +1,31 @@
package middleware

import (
"io"
"net/http"
"net/http/httptest"
"testing"

"github.com/goanywhere/rex"
. "github.com/smartystreets/goconvey/convey"
)

func TestNoCache(t *testing.T) {
app := rex.New()
app.Use(NoCache)
app.GET("/", func(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "app")
})

Convey("rex.middleware.NoCache", t, func() {
request, _ := http.NewRequest("GET", "/", nil)
response := httptest.NewRecorder()

app.ServeHTTP(response, request)

header := response.Header()
So(header.Get("Cache-Control"), ShouldEqual, "no-cache, no-store, must-revalidate")
So(header.Get("Pragma"), ShouldEqual, "no-cache")
So(header.Get("Expires"), ShouldEqual, "0")
})
}

+ 1
- 0
middleware/compress_test.go 파일 보기

@@ -0,0 +1 @@
package middleware

+ 31
- 0
middleware/header_test.go 파일 보기

@@ -0,0 +1,31 @@
package middleware

import (
"io"
"net/http"
"net/http/httptest"
"testing"

"github.com/goanywhere/rex"
. "github.com/smartystreets/goconvey/convey"
)

func TestHeader(t *testing.T) {
var values = make(map[string]string)
values["X-Powered-By"] = "rex server"

app := rex.New()
app.Use(Header(values))
app.GET("/", func(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "app")
})

Convey("rex.middleware.Header", t, func() {
request, _ := http.NewRequest("GET", "/", nil)
response := httptest.NewRecorder()

app.ServeHTTP(response, request)

So(response.Header().Get("X-Powered-By"), ShouldEqual, "rex server")
})
}

Loading…
취소
저장