diff options
Diffstat (limited to 'modules/httpcache/httpcache_test.go')
-rw-r--r-- | modules/httpcache/httpcache_test.go | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/modules/httpcache/httpcache_test.go b/modules/httpcache/httpcache_test.go index fe5ca17956..68ac892c91 100644 --- a/modules/httpcache/httpcache_test.go +++ b/modules/httpcache/httpcache_test.go @@ -8,6 +8,7 @@ import ( "net/http" "net/http/httptest" "os" + "strings" "testing" "time" @@ -24,6 +25,17 @@ func (m mockFileInfo) ModTime() time.Time { return time.Time{} } func (m mockFileInfo) IsDir() bool { return false } func (m mockFileInfo) Sys() interface{} { return nil } +func countFormalHeaders(h http.Header) (c int) { + for k := range h { + // ignore our headers for internal usage + if strings.HasPrefix(k, "X-Gitea-") { + continue + } + c++ + } + return c +} + func TestHandleFileETagCache(t *testing.T) { fi := mockFileInfo{} etag := `"MTBnaXRlYS50ZXN0TW9uLCAwMSBKYW4gMDAwMSAwMDowMDowMCBHTVQ="` @@ -35,7 +47,7 @@ func TestHandleFileETagCache(t *testing.T) { handled := HandleFileETagCache(req, w, fi) assert.False(t, handled) - assert.Len(t, w.Header(), 2) + assert.Equal(t, 2, countFormalHeaders(w.Header())) assert.Contains(t, w.Header(), "Cache-Control") assert.Contains(t, w.Header(), "Etag") assert.Equal(t, etag, w.Header().Get("Etag")) @@ -49,7 +61,7 @@ func TestHandleFileETagCache(t *testing.T) { handled := HandleFileETagCache(req, w, fi) assert.False(t, handled) - assert.Len(t, w.Header(), 2) + assert.Equal(t, 2, countFormalHeaders(w.Header())) assert.Contains(t, w.Header(), "Cache-Control") assert.Contains(t, w.Header(), "Etag") assert.Equal(t, etag, w.Header().Get("Etag")) @@ -63,7 +75,7 @@ func TestHandleFileETagCache(t *testing.T) { handled := HandleFileETagCache(req, w, fi) assert.True(t, handled) - assert.Len(t, w.Header(), 1) + assert.Equal(t, 1, countFormalHeaders(w.Header())) assert.Contains(t, w.Header(), "Etag") assert.Equal(t, etag, w.Header().Get("Etag")) assert.Equal(t, http.StatusNotModified, w.Code) @@ -80,7 +92,7 @@ func TestHandleGenericETagCache(t *testing.T) { handled := HandleGenericETagCache(req, w, etag) assert.False(t, handled) - assert.Len(t, w.Header(), 2) + assert.Equal(t, 2, countFormalHeaders(w.Header())) assert.Contains(t, w.Header(), "Cache-Control") assert.Contains(t, w.Header(), "Etag") assert.Equal(t, etag, w.Header().Get("Etag")) @@ -94,7 +106,7 @@ func TestHandleGenericETagCache(t *testing.T) { handled := HandleGenericETagCache(req, w, etag) assert.False(t, handled) - assert.Len(t, w.Header(), 2) + assert.Equal(t, 2, countFormalHeaders(w.Header())) assert.Contains(t, w.Header(), "Cache-Control") assert.Contains(t, w.Header(), "Etag") assert.Equal(t, etag, w.Header().Get("Etag")) @@ -108,7 +120,7 @@ func TestHandleGenericETagCache(t *testing.T) { handled := HandleGenericETagCache(req, w, etag) assert.True(t, handled) - assert.Len(t, w.Header(), 1) + assert.Equal(t, 1, countFormalHeaders(w.Header())) assert.Contains(t, w.Header(), "Etag") assert.Equal(t, etag, w.Header().Get("Etag")) assert.Equal(t, http.StatusNotModified, w.Code) @@ -122,7 +134,7 @@ func TestHandleGenericETagCache(t *testing.T) { handled := HandleGenericETagCache(req, w, etag) assert.False(t, handled) - assert.Len(t, w.Header(), 2) + assert.Equal(t, 2, countFormalHeaders(w.Header())) assert.Contains(t, w.Header(), "Cache-Control") assert.Contains(t, w.Header(), "Etag") assert.Equal(t, etag, w.Header().Get("Etag")) @@ -136,7 +148,7 @@ func TestHandleGenericETagCache(t *testing.T) { handled := HandleGenericETagCache(req, w, etag) assert.True(t, handled) - assert.Len(t, w.Header(), 1) + assert.Equal(t, 1, countFormalHeaders(w.Header())) assert.Contains(t, w.Header(), "Etag") assert.Equal(t, etag, w.Header().Get("Etag")) assert.Equal(t, http.StatusNotModified, w.Code) |