-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.go
42 lines (34 loc) · 929 Bytes
/
utils_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
package cors
import (
"strings"
"testing"
"github.com/gotoxu/assert"
)
func TestWildcard(t *testing.T) {
w := wildcard{"foo", "bar"}
assert.True(t, w.match("foobar"))
assert.True(t, w.match("foobazbar"))
assert.False(t, w.match("foobaz"))
}
func TestConvert(t *testing.T) {
s := convert([]string{"A", "b", "C"}, strings.ToLower)
e := []string{"a", "b", "c"}
assert.DeepEqual(t, s, e)
}
func TestParseHeaderList(t *testing.T) {
h := parseHeaderList("header, second-header, THIRD-HEADER, Numb3r3d-H34d3r")
e := []string{"Header", "Second-Header", "Third-Header", "Numb3r3d-H34d3r"}
assert.DeepEqual(t, h, e)
}
func TestParseHeaderListEmpty(t *testing.T) {
h1 := parseHeaderList("")
assert.Empty(t, h1)
h2 := parseHeaderList(", ")
assert.Empty(t, h2)
}
func BenchmarkParseHeaderList(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
parseHeaderList("header, second-header, THIRD-HEADER")
}
}