mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-17 20:52:14 +01:00
adding WebhookURLTimeoutArg for retrieving and validating webhookURLTimeout form field
This commit is contained in:
@@ -121,6 +121,27 @@ func WaitDelayArg(r Resource, config conf.Config) (float64, error) {
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
WebhookURLTimeoutArg is a helper for retrieving
|
||||||
|
the "webhookURLTimeout" argument as float64.
|
||||||
|
|
||||||
|
It also validates it against the application
|
||||||
|
configuration.
|
||||||
|
*/
|
||||||
|
func WebhookURLTimeoutArg(r Resource, config conf.Config) (float64, error) {
|
||||||
|
const op string = "resource.WebhookURLTimeoutArg"
|
||||||
|
result, err := r.Float64Arg(
|
||||||
|
WebhookURLTimeoutArgKey,
|
||||||
|
config.DefaultWebhookURLTimeout(),
|
||||||
|
xassert.Float64NotInferiorTo(0),
|
||||||
|
xassert.Float64NotSuperiorTo(config.MaximumWebhookURLTimeout()),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return result, xerror.New(op, err)
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
PaperSizeArgs is a helper for retrieving
|
PaperSizeArgs is a helper for retrieving
|
||||||
the "paperWidth" and "paperHeight" arguments
|
the "paperWidth" and "paperHeight" arguments
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ func TestWaitDelayArg(t *testing.T) {
|
|||||||
test.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
assert.Equal(t, expected, v)
|
assert.Equal(t, expected, v)
|
||||||
// shoul not be OK as argument
|
// shoul not be OK as argument
|
||||||
// value is > config.MaximumWaitTimeout().
|
// value is > config.MaximumWaitDelay().
|
||||||
expected = defaultValue
|
expected = defaultValue
|
||||||
r.WithArg(WaitDelayArgKey, "31.0")
|
r.WithArg(WaitDelayArgKey, "31.0")
|
||||||
v, err = WaitDelayArg(r, config)
|
v, err = WaitDelayArg(r, config)
|
||||||
@@ -119,6 +119,50 @@ func TestWaitDelayArg(t *testing.T) {
|
|||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestWebhookURLTimeoutArg(t *testing.T) {
|
||||||
|
const resourceDirectoryName string = "foo"
|
||||||
|
var expected float64
|
||||||
|
logger := test.DebugLogger()
|
||||||
|
config := conf.DefaultConfig()
|
||||||
|
r, err := New(logger, resourceDirectoryName)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
// argument does not exist.
|
||||||
|
expected = config.DefaultWebhookURLTimeout()
|
||||||
|
v, err := WebhookURLTimeoutArg(r, config)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
assert.Equal(t, expected, v)
|
||||||
|
// argument exist.
|
||||||
|
expected = 5.0
|
||||||
|
r.WithArg(WebhookURLTimeoutArgKey, "5.0")
|
||||||
|
v, err = WebhookURLTimeoutArg(r, config)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
assert.Equal(t, expected, v)
|
||||||
|
// shoul not be OK as argument
|
||||||
|
// value is < 0.
|
||||||
|
expected = config.DefaultWebhookURLTimeout()
|
||||||
|
r.WithArg(WebhookURLTimeoutArgKey, "-1.0")
|
||||||
|
v, err = WebhookURLTimeoutArg(r, config)
|
||||||
|
test.AssertError(t, err)
|
||||||
|
assert.Equal(t, expected, v)
|
||||||
|
// shoul not be OK as argument
|
||||||
|
// value is > config.MaximumWebhookURLTimeout().
|
||||||
|
expected = config.DefaultWebhookURLTimeout()
|
||||||
|
r.WithArg(WebhookURLTimeoutArgKey, "31.0")
|
||||||
|
v, err = WebhookURLTimeoutArg(r, config)
|
||||||
|
test.AssertError(t, err)
|
||||||
|
assert.Equal(t, expected, v)
|
||||||
|
// should not be OK as
|
||||||
|
// argument value is invalid.
|
||||||
|
expected = config.DefaultWebhookURLTimeout()
|
||||||
|
r.WithArg(WebhookURLTimeoutArgKey, "foo")
|
||||||
|
v, err = WebhookURLTimeoutArg(r, config)
|
||||||
|
test.AssertError(t, err)
|
||||||
|
assert.Equal(t, expected, v)
|
||||||
|
// finally...
|
||||||
|
err = r.Close()
|
||||||
|
assert.Nil(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
func TestPaperSizeArgs(t *testing.T) {
|
func TestPaperSizeArgs(t *testing.T) {
|
||||||
const resourceDirectoryName string = "foo"
|
const resourceDirectoryName string = "foo"
|
||||||
var expected float64
|
var expected float64
|
||||||
|
|||||||
Reference in New Issue
Block a user