mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-16 20:32:13 +01:00
rolling back to golangci-lint 1.20.1 + moving normize filename to resource & tests with a file with special chars in its name + webhookurl custom headers done + preparing remote url custom headers
This commit is contained in:
62
internal/app/xhttp/pkg/resource/header_test.go
Normal file
62
internal/app/xhttp/pkg/resource/header_test.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package resource
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/thecodingmachine/gotenberg/test"
|
||||
)
|
||||
|
||||
func TestRemoteURLCustomHeaders(t *testing.T) {
|
||||
const resourceDirectoryName string = "foo"
|
||||
logger := test.DebugLogger()
|
||||
r, err := New(logger, resourceDirectoryName)
|
||||
assert.Nil(t, err)
|
||||
// should find the custom header.
|
||||
customHeaderValue := "bar"
|
||||
customHeaderCanonicalRealKey := "Foo"
|
||||
customHeaderCanonicalKey := http.CanonicalHeaderKey(fmt.Sprintf("%s%s", RemoteURLCustomHeaderCanonicalBaseKey, customHeaderCanonicalRealKey))
|
||||
r.WithCustomHeader(customHeaderCanonicalKey, []string{customHeaderValue})
|
||||
r.WithCustomHeader("Bar", []string{"Bar"})
|
||||
expected := map[string][]string{
|
||||
customHeaderCanonicalRealKey: []string{
|
||||
customHeaderValue,
|
||||
},
|
||||
}
|
||||
notExpected := map[string][]string{
|
||||
customHeaderCanonicalKey: []string{
|
||||
customHeaderValue,
|
||||
},
|
||||
}
|
||||
v := RemoteURLCustomHeaders(r)
|
||||
assert.Equal(t, expected, v)
|
||||
assert.NotEqual(t, notExpected, v)
|
||||
}
|
||||
|
||||
func TestWebhookURLCustomHeaders(t *testing.T) {
|
||||
const resourceDirectoryName string = "foo"
|
||||
logger := test.DebugLogger()
|
||||
r, err := New(logger, resourceDirectoryName)
|
||||
assert.Nil(t, err)
|
||||
// should find the custom header.
|
||||
customHeaderValue := "bar"
|
||||
customHeaderCanonicalRealKey := "Foo"
|
||||
customHeaderCanonicalKey := http.CanonicalHeaderKey(fmt.Sprintf("%s%s", WebhookURLCustomHeaderCanonicalBaseKey, customHeaderCanonicalRealKey))
|
||||
r.WithCustomHeader(customHeaderCanonicalKey, []string{customHeaderValue})
|
||||
r.WithCustomHeader("Bar", []string{"Bar"})
|
||||
expected := map[string][]string{
|
||||
customHeaderCanonicalRealKey: []string{
|
||||
customHeaderValue,
|
||||
},
|
||||
}
|
||||
notExpected := map[string][]string{
|
||||
customHeaderCanonicalKey: []string{
|
||||
customHeaderValue,
|
||||
},
|
||||
}
|
||||
v := WebhookURLCustomHeaders(r)
|
||||
assert.Equal(t, expected, v)
|
||||
assert.NotEqual(t, notExpected, v)
|
||||
}
|
||||
Reference in New Issue
Block a user