2019-03-11 16:56:48 +00:00
|
|
|
package api
|
2018-12-06 21:50:17 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|