forked from lox/httpcache
/
key_test.go
60 lines (43 loc) · 1.52 KB
/
key_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
package httpcache_test
import (
"net/url"
"testing"
"github.com/lox/httpcache"
"github.com/stretchr/testify/assert"
)
func mustParseUrl(u string) *url.URL {
ru, err := url.Parse(u)
if err != nil {
panic(err)
}
return ru
}
func TestKeysDiffer(t *testing.T) {
k1 := httpcache.NewKey("GET", mustParseUrl("http://x.org/test"), nil)
k2 := httpcache.NewKey("GET", mustParseUrl("http://y.org/test"), nil)
assert.NotEqual(t, k1.String(), k2.String())
}
func TestRequestKey(t *testing.T) {
r := newRequest("GET", "http://x.org/test")
k1 := httpcache.NewKey("GET", mustParseUrl("http://x.org/test"), nil)
k2 := httpcache.NewRequestKey(r)
assert.Equal(t, k1.String(), k2.String())
}
func TestVaryKey(t *testing.T) {
r := newRequest("GET", "http://x.org/test", "Llamas-1: true", "Llamas-2: false")
k1 := httpcache.NewRequestKey(r)
k2 := httpcache.NewRequestKey(r).Vary("Llamas-1, Llamas-2", r)
assert.NotEqual(t, k1.String(), k2.String())
}
func TestRequestKeyWithContentLocation(t *testing.T) {
r := newRequest("GET", "http://x.org/test1", "Content-Location: http://x.org/test2")
k1 := httpcache.NewKey("GET", mustParseUrl("http://x.org/test2"), nil)
k2 := httpcache.NewRequestKey(r)
assert.Equal(t, k1.String(), k2.String())
}
func TestRequestKeyWithIllegalContentLocation(t *testing.T) {
r := newRequest("GET", "http://x.org/test1", "Content-Location: http://y.org/test2")
k1 := httpcache.NewKey("GET", mustParseUrl("http://x.org/test1"), nil)
k2 := httpcache.NewRequestKey(r)
assert.Equal(t, k1.String(), k2.String())
}