This repository has been archived by the owner on Mar 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
helpers_test.go
82 lines (75 loc) · 2.08 KB
/
helpers_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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"testing"
"net/http"
)
func TestVerifyContentType(t *testing.T) {
tables := []struct {
x string
y bool
}{
{"text/css", true},
{"text/javascript", true},
{"image/png", true},
{"image/jpeg", true},
{"image/pong", false},
{"image/jpg", false},
}
mockHeader := http.Header{}
mockHeader.Add("Content-Type", "")
for _, table := range tables {
mockHeader.Set("Content-Type", table.x)
result := verifyContentType(mockHeader)
if result != table.y {
t.Errorf("Content type verification returned unexpected result [%t] for value [%s]. Expected [%t].",
result, table.x, table.y)
}
}
}
func TestDefineCacheControl(t *testing.T) {
tables := []struct {
x string
i bool
r bool
m int
}{
{"private", true, false, 3600},
{"no-store", true, false, 3600},
{"private, no-store", true, false, 3600},
{"no-cache", false, true, 3600},
{"must-revalidate", false, true, 3600},
{"no-cache, must-revalidate", false, true, 3600},
{"private, no-cache", true, true, 3600},
{"no-store, must-revalidate", true, true, 3600},
{"max-age:7200", false, false, 7200},
{"private, max-age:7200", true, false, 7200},
{"no-cache, max-age:7200", false, true, 7200},
{"private, no-cache, max-age:7200", true, true, 7200},
}
mockHeader := http.Header{}
mockHeader.Add("Cache-Control", "")
for _, table := range tables {
mockHeader.Set("Cache-Control", table.x)
i, r, m := defineCacheControl(mockHeader)
if i != table.i || r != table.r || m != table.m {
t.Errorf("Cache control definition returned unexpected result [%t, %t, %d] for value [%s]. Expected [%t, %t, %d].",
i, r, m, table.x, table.i, table.r, table.m)
}
}
}
func TestCreateHash(t *testing.T) {
tables := []struct {
x string
y string
}{
{"http://www.google.nl", "3d04d47edbf1d492cd15bf9fa1950b4f"},
{"http://www.google.com", "ed646a3334ca891fd3467db131372140"},
}
for _, table := range tables {
result := createHash(table.x)
if result != table.y {
t.Errorf("Create hash returned unexpected result [%s] for value [%s]. Expected [%s].",
result, table.x, table.y)
}
}
}