Files
gin-contrib/nocache/nocache_test.go
T
2024-04-02 15:13:13 +03:00

36 lines
764 B
Go

package nocache
import (
"context"
"net/http"
"net/http/httptest"
"testing"
"time"
"git.company.lan/gopkg/gin"
)
func Test_NoCacheHeaders(t *testing.T) {
responseHeaders := map[string]string{
"Cache-Control": "no-cache, no-store, no-transform, must-revalidate, private, max-age=0",
"Pragma": "no-cache",
"Expires": time.Unix(0, 0).UTC().Format(http.TimeFormat),
}
m := gin.New()
m.Use(NoCache())
recorder := httptest.NewRecorder()
r, _ := http.NewRequestWithContext(context.Background(), "GET", "/", nil)
for _, k := range etagHeaders {
r.Header.Add(k, "value")
}
m.ServeHTTP(recorder, r)
for key, value := range responseHeaders {
if recorder.Header()[key][0] != value {
t.Errorf("Missing header: %s", key)
}
}
}