From 318df7645497cee70eed1e17fa7466eef44c4f51 Mon Sep 17 00:00:00 2001
From: Yasuhiro Matsumoto <mattn.jp@gmail.com>
Date: Wed, 19 Apr 2017 17:48:53 +0900
Subject: [PATCH] add test for linkHeader

---
 mastodon_test.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/mastodon_test.go b/mastodon_test.go
index 8005b75..1dfb53b 100644
--- a/mastodon_test.go
+++ b/mastodon_test.go
@@ -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)
+		}
+	}
+}