add test for linkHeader

pull/28/head
Yasuhiro Matsumoto 2017-04-19 17:48:53 +09:00
parent 00bd1f0aba
commit 318df76454
1 changed files with 46 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import (
"io"
"net/http"
"net/http/httptest"
"reflect"
"testing"
)
@ -125,3 +126,48 @@ func TestForTheCoverages(t *testing.T) {
(*ErrorEvent)(nil).event()
_ = (&ErrorEvent{io.EOF}).Error()
}
func TestLinkHeader(t *testing.T) {
tests := []struct {
header []string
rel string
want []string
}{
{
header: []string{`<http://example.com/?max_id=3>; rel="foo"`},
rel: "boo",
want: nil,
},
{
header: []string{`<http://example.com/?max_id=3>; rel="foo"`},
rel: "foo",
want: []string{"http://example.com/?max_id=3"},
},
{
header: []string{`<http://example.com/?max_id=3>; rel="foo1"`},
rel: "foo",
want: nil,
},
{
header: []string{`<http://example.com/?max_id=3>; rel="foo", <http://example.com/?max_id=4>; rel="bar"`},
rel: "foo",
want: []string{"http://example.com/?max_id=3"},
},
{
header: []string{`<http://example.com/?max_id=3>; rel="foo", <http://example.com/?max_id=4>; rel="bar"`},
rel: "bar",
want: []string{"http://example.com/?max_id=4"},
},
}
for _, test := range tests {
h := make(http.Header)
for _, he := range test.header {
h.Add("Link", he)
}
got := linkHeader(h, test.rel)
if !reflect.DeepEqual(got, test.want) {
t.Fatalf("want %v but %v", test.want, got)
}
}
}