mirror of
https://github.com/go-acme/lego.git
synced 2024-12-23 01:07:23 +02:00
56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
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 {
|
|
t.Run(test.desc, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
link := getLink(test.header, test.relName)
|
|
|
|
assert.Equal(t, test.expected, link)
|
|
})
|
|
}
|
|
}
|