Fix order when reading custom headers in resources.GetRemote

Fixes #10616
This commit is contained in:
Bjørn Erik Pedersen
2023-01-16 11:00:55 +01:00
parent 6e9fa9e0fd
commit b5d485060f
2 changed files with 54 additions and 12 deletions

View File

@@ -20,6 +20,8 @@ import (
)
func TestDecodeRemoteOptions(t *testing.T) {
t.Parallel()
c := qt.New(t)
for _, test := range []struct {
@@ -81,10 +83,43 @@ func TestDecodeRemoteOptions(t *testing.T) {
})
}
}
func TestOptionsNewRequest(t *testing.T) {
t.Parallel()
c := qt.New(t)
opts := fromRemoteOptions{
Method: "GET",
Body: []byte("foo"),
}
req, err := opts.NewRequest("https://example.com/api")
c.Assert(err, qt.IsNil)
c.Assert(req.Method, qt.Equals, "GET")
c.Assert(req.Header["User-Agent"], qt.DeepEquals, []string{"Hugo Static Site Generator"})
opts = fromRemoteOptions{
Method: "GET",
Body: []byte("foo"),
Headers: map[string]any{
"User-Agent": "foo",
},
}
req, err = opts.NewRequest("https://example.com/api")
c.Assert(err, qt.IsNil)
c.Assert(req.Method, qt.Equals, "GET")
c.Assert(req.Header["User-Agent"], qt.DeepEquals, []string{"foo"})
}
func TestCalculateResourceID(t *testing.T) {
t.Parallel()
c := qt.New(t)
c.Assert(calculateResourceID("foo", nil), qt.Equals, "5917621528921068675")