File: service_test.go

package info (click to toggle)
golang-github-xenolf-lego 4.9.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,080 kB
  • sloc: xml: 533; makefile: 128; sh: 18
file content (56 lines) | stat: -rw-r--r-- 1,226 bytes parent folder | download | duplicates (3)
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
package api

import (
	"net/http"
	"testing"

	"github.com/stretchr/testify/assert"
)

func Test_getLink(t *testing.T) {
	testCases := []struct {
		desc     string
		header   http.Header
		relName  string
		expected string
	}{
		{
			desc: "success",
			header: http.Header{
				"Link": []string{`<https://acme-staging-v02.api.letsencrypt.org/next>; rel="next", <https://acme-staging-v02.api.letsencrypt.org/up?query>; rel="up"`},
			},
			relName:  "up",
			expected: "https://acme-staging-v02.api.letsencrypt.org/up?query",
		},
		{
			desc: "success several lines",
			header: http.Header{
				"Link": []string{`<https://acme-staging-v02.api.letsencrypt.org/next>; rel="next"`, `<https://acme-staging-v02.api.letsencrypt.org/up?query>; rel="up"`},
			},
			relName:  "up",
			expected: "https://acme-staging-v02.api.letsencrypt.org/up?query",
		},
		{
			desc:     "no link",
			header:   http.Header{},
			relName:  "up",
			expected: "",
		},
		{
			desc:     "no header",
			relName:  "up",
			expected: "",
		},
	}

	for _, test := range testCases {
		test := test
		t.Run(test.desc, func(t *testing.T) {
			t.Parallel()

			link := getLink(test.header, test.relName)

			assert.Equal(t, test.expected, link)
		})
	}
}