forked from codesenberg/bombardier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
headers_test.go
62 lines (57 loc) · 1.15 KB
/
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
60
61
62
package main
import (
"testing"
)
func TestHeadersToStringConversion(t *testing.T) {
expectations := []struct {
in headersList
out string
}{
{
[]header{},
"[]",
},
{
[]header{
{"Key1", "Value1"},
{"Key2", "Value2"}},
"[{Key1 Value1} {Key2 Value2}]",
},
}
for _, e := range expectations {
actual := e.in.String()
expected := e.out
if expected != actual {
t.Errorf("Expected \"%v\", but got \"%v\"", expected, actual)
}
}
}
func TestShouldErrorOnInvalidFormat(t *testing.T) {
h := new(headersList)
if err := h.Set("Yaba daba do"); err == nil {
t.Error("Should fail on strings without colon")
}
}
func TestShouldProperlyAddValidHeaders(t *testing.T) {
h := new(headersList)
for _, hs := range []string{"Key1: Value1", "Key2: Value2"} {
if err := h.Set(hs); err != nil {
t.Error(err)
}
}
e := []header{{"Key1", "Value1"}, {"Key2", "Value2"}}
for i, v := range *h {
if e[i] != v {
t.Fail()
}
}
}
func TestShouldTrimHeaderValues(t *testing.T) {
h := new(headersList)
if err := h.Set("Key: Value "); err != nil {
t.Error(err)
}
if (*h)[0].key != "Key" || (*h)[0].value != "Value" {
t.Fail()
}
}