forked from willnorris/webmention
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhttp_test.go
40 lines (36 loc) · 1.17 KB
/
http_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
// Copyright 2014 Google Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
package webmention
import (
"net/http"
"testing"
)
func TestHttpLink(t *testing.T) {
tests := []struct {
input []string
want string
}{
{[]string{`<foo>; rel="webmention"`}, "foo"},
{[]string{`<foo>; rel="a webmention b"`}, "foo"},
{[]string{`<foo>; rel="http://webmention.org"`}, "foo"},
{[]string{`<foo>; rel="http://webmention.org/"`}, "foo"},
{[]string{`<foo>; rel="https://webmention.org"`}, ""},
{[]string{`<foo>`}, ""},
{[]string{`<foo>; rel="a", <bar>; rel="webmention"`}, "bar"},
{[]string{`<foo>; rel="a"`, `<bar>; rel="webmention"`}, "bar"},
{[]string{`<foo>; rel="webmention", <bar>; rel="webmention"`}, "foo"},
{[]string{`<foo>; rel="webmention"`, `<bar>; rel="webmention"`}, "foo"},
}
for _, tt := range tests {
headers := make(http.Header)
for _, i := range tt.input {
headers.Add("Link", i)
}
if got := httpLink(headers); got != tt.want {
t.Errorf("httpLink(%q) got %v, want %v", headers, got, tt.want)
}
}
}