-
Notifications
You must be signed in to change notification settings - Fork 6
/
set_headers_test.go
59 lines (46 loc) · 1.43 KB
/
set_headers_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (c) 2016, Janoš Guljaš <[email protected]>
// All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package web
import (
"net/http"
"net/http/httptest"
"testing"
)
func TestNewSetHeadersHandler(t *testing.T) {
r := httptest.NewRequest("", "/", nil)
w := httptest.NewRecorder()
key := "X-Test"
value := "1234"
NewSetHeadersHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}), map[string]string{key: value}).
ServeHTTP(w, r)
v := w.Header().Get(key)
if v != value {
t.Errorf("expected %s value for header %s, but got %s", value, key, v)
}
}
func TestNoCacheHeadersHandler(t *testing.T) {
r := httptest.NewRequest("", "/", nil)
w := httptest.NewRecorder()
NoCacheHeadersHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})).
ServeHTTP(w, r)
for key, value := range noCacheHeaders {
v := w.Header().Get(key)
if v != value {
t.Errorf("expected %s value for header %s, but got %s", value, key, v)
}
}
}
func TestNoExpireHeadersHandler(t *testing.T) {
r := httptest.NewRequest("", "/", nil)
w := httptest.NewRecorder()
NoExpireHeadersHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})).
ServeHTTP(w, r)
for key, value := range noExpireHeaders {
v := w.Header().Get(key)
if v != value {
t.Errorf("expected %s value for header %s, but got %s", value, key, v)
}
}
}