-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheaders_test.go
More file actions
49 lines (37 loc) · 1.05 KB
/
headers_test.go
File metadata and controls
49 lines (37 loc) · 1.05 KB
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
package webtools
import (
"net/http"
"net/http/httptest"
"testing"
"time"
"cattlecloud.net/go/scope"
"github.com/shoenig/test/must"
)
func Test_SetCacheControl(t *testing.T) {
t.Parallel()
w := httptest.NewRecorder()
SetCacheControl(w, 4*time.Minute)
must.Eq(t, "private, max-age=240", w.Header().Get("Cache-Control"))
}
func Test_SetContentType(t *testing.T) {
t.Parallel()
w := httptest.NewRecorder()
SetContentType(w, ContentTypeText)
must.Eq(t, "text/plain; charset=utf8", w.Header().Get("Content-Type"))
}
func Test_SetBasicAuth(t *testing.T) {
t.Parallel()
r, err := http.NewRequestWithContext(scope.New(), http.MethodGet, "/", nil)
must.NoError(t, err)
SetBasicAuth(r, "bob", "passw0rd")
value := r.Header.Get("Authorization")
must.Eq(t, "Basic Ym9iOnBhc3N3MHJk", value)
}
func Test_SetBasicAuth_empty(t *testing.T) {
t.Parallel()
r, err := http.NewRequestWithContext(scope.New(), http.MethodGet, "/", nil)
must.NoError(t, err)
SetBasicAuth(r, "bob", "")
value := r.Header.Get("Authorization")
must.Eq(t, "", value) // not set
}