mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-17 20:52:14 +01:00
refactoring tests util methods + adding context tests
This commit is contained in:
1
go.mod
1
go.mod
@@ -19,5 +19,4 @@ require (
|
|||||||
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 // indirect
|
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 // indirect
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58
|
||||||
golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7 // indirect
|
golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7 // indirect
|
||||||
golang.org/x/tools v0.0.0-20190723021737-8bb11ff117ca // indirect
|
|
||||||
)
|
)
|
||||||
|
|||||||
11
go.sum
11
go.sum
@@ -15,8 +15,7 @@ github.com/labstack/echo/v4 v4.1.6 h1:WOvLa4T1KzWCRpANwz0HGgWDelXSSGwIKtKBbFdHTv
|
|||||||
github.com/labstack/echo/v4 v4.1.6/go.mod h1:kU/7PwzgNxZH4das4XNsSpBSOD09XIF5YEPzjpkGnGE=
|
github.com/labstack/echo/v4 v4.1.6/go.mod h1:kU/7PwzgNxZH4das4XNsSpBSOD09XIF5YEPzjpkGnGE=
|
||||||
github.com/labstack/gommon v0.2.9 h1:heVeuAYtevIQVYkGj6A41dtfT91LrvFG220lavpWhrU=
|
github.com/labstack/gommon v0.2.9 h1:heVeuAYtevIQVYkGj6A41dtfT91LrvFG220lavpWhrU=
|
||||||
github.com/labstack/gommon v0.2.9/go.mod h1:E8ZTmW9vw5az5/ZyHWCp0Lw4OH2ecsaBP1C/NKavGG4=
|
github.com/labstack/gommon v0.2.9/go.mod h1:E8ZTmW9vw5az5/ZyHWCp0Lw4OH2ecsaBP1C/NKavGG4=
|
||||||
github.com/mafredri/cdp v0.23.4 h1:ffp4qq6slfCL4rFWBDeRHapkLE776gER4tX5Z3LS8CY=
|
github.com/mafredri/cdp v0.24.2 h1:Rzhj/EQw9opbiwUpNML7P+4Hvf0/nSYPaDbiCEpILOM=
|
||||||
github.com/mafredri/cdp v0.23.4/go.mod h1:hgdiA0yp1uqhSaDOHJWPgXpMbh+LAfUdD9vbN2AM8gE=
|
|
||||||
github.com/mafredri/cdp v0.24.2/go.mod h1:hgdiA0yp1uqhSaDOHJWPgXpMbh+LAfUdD9vbN2AM8gE=
|
github.com/mafredri/cdp v0.24.2/go.mod h1:hgdiA0yp1uqhSaDOHJWPgXpMbh+LAfUdD9vbN2AM8gE=
|
||||||
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
|
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
|
||||||
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||||
@@ -50,9 +49,7 @@ golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73r
|
|||||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
golang.org/x/net v0.0.0-20190607181551-461777fb6f67/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190607181551-461777fb6f67/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 h1:Ao/3l156eZf2AW5wK8a7/smtodRU+gha3+BeqJ69lRk=
|
||||||
golang.org/x/net v0.0.0-20190628185345-da137c7871d7 h1:rTIdg5QFRR7XCaK4LCjBiPbx8j4DQRpdYMnGn/bJUEU=
|
|
||||||
golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
|
||||||
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
@@ -62,12 +59,10 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20190602015325-4c4f7f33c9ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190602015325-4c4f7f33c9ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20190609082536-301114b31cce/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190609082536-301114b31cce/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb h1:fgwFCsaw9buMuxNd6+DQfAuSFqbNiQZpcgJQAgJsK6k=
|
golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7 h1:LepdCS8Gf/MVejFIt8lsiexZATdoGVyp5bcyS+rYoUI=
|
||||||
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
||||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20190608022120-eacb66d2a7c3/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
golang.org/x/tools v0.0.0-20190608022120-eacb66d2a7c3/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||||
golang.org/x/tools v0.0.0-20190723021737-8bb11ff117ca/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI=
|
|
||||||
|
|||||||
78
internal/app/xhttp/pkg/context/context_test.go
Normal file
78
internal/app/xhttp/pkg/context/context_test.go
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
package context
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/thecodingmachine/gotenberg/internal/pkg/conf"
|
||||||
|
"github.com/thecodingmachine/gotenberg/test"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMustCastFromEchoContext(t *testing.T) {
|
||||||
|
// should be OK.
|
||||||
|
ctx := New(
|
||||||
|
test.DummyEchoContext(),
|
||||||
|
test.DebugLogger(),
|
||||||
|
conf.DefaultConfig(),
|
||||||
|
)
|
||||||
|
assert.NotPanics(t, func() {
|
||||||
|
result := MustCastFromEchoContext(ctx)
|
||||||
|
assert.Equal(t, ctx, result)
|
||||||
|
})
|
||||||
|
// should not be OK.
|
||||||
|
assert.Panics(t, func() {
|
||||||
|
MustCastFromEchoContext(test.DummyEchoContext())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLogRequestResult(t *testing.T) {
|
||||||
|
ctx := New(
|
||||||
|
test.DummyEchoContext(),
|
||||||
|
test.DebugLogger(),
|
||||||
|
conf.DefaultConfig(),
|
||||||
|
)
|
||||||
|
// Info log.
|
||||||
|
err := ctx.LogRequestResult(nil, false)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
// Debug log.
|
||||||
|
err = ctx.LogRequestResult(nil, true)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
// Error log.
|
||||||
|
err = ctx.LogRequestResult(errors.New("foo"), true)
|
||||||
|
assert.NotNil(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetters(t *testing.T) {
|
||||||
|
const resourceDirectoryName string = "foo"
|
||||||
|
logger := test.DebugLogger()
|
||||||
|
config := conf.DefaultConfig()
|
||||||
|
ctx := New(
|
||||||
|
test.DummyEchoContext(),
|
||||||
|
logger,
|
||||||
|
config,
|
||||||
|
)
|
||||||
|
// Logger.
|
||||||
|
assert.Equal(t, logger, ctx.XLogger())
|
||||||
|
// Config.
|
||||||
|
assert.Equal(t, config, ctx.Config())
|
||||||
|
// Context should not have a resource.Resource.
|
||||||
|
assert.Equal(t, false, ctx.HasResource())
|
||||||
|
assert.Panics(t, func() {
|
||||||
|
ctx.MustResource()
|
||||||
|
})
|
||||||
|
// Context should have a resource.Resource.
|
||||||
|
ctx = New(
|
||||||
|
test.EchoContextMultipart(t),
|
||||||
|
logger,
|
||||||
|
config,
|
||||||
|
)
|
||||||
|
err := ctx.WithResource(resourceDirectoryName)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
assert.Equal(t, true, ctx.HasResource())
|
||||||
|
assert.NotPanics(t, func() {
|
||||||
|
r := ctx.MustResource()
|
||||||
|
err = r.Close()
|
||||||
|
assert.Nil(t, err)
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -32,7 +32,9 @@ type Config struct {
|
|||||||
logLevel xlog.Level
|
logLevel xlog.Level
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultConfig() Config {
|
// DefaultConfig returns the default
|
||||||
|
// configuration.
|
||||||
|
func DefaultConfig() Config {
|
||||||
return Config{
|
return Config{
|
||||||
maximumWaitTimeout: 30.0,
|
maximumWaitTimeout: 30.0,
|
||||||
maximumWaitDelay: 10.0,
|
maximumWaitDelay: 10.0,
|
||||||
@@ -53,7 +55,7 @@ to environment variables.
|
|||||||
func FromEnv() (Config, error) {
|
func FromEnv() (Config, error) {
|
||||||
const op string = "conf.FromEnv"
|
const op string = "conf.FromEnv"
|
||||||
resolver := func() (Config, error) {
|
resolver := func() (Config, error) {
|
||||||
c := defaultConfig()
|
c := DefaultConfig()
|
||||||
maximumWaitTimeout, err := xassert.Float64FromEnv(
|
maximumWaitTimeout, err := xassert.Float64FromEnv(
|
||||||
maximumWaitTimeoutEnvVar,
|
maximumWaitTimeoutEnvVar,
|
||||||
c.maximumWaitTimeout,
|
c.maximumWaitTimeout,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/thecodingmachine/gotenberg/internal/pkg/xlog"
|
"github.com/thecodingmachine/gotenberg/internal/pkg/xlog"
|
||||||
"github.com/thecodingmachine/gotenberg/test/internalpkg/xerrortest"
|
"github.com/thecodingmachine/gotenberg/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestEmptyFromEnv(t *testing.T) {
|
func TestEmptyFromEnv(t *testing.T) {
|
||||||
@@ -17,7 +17,7 @@ func TestEmptyFromEnv(t *testing.T) {
|
|||||||
)
|
)
|
||||||
// no environment variables set,
|
// no environment variables set,
|
||||||
// values should be equal to default config.
|
// values should be equal to default config.
|
||||||
expected = defaultConfig()
|
expected = DefaultConfig()
|
||||||
result, err = FromEnv()
|
result, err = FromEnv()
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, expected, result)
|
assert.Equal(t, expected, result)
|
||||||
@@ -31,7 +31,7 @@ func TestMaximumWaitTimeoutFromEnv(t *testing.T) {
|
|||||||
)
|
)
|
||||||
// MAXIMUM_WAIT_TIMEOUT correctly set.
|
// MAXIMUM_WAIT_TIMEOUT correctly set.
|
||||||
os.Setenv(maximumWaitTimeoutEnvVar, "10.0")
|
os.Setenv(maximumWaitTimeoutEnvVar, "10.0")
|
||||||
expected = defaultConfig()
|
expected = DefaultConfig()
|
||||||
expected.maximumWaitTimeout = 10.0
|
expected.maximumWaitTimeout = 10.0
|
||||||
result, err = FromEnv()
|
result, err = FromEnv()
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
@@ -39,16 +39,16 @@ func TestMaximumWaitTimeoutFromEnv(t *testing.T) {
|
|||||||
os.Unsetenv(maximumWaitTimeoutEnvVar)
|
os.Unsetenv(maximumWaitTimeoutEnvVar)
|
||||||
// MAXIMUM_WAIT_TIMEOUT wrongly set.
|
// MAXIMUM_WAIT_TIMEOUT wrongly set.
|
||||||
os.Setenv(maximumWaitTimeoutEnvVar, "foo")
|
os.Setenv(maximumWaitTimeoutEnvVar, "foo")
|
||||||
expected = defaultConfig()
|
expected = DefaultConfig()
|
||||||
result, err = FromEnv()
|
result, err = FromEnv()
|
||||||
xerrortest.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
assert.Equal(t, expected, result)
|
assert.Equal(t, expected, result)
|
||||||
os.Unsetenv(maximumWaitTimeoutEnvVar)
|
os.Unsetenv(maximumWaitTimeoutEnvVar)
|
||||||
// MAXIMUM_WAIT_TIMEOUT < 0.
|
// MAXIMUM_WAIT_TIMEOUT < 0.
|
||||||
os.Setenv(maximumWaitTimeoutEnvVar, "-1.0")
|
os.Setenv(maximumWaitTimeoutEnvVar, "-1.0")
|
||||||
expected = defaultConfig()
|
expected = DefaultConfig()
|
||||||
result, err = FromEnv()
|
result, err = FromEnv()
|
||||||
xerrortest.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
assert.Equal(t, expected, result)
|
assert.Equal(t, expected, result)
|
||||||
os.Unsetenv(maximumWaitTimeoutEnvVar)
|
os.Unsetenv(maximumWaitTimeoutEnvVar)
|
||||||
}
|
}
|
||||||
@@ -61,7 +61,7 @@ func TestMaximumWaitDelayFromEnv(t *testing.T) {
|
|||||||
)
|
)
|
||||||
// MAXIMUM_WAIT_DELAY correctly set.
|
// MAXIMUM_WAIT_DELAY correctly set.
|
||||||
os.Setenv(maximumWaitDelayEnvVar, "10.0")
|
os.Setenv(maximumWaitDelayEnvVar, "10.0")
|
||||||
expected = defaultConfig()
|
expected = DefaultConfig()
|
||||||
expected.maximumWaitDelay = 10.0
|
expected.maximumWaitDelay = 10.0
|
||||||
result, err = FromEnv()
|
result, err = FromEnv()
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
@@ -69,16 +69,16 @@ func TestMaximumWaitDelayFromEnv(t *testing.T) {
|
|||||||
os.Unsetenv(maximumWaitDelayEnvVar)
|
os.Unsetenv(maximumWaitDelayEnvVar)
|
||||||
// MAXIMUM_WAIT_DELAY wrongly set.
|
// MAXIMUM_WAIT_DELAY wrongly set.
|
||||||
os.Setenv(maximumWaitDelayEnvVar, "foo")
|
os.Setenv(maximumWaitDelayEnvVar, "foo")
|
||||||
expected = defaultConfig()
|
expected = DefaultConfig()
|
||||||
result, err = FromEnv()
|
result, err = FromEnv()
|
||||||
xerrortest.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
assert.Equal(t, expected, result)
|
assert.Equal(t, expected, result)
|
||||||
os.Unsetenv(maximumWaitDelayEnvVar)
|
os.Unsetenv(maximumWaitDelayEnvVar)
|
||||||
// MAXIMUM_WAIT_DELAY < 0.
|
// MAXIMUM_WAIT_DELAY < 0.
|
||||||
os.Setenv(maximumWaitDelayEnvVar, "-1.0")
|
os.Setenv(maximumWaitDelayEnvVar, "-1.0")
|
||||||
expected = defaultConfig()
|
expected = DefaultConfig()
|
||||||
result, err = FromEnv()
|
result, err = FromEnv()
|
||||||
xerrortest.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
assert.Equal(t, expected, result)
|
assert.Equal(t, expected, result)
|
||||||
os.Unsetenv(maximumWaitDelayEnvVar)
|
os.Unsetenv(maximumWaitDelayEnvVar)
|
||||||
}
|
}
|
||||||
@@ -91,7 +91,7 @@ func TestMaximumWebhookURLTimeoutFromEnv(t *testing.T) {
|
|||||||
)
|
)
|
||||||
// MAXIMUM_WEBHOOK_URL_TIMEOUT correctly set.
|
// MAXIMUM_WEBHOOK_URL_TIMEOUT correctly set.
|
||||||
os.Setenv(maximumWebhookURLTimeoutEnvVar, "10.0")
|
os.Setenv(maximumWebhookURLTimeoutEnvVar, "10.0")
|
||||||
expected = defaultConfig()
|
expected = DefaultConfig()
|
||||||
expected.maximumWebhookURLTimeout = 10.0
|
expected.maximumWebhookURLTimeout = 10.0
|
||||||
result, err = FromEnv()
|
result, err = FromEnv()
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
@@ -99,16 +99,16 @@ func TestMaximumWebhookURLTimeoutFromEnv(t *testing.T) {
|
|||||||
os.Unsetenv(maximumWebhookURLTimeoutEnvVar)
|
os.Unsetenv(maximumWebhookURLTimeoutEnvVar)
|
||||||
// MAXIMUM_WEBHOOK_URL_TIMEOUT wrongly set.
|
// MAXIMUM_WEBHOOK_URL_TIMEOUT wrongly set.
|
||||||
os.Setenv(maximumWebhookURLTimeoutEnvVar, "foo")
|
os.Setenv(maximumWebhookURLTimeoutEnvVar, "foo")
|
||||||
expected = defaultConfig()
|
expected = DefaultConfig()
|
||||||
result, err = FromEnv()
|
result, err = FromEnv()
|
||||||
xerrortest.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
assert.Equal(t, expected, result)
|
assert.Equal(t, expected, result)
|
||||||
os.Unsetenv(maximumWebhookURLTimeoutEnvVar)
|
os.Unsetenv(maximumWebhookURLTimeoutEnvVar)
|
||||||
// MAXIMUM_WEBHOOK_URL_TIMEOUT < 0.
|
// MAXIMUM_WEBHOOK_URL_TIMEOUT < 0.
|
||||||
os.Setenv(maximumWebhookURLTimeoutEnvVar, "-1.0")
|
os.Setenv(maximumWebhookURLTimeoutEnvVar, "-1.0")
|
||||||
expected = defaultConfig()
|
expected = DefaultConfig()
|
||||||
result, err = FromEnv()
|
result, err = FromEnv()
|
||||||
xerrortest.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
assert.Equal(t, expected, result)
|
assert.Equal(t, expected, result)
|
||||||
os.Unsetenv(maximumWebhookURLTimeoutEnvVar)
|
os.Unsetenv(maximumWebhookURLTimeoutEnvVar)
|
||||||
}
|
}
|
||||||
@@ -121,7 +121,7 @@ func TestDefaultWaitTimeoutFromEnv(t *testing.T) {
|
|||||||
)
|
)
|
||||||
// DEFAULT_WAIT_TIMEOUT correctly set.
|
// DEFAULT_WAIT_TIMEOUT correctly set.
|
||||||
os.Setenv(defaultWaitTimeoutEnvVar, "10.0")
|
os.Setenv(defaultWaitTimeoutEnvVar, "10.0")
|
||||||
expected = defaultConfig()
|
expected = DefaultConfig()
|
||||||
expected.defaultWaitTimeout = 10.0
|
expected.defaultWaitTimeout = 10.0
|
||||||
result, err = FromEnv()
|
result, err = FromEnv()
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
@@ -129,23 +129,23 @@ func TestDefaultWaitTimeoutFromEnv(t *testing.T) {
|
|||||||
os.Unsetenv(defaultWaitTimeoutEnvVar)
|
os.Unsetenv(defaultWaitTimeoutEnvVar)
|
||||||
// DEFAULT_WAIT_TIMEOUT wrongly set.
|
// DEFAULT_WAIT_TIMEOUT wrongly set.
|
||||||
os.Setenv(defaultWaitTimeoutEnvVar, "foo")
|
os.Setenv(defaultWaitTimeoutEnvVar, "foo")
|
||||||
expected = defaultConfig()
|
expected = DefaultConfig()
|
||||||
result, err = FromEnv()
|
result, err = FromEnv()
|
||||||
xerrortest.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
assert.Equal(t, expected, result)
|
assert.Equal(t, expected, result)
|
||||||
os.Unsetenv(defaultWaitTimeoutEnvVar)
|
os.Unsetenv(defaultWaitTimeoutEnvVar)
|
||||||
// DEFAULT_WAIT_TIMEOUT < 0.
|
// DEFAULT_WAIT_TIMEOUT < 0.
|
||||||
os.Setenv(defaultWaitTimeoutEnvVar, "-1.0")
|
os.Setenv(defaultWaitTimeoutEnvVar, "-1.0")
|
||||||
expected = defaultConfig()
|
expected = DefaultConfig()
|
||||||
result, err = FromEnv()
|
result, err = FromEnv()
|
||||||
xerrortest.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
assert.Equal(t, expected, result)
|
assert.Equal(t, expected, result)
|
||||||
os.Unsetenv(defaultWaitTimeoutEnvVar)
|
os.Unsetenv(defaultWaitTimeoutEnvVar)
|
||||||
// DEFAULT_WAIT_TIMEOUT > MAXIMUM_WAIT_TIMEOUT.
|
// DEFAULT_WAIT_TIMEOUT > MAXIMUM_WAIT_TIMEOUT.
|
||||||
os.Setenv(defaultWaitTimeoutEnvVar, "40.0")
|
os.Setenv(defaultWaitTimeoutEnvVar, "40.0")
|
||||||
expected = defaultConfig()
|
expected = DefaultConfig()
|
||||||
result, err = FromEnv()
|
result, err = FromEnv()
|
||||||
xerrortest.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
assert.Equal(t, expected, result)
|
assert.Equal(t, expected, result)
|
||||||
os.Unsetenv(defaultWaitTimeoutEnvVar)
|
os.Unsetenv(defaultWaitTimeoutEnvVar)
|
||||||
}
|
}
|
||||||
@@ -158,7 +158,7 @@ func TestDefaultWebhookURLTimeoutFromEnv(t *testing.T) {
|
|||||||
)
|
)
|
||||||
// DEFAULT_WEBHOOK_URL_TIMEOUT correctly set.
|
// DEFAULT_WEBHOOK_URL_TIMEOUT correctly set.
|
||||||
os.Setenv(defaultWebhookURLTimeoutEnvVar, "10.0")
|
os.Setenv(defaultWebhookURLTimeoutEnvVar, "10.0")
|
||||||
expected = defaultConfig()
|
expected = DefaultConfig()
|
||||||
expected.defaultWebhookURLTimeout = 10.0
|
expected.defaultWebhookURLTimeout = 10.0
|
||||||
result, err = FromEnv()
|
result, err = FromEnv()
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
@@ -166,23 +166,23 @@ func TestDefaultWebhookURLTimeoutFromEnv(t *testing.T) {
|
|||||||
os.Unsetenv(defaultWebhookURLTimeoutEnvVar)
|
os.Unsetenv(defaultWebhookURLTimeoutEnvVar)
|
||||||
// DEFAULT_WEBHOOK_URL_TIMEOUT wrongly set.
|
// DEFAULT_WEBHOOK_URL_TIMEOUT wrongly set.
|
||||||
os.Setenv(defaultWebhookURLTimeoutEnvVar, "foo")
|
os.Setenv(defaultWebhookURLTimeoutEnvVar, "foo")
|
||||||
expected = defaultConfig()
|
expected = DefaultConfig()
|
||||||
result, err = FromEnv()
|
result, err = FromEnv()
|
||||||
xerrortest.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
assert.Equal(t, expected, result)
|
assert.Equal(t, expected, result)
|
||||||
os.Unsetenv(defaultWebhookURLTimeoutEnvVar)
|
os.Unsetenv(defaultWebhookURLTimeoutEnvVar)
|
||||||
// DEFAULT_WEBHOOK_URL_TIMEOUT < 0.
|
// DEFAULT_WEBHOOK_URL_TIMEOUT < 0.
|
||||||
os.Setenv(defaultWebhookURLTimeoutEnvVar, "-1.0")
|
os.Setenv(defaultWebhookURLTimeoutEnvVar, "-1.0")
|
||||||
expected = defaultConfig()
|
expected = DefaultConfig()
|
||||||
result, err = FromEnv()
|
result, err = FromEnv()
|
||||||
xerrortest.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
assert.Equal(t, expected, result)
|
assert.Equal(t, expected, result)
|
||||||
os.Unsetenv(defaultWebhookURLTimeoutEnvVar)
|
os.Unsetenv(defaultWebhookURLTimeoutEnvVar)
|
||||||
// DEFAULT_WEBHOOK_URL_TIMEOUT > MAXIMUM_WEBHOOK_URL_TIMEOUT.
|
// DEFAULT_WEBHOOK_URL_TIMEOUT > MAXIMUM_WEBHOOK_URL_TIMEOUT.
|
||||||
os.Setenv(defaultWebhookURLTimeoutEnvVar, "40.0")
|
os.Setenv(defaultWebhookURLTimeoutEnvVar, "40.0")
|
||||||
expected = defaultConfig()
|
expected = DefaultConfig()
|
||||||
result, err = FromEnv()
|
result, err = FromEnv()
|
||||||
xerrortest.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
assert.Equal(t, expected, result)
|
assert.Equal(t, expected, result)
|
||||||
os.Unsetenv(defaultWebhookURLTimeoutEnvVar)
|
os.Unsetenv(defaultWebhookURLTimeoutEnvVar)
|
||||||
}
|
}
|
||||||
@@ -195,7 +195,7 @@ func TestDefaultListenPortFromEnv(t *testing.T) {
|
|||||||
)
|
)
|
||||||
// DEFAULT_LISTEN_PORT correctly set.
|
// DEFAULT_LISTEN_PORT correctly set.
|
||||||
os.Setenv(defaultListenPortEnvVar, "80")
|
os.Setenv(defaultListenPortEnvVar, "80")
|
||||||
expected = defaultConfig()
|
expected = DefaultConfig()
|
||||||
expected.defaultListenPort = 80
|
expected.defaultListenPort = 80
|
||||||
result, err = FromEnv()
|
result, err = FromEnv()
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
@@ -203,23 +203,23 @@ func TestDefaultListenPortFromEnv(t *testing.T) {
|
|||||||
os.Unsetenv(defaultListenPortEnvVar)
|
os.Unsetenv(defaultListenPortEnvVar)
|
||||||
// DEFAULT_LISTEN_PORT wrongly set.
|
// DEFAULT_LISTEN_PORT wrongly set.
|
||||||
os.Setenv(defaultListenPortEnvVar, "foo")
|
os.Setenv(defaultListenPortEnvVar, "foo")
|
||||||
expected = defaultConfig()
|
expected = DefaultConfig()
|
||||||
result, err = FromEnv()
|
result, err = FromEnv()
|
||||||
xerrortest.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
assert.Equal(t, expected, result)
|
assert.Equal(t, expected, result)
|
||||||
os.Unsetenv(defaultListenPortEnvVar)
|
os.Unsetenv(defaultListenPortEnvVar)
|
||||||
// DEFAULT_LISTEN_PORT < 0.
|
// DEFAULT_LISTEN_PORT < 0.
|
||||||
os.Setenv(defaultListenPortEnvVar, "-1.0")
|
os.Setenv(defaultListenPortEnvVar, "-1.0")
|
||||||
expected = defaultConfig()
|
expected = DefaultConfig()
|
||||||
result, err = FromEnv()
|
result, err = FromEnv()
|
||||||
xerrortest.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
assert.Equal(t, expected, result)
|
assert.Equal(t, expected, result)
|
||||||
os.Unsetenv(defaultListenPortEnvVar)
|
os.Unsetenv(defaultListenPortEnvVar)
|
||||||
// DEFAULT_LISTEN_PORT > 65535.
|
// DEFAULT_LISTEN_PORT > 65535.
|
||||||
os.Setenv(defaultListenPortEnvVar, "65536")
|
os.Setenv(defaultListenPortEnvVar, "65536")
|
||||||
expected = defaultConfig()
|
expected = DefaultConfig()
|
||||||
result, err = FromEnv()
|
result, err = FromEnv()
|
||||||
xerrortest.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
assert.Equal(t, expected, result)
|
assert.Equal(t, expected, result)
|
||||||
os.Unsetenv(defaultListenPortEnvVar)
|
os.Unsetenv(defaultListenPortEnvVar)
|
||||||
}
|
}
|
||||||
@@ -232,14 +232,14 @@ func TestDisableGoogleChromeFromEnv(t *testing.T) {
|
|||||||
)
|
)
|
||||||
// DISABLE_GOOGLE_CHROME correctly set.
|
// DISABLE_GOOGLE_CHROME correctly set.
|
||||||
os.Setenv(disableGoogleChromeEnvVar, "1")
|
os.Setenv(disableGoogleChromeEnvVar, "1")
|
||||||
expected = defaultConfig()
|
expected = DefaultConfig()
|
||||||
expected.disableGoogleChrome = true
|
expected.disableGoogleChrome = true
|
||||||
result, err = FromEnv()
|
result, err = FromEnv()
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, expected, result)
|
assert.Equal(t, expected, result)
|
||||||
os.Unsetenv(disableGoogleChromeEnvVar)
|
os.Unsetenv(disableGoogleChromeEnvVar)
|
||||||
os.Setenv(disableGoogleChromeEnvVar, "0")
|
os.Setenv(disableGoogleChromeEnvVar, "0")
|
||||||
expected = defaultConfig()
|
expected = DefaultConfig()
|
||||||
expected.disableGoogleChrome = false
|
expected.disableGoogleChrome = false
|
||||||
result, err = FromEnv()
|
result, err = FromEnv()
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
@@ -247,9 +247,9 @@ func TestDisableGoogleChromeFromEnv(t *testing.T) {
|
|||||||
os.Unsetenv(disableGoogleChromeEnvVar)
|
os.Unsetenv(disableGoogleChromeEnvVar)
|
||||||
// DISABLE_GOOGLE_CHROME wrongly set.
|
// DISABLE_GOOGLE_CHROME wrongly set.
|
||||||
os.Setenv(disableGoogleChromeEnvVar, "foo")
|
os.Setenv(disableGoogleChromeEnvVar, "foo")
|
||||||
expected = defaultConfig()
|
expected = DefaultConfig()
|
||||||
result, err = FromEnv()
|
result, err = FromEnv()
|
||||||
xerrortest.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
assert.Equal(t, expected, result)
|
assert.Equal(t, expected, result)
|
||||||
os.Unsetenv(disableGoogleChromeEnvVar)
|
os.Unsetenv(disableGoogleChromeEnvVar)
|
||||||
}
|
}
|
||||||
@@ -262,14 +262,14 @@ func TestDisableUnoconvFromEnv(t *testing.T) {
|
|||||||
)
|
)
|
||||||
// DISABLE_UNOCONV correctly set.
|
// DISABLE_UNOCONV correctly set.
|
||||||
os.Setenv(disableUnoconvEnvVar, "1")
|
os.Setenv(disableUnoconvEnvVar, "1")
|
||||||
expected = defaultConfig()
|
expected = DefaultConfig()
|
||||||
expected.disableUnoconv = true
|
expected.disableUnoconv = true
|
||||||
result, err = FromEnv()
|
result, err = FromEnv()
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, expected, result)
|
assert.Equal(t, expected, result)
|
||||||
os.Unsetenv(disableUnoconvEnvVar)
|
os.Unsetenv(disableUnoconvEnvVar)
|
||||||
os.Setenv(disableUnoconvEnvVar, "0")
|
os.Setenv(disableUnoconvEnvVar, "0")
|
||||||
expected = defaultConfig()
|
expected = DefaultConfig()
|
||||||
expected.disableUnoconv = false
|
expected.disableUnoconv = false
|
||||||
result, err = FromEnv()
|
result, err = FromEnv()
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
@@ -277,9 +277,9 @@ func TestDisableUnoconvFromEnv(t *testing.T) {
|
|||||||
os.Unsetenv(disableUnoconvEnvVar)
|
os.Unsetenv(disableUnoconvEnvVar)
|
||||||
// DISABLE_UNOCONV wrongly set.
|
// DISABLE_UNOCONV wrongly set.
|
||||||
os.Setenv(disableUnoconvEnvVar, "foo")
|
os.Setenv(disableUnoconvEnvVar, "foo")
|
||||||
expected = defaultConfig()
|
expected = DefaultConfig()
|
||||||
result, err = FromEnv()
|
result, err = FromEnv()
|
||||||
xerrortest.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
assert.Equal(t, expected, result)
|
assert.Equal(t, expected, result)
|
||||||
os.Unsetenv(disableUnoconvEnvVar)
|
os.Unsetenv(disableUnoconvEnvVar)
|
||||||
}
|
}
|
||||||
@@ -292,20 +292,20 @@ func TestLogLevelFromEnv(t *testing.T) {
|
|||||||
)
|
)
|
||||||
// LOG_LEVEL correctly set.
|
// LOG_LEVEL correctly set.
|
||||||
os.Setenv(logLevelEnvVar, "DEBUG")
|
os.Setenv(logLevelEnvVar, "DEBUG")
|
||||||
expected = defaultConfig()
|
expected = DefaultConfig()
|
||||||
expected.logLevel = xlog.DebugLevel
|
expected.logLevel = xlog.DebugLevel
|
||||||
result, err = FromEnv()
|
result, err = FromEnv()
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, expected, result)
|
assert.Equal(t, expected, result)
|
||||||
os.Unsetenv(logLevelEnvVar)
|
os.Unsetenv(logLevelEnvVar)
|
||||||
os.Setenv(logLevelEnvVar, "INFO")
|
os.Setenv(logLevelEnvVar, "INFO")
|
||||||
expected = defaultConfig()
|
expected = DefaultConfig()
|
||||||
result, err = FromEnv()
|
result, err = FromEnv()
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, expected, result)
|
assert.Equal(t, expected, result)
|
||||||
os.Unsetenv(logLevelEnvVar)
|
os.Unsetenv(logLevelEnvVar)
|
||||||
os.Setenv(logLevelEnvVar, "ERROR")
|
os.Setenv(logLevelEnvVar, "ERROR")
|
||||||
expected = defaultConfig()
|
expected = DefaultConfig()
|
||||||
expected.logLevel = xlog.ErrorLevel
|
expected.logLevel = xlog.ErrorLevel
|
||||||
result, err = FromEnv()
|
result, err = FromEnv()
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
@@ -313,15 +313,15 @@ func TestLogLevelFromEnv(t *testing.T) {
|
|||||||
os.Unsetenv(logLevelEnvVar)
|
os.Unsetenv(logLevelEnvVar)
|
||||||
// LOG_LEVEL wrongly set.
|
// LOG_LEVEL wrongly set.
|
||||||
os.Setenv(logLevelEnvVar, "foo")
|
os.Setenv(logLevelEnvVar, "foo")
|
||||||
expected = defaultConfig()
|
expected = DefaultConfig()
|
||||||
result, err = FromEnv()
|
result, err = FromEnv()
|
||||||
xerrortest.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
assert.Equal(t, expected, result)
|
assert.Equal(t, expected, result)
|
||||||
os.Unsetenv(logLevelEnvVar)
|
os.Unsetenv(logLevelEnvVar)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetters(t *testing.T) {
|
func TestGetters(t *testing.T) {
|
||||||
result := defaultConfig()
|
result := DefaultConfig()
|
||||||
assert.Equal(t, result.maximumWaitTimeout, result.MaximumWaitTimeout())
|
assert.Equal(t, result.maximumWaitTimeout, result.MaximumWaitTimeout())
|
||||||
assert.Equal(t, result.maximumWaitDelay, result.MaximumWaitDelay())
|
assert.Equal(t, result.maximumWaitDelay, result.MaximumWaitDelay())
|
||||||
assert.Equal(t, result.maximumWebhookURLTimeout, result.MaximumWebhookURLTimeout())
|
assert.Equal(t, result.maximumWebhookURLTimeout, result.MaximumWebhookURLTimeout())
|
||||||
|
|||||||
@@ -7,15 +7,13 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/thecodingmachine/gotenberg/internal/pkg/xerror"
|
"github.com/thecodingmachine/gotenberg/internal/pkg/xerror"
|
||||||
"github.com/thecodingmachine/gotenberg/internal/pkg/xlog"
|
"github.com/thecodingmachine/gotenberg/internal/pkg/xlog"
|
||||||
"github.com/thecodingmachine/gotenberg/test/internalpkg/printertest"
|
"github.com/thecodingmachine/gotenberg/test"
|
||||||
"github.com/thecodingmachine/gotenberg/test/internalpkg/xerrortest"
|
|
||||||
"github.com/thecodingmachine/gotenberg/test/internalpkg/xlogtest"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMergePrinter(t *testing.T) {
|
func TestMergePrinter(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
logger xlog.Logger = xlogtest.DebugLogger()
|
logger xlog.Logger = test.DebugLogger()
|
||||||
fpaths []string = printertest.MergeFpaths(t)
|
fpaths []string = test.MergeFpaths(t)
|
||||||
opts MergePrinterOptions
|
opts MergePrinterOptions
|
||||||
dest string
|
dest string
|
||||||
p Printer
|
p Printer
|
||||||
@@ -26,7 +24,7 @@ func TestMergePrinter(t *testing.T) {
|
|||||||
WaitTimeout: 10.0,
|
WaitTimeout: 10.0,
|
||||||
}
|
}
|
||||||
p = NewMergePrinter(logger, fpaths, opts)
|
p = NewMergePrinter(logger, fpaths, opts)
|
||||||
dest = printertest.GenerateDestination()
|
dest = test.GenerateDestination()
|
||||||
err = p.Print(dest)
|
err = p.Print(dest)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
err = os.RemoveAll(dest)
|
err = os.RemoveAll(dest)
|
||||||
@@ -37,9 +35,9 @@ func TestMergePrinter(t *testing.T) {
|
|||||||
WaitTimeout: 0.0,
|
WaitTimeout: 0.0,
|
||||||
}
|
}
|
||||||
p = NewMergePrinter(logger, fpaths, opts)
|
p = NewMergePrinter(logger, fpaths, opts)
|
||||||
dest = printertest.GenerateDestination()
|
dest = test.GenerateDestination()
|
||||||
err = p.Print(dest)
|
err = p.Print(dest)
|
||||||
xerrortest.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
assert.Equal(t, xerror.TimeoutCode, xerror.Code(err))
|
assert.Equal(t, xerror.TimeoutCode, xerror.Code(err))
|
||||||
err = os.RemoveAll(dest)
|
err = os.RemoveAll(dest)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|||||||
@@ -7,15 +7,13 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/thecodingmachine/gotenberg/internal/pkg/xerror"
|
"github.com/thecodingmachine/gotenberg/internal/pkg/xerror"
|
||||||
"github.com/thecodingmachine/gotenberg/internal/pkg/xlog"
|
"github.com/thecodingmachine/gotenberg/internal/pkg/xlog"
|
||||||
"github.com/thecodingmachine/gotenberg/test/internalpkg/printertest"
|
"github.com/thecodingmachine/gotenberg/test"
|
||||||
"github.com/thecodingmachine/gotenberg/test/internalpkg/xerrortest"
|
|
||||||
"github.com/thecodingmachine/gotenberg/test/internalpkg/xlogtest"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestOfficePrinter(t *testing.T) {
|
func TestOfficePrinter(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
logger xlog.Logger = xlogtest.DebugLogger()
|
logger xlog.Logger = test.DebugLogger()
|
||||||
fpaths []string = printertest.OfficeFpaths(t)
|
fpaths []string = test.OfficeFpaths(t)
|
||||||
opts OfficePrinterOptions
|
opts OfficePrinterOptions
|
||||||
dest string
|
dest string
|
||||||
p Printer
|
p Printer
|
||||||
@@ -27,7 +25,7 @@ func TestOfficePrinter(t *testing.T) {
|
|||||||
Landscape: false,
|
Landscape: false,
|
||||||
}
|
}
|
||||||
p = NewOfficePrinter(logger, fpaths, opts)
|
p = NewOfficePrinter(logger, fpaths, opts)
|
||||||
dest = printertest.GenerateDestination()
|
dest = test.GenerateDestination()
|
||||||
err = p.Print(dest)
|
err = p.Print(dest)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
err = os.RemoveAll(dest)
|
err = os.RemoveAll(dest)
|
||||||
@@ -38,7 +36,7 @@ func TestOfficePrinter(t *testing.T) {
|
|||||||
Landscape: false,
|
Landscape: false,
|
||||||
}
|
}
|
||||||
p = NewOfficePrinter(logger, []string{fpaths[0]}, opts)
|
p = NewOfficePrinter(logger, []string{fpaths[0]}, opts)
|
||||||
dest = printertest.GenerateDestination()
|
dest = test.GenerateDestination()
|
||||||
err = p.Print(dest)
|
err = p.Print(dest)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
err = os.RemoveAll(dest)
|
err = os.RemoveAll(dest)
|
||||||
@@ -49,7 +47,7 @@ func TestOfficePrinter(t *testing.T) {
|
|||||||
Landscape: true,
|
Landscape: true,
|
||||||
}
|
}
|
||||||
p = NewOfficePrinter(logger, fpaths, opts)
|
p = NewOfficePrinter(logger, fpaths, opts)
|
||||||
dest = printertest.GenerateDestination()
|
dest = test.GenerateDestination()
|
||||||
err = p.Print(dest)
|
err = p.Print(dest)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
err = os.RemoveAll(dest)
|
err = os.RemoveAll(dest)
|
||||||
@@ -61,9 +59,9 @@ func TestOfficePrinter(t *testing.T) {
|
|||||||
Landscape: true,
|
Landscape: true,
|
||||||
}
|
}
|
||||||
p = NewOfficePrinter(logger, fpaths, opts)
|
p = NewOfficePrinter(logger, fpaths, opts)
|
||||||
dest = printertest.GenerateDestination()
|
dest = test.GenerateDestination()
|
||||||
err = p.Print(dest)
|
err = p.Print(dest)
|
||||||
xerrortest.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
assert.Equal(t, xerror.TimeoutCode, xerror.Code(err))
|
assert.Equal(t, xerror.TimeoutCode, xerror.Code(err))
|
||||||
err = os.RemoveAll(dest)
|
err = os.RemoveAll(dest)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/thecodingmachine/gotenberg/test/internalpkg/xerrortest"
|
"github.com/thecodingmachine/gotenberg/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFloat64NotInferiorTo(t *testing.T) {
|
func TestFloat64NotInferiorTo(t *testing.T) {
|
||||||
@@ -16,7 +16,7 @@ func TestFloat64NotInferiorTo(t *testing.T) {
|
|||||||
// should not be OK.
|
// should not be OK.
|
||||||
rule.with("FOO", -10.0)
|
rule.with("FOO", -10.0)
|
||||||
err = rule.validate()
|
err = rule.validate()
|
||||||
xerrortest.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFloat64NotSuperiorTo(t *testing.T) {
|
func TestFloat64NotSuperiorTo(t *testing.T) {
|
||||||
@@ -28,5 +28,5 @@ func TestFloat64NotSuperiorTo(t *testing.T) {
|
|||||||
// should not be OK.
|
// should not be OK.
|
||||||
rule.with("FOO", 10.0)
|
rule.with("FOO", 10.0)
|
||||||
err = rule.validate()
|
err = rule.validate()
|
||||||
xerrortest.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/thecodingmachine/gotenberg/test/internalpkg/xerrortest"
|
"github.com/thecodingmachine/gotenberg/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestInt64NotInferiorTo(t *testing.T) {
|
func TestInt64NotInferiorTo(t *testing.T) {
|
||||||
@@ -16,7 +16,7 @@ func TestInt64NotInferiorTo(t *testing.T) {
|
|||||||
// should not be OK.
|
// should not be OK.
|
||||||
rule.with("FOO", -10)
|
rule.with("FOO", -10)
|
||||||
err = rule.validate()
|
err = rule.validate()
|
||||||
xerrortest.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInt64NotSuperiorTo(t *testing.T) {
|
func TestInt64NotSuperiorTo(t *testing.T) {
|
||||||
@@ -28,5 +28,5 @@ func TestInt64NotSuperiorTo(t *testing.T) {
|
|||||||
// should not be OK.
|
// should not be OK.
|
||||||
rule.with("FOO", 10)
|
rule.with("FOO", 10)
|
||||||
err = rule.validate()
|
err = rule.validate()
|
||||||
xerrortest.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/thecodingmachine/gotenberg/test/internalpkg/xerrortest"
|
"github.com/thecodingmachine/gotenberg/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestStringOfOne(t *testing.T) {
|
func TestStringOfOne(t *testing.T) {
|
||||||
@@ -16,5 +16,5 @@ func TestStringOfOne(t *testing.T) {
|
|||||||
// should not be OK.
|
// should not be OK.
|
||||||
rule.with("FOO", "qux")
|
rule.with("FOO", "qux")
|
||||||
err = rule.validate()
|
err = rule.validate()
|
||||||
xerrortest.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/thecodingmachine/gotenberg/test/internalpkg/xerrortest"
|
"github.com/thecodingmachine/gotenberg/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestString(t *testing.T) {
|
func TestString(t *testing.T) {
|
||||||
@@ -31,7 +31,7 @@ func TestString(t *testing.T) {
|
|||||||
v, err = String("foo", "BAZ", defaultValue, rule)
|
v, err = String("foo", "BAZ", defaultValue, rule)
|
||||||
expected = defaultValue
|
expected = defaultValue
|
||||||
assert.Equal(t, expected, v)
|
assert.Equal(t, expected, v)
|
||||||
xerrortest.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStringFromEnv(t *testing.T) {
|
func TestStringFromEnv(t *testing.T) {
|
||||||
@@ -61,7 +61,7 @@ func TestStringFromEnv(t *testing.T) {
|
|||||||
v, err = StringFromEnv(envVar, defaultValue, rule)
|
v, err = StringFromEnv(envVar, defaultValue, rule)
|
||||||
expected = defaultValue
|
expected = defaultValue
|
||||||
assert.Equal(t, expected, v)
|
assert.Equal(t, expected, v)
|
||||||
xerrortest.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
os.Unsetenv(envVar)
|
os.Unsetenv(envVar)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,13 +88,13 @@ func TestInt64(t *testing.T) {
|
|||||||
v, err = Int64("foo", "foo", defaultValue)
|
v, err = Int64("foo", "foo", defaultValue)
|
||||||
expected = defaultValue
|
expected = defaultValue
|
||||||
assert.Equal(t, expected, v)
|
assert.Equal(t, expected, v)
|
||||||
xerrortest.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
// should not be OK as given value does not
|
// should not be OK as given value does not
|
||||||
// validate the rule x >= 6.
|
// validate the rule x >= 6.
|
||||||
v, err = Int64("foo", "5", defaultValue, rule)
|
v, err = Int64("foo", "5", defaultValue, rule)
|
||||||
expected = defaultValue
|
expected = defaultValue
|
||||||
assert.Equal(t, expected, v)
|
assert.Equal(t, expected, v)
|
||||||
xerrortest.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInt64FromEnv(t *testing.T) {
|
func TestInt64FromEnv(t *testing.T) {
|
||||||
@@ -124,7 +124,7 @@ func TestInt64FromEnv(t *testing.T) {
|
|||||||
v, err = Int64FromEnv(envVar, defaultValue)
|
v, err = Int64FromEnv(envVar, defaultValue)
|
||||||
expected = defaultValue
|
expected = defaultValue
|
||||||
assert.Equal(t, expected, v)
|
assert.Equal(t, expected, v)
|
||||||
xerrortest.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
os.Unsetenv(envVar)
|
os.Unsetenv(envVar)
|
||||||
// should not be OK as environment variable
|
// should not be OK as environment variable
|
||||||
// value does not validate the rule x >= 6.
|
// value does not validate the rule x >= 6.
|
||||||
@@ -132,7 +132,7 @@ func TestInt64FromEnv(t *testing.T) {
|
|||||||
v, err = Int64FromEnv(envVar, defaultValue, rule)
|
v, err = Int64FromEnv(envVar, defaultValue, rule)
|
||||||
expected = defaultValue
|
expected = defaultValue
|
||||||
assert.Equal(t, expected, v)
|
assert.Equal(t, expected, v)
|
||||||
xerrortest.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
os.Unsetenv(envVar)
|
os.Unsetenv(envVar)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,13 +157,13 @@ func TestFloat64(t *testing.T) {
|
|||||||
v, err = Float64("foo", "foo", defaultValue)
|
v, err = Float64("foo", "foo", defaultValue)
|
||||||
expected = defaultValue
|
expected = defaultValue
|
||||||
assert.Equal(t, expected, v)
|
assert.Equal(t, expected, v)
|
||||||
xerrortest.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
// should not be OK as given value does not
|
// should not be OK as given value does not
|
||||||
// validate the rule x >= 6.
|
// validate the rule x >= 6.
|
||||||
v, err = Float64("foo", "5", defaultValue, rule)
|
v, err = Float64("foo", "5", defaultValue, rule)
|
||||||
expected = defaultValue
|
expected = defaultValue
|
||||||
assert.Equal(t, expected, v)
|
assert.Equal(t, expected, v)
|
||||||
xerrortest.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFloat64FromEnv(t *testing.T) {
|
func TestFloat64FromEnv(t *testing.T) {
|
||||||
@@ -193,7 +193,7 @@ func TestFloat64FromEnv(t *testing.T) {
|
|||||||
v, err = Float64FromEnv(envVar, defaultValue)
|
v, err = Float64FromEnv(envVar, defaultValue)
|
||||||
expected = defaultValue
|
expected = defaultValue
|
||||||
assert.Equal(t, expected, v)
|
assert.Equal(t, expected, v)
|
||||||
xerrortest.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
os.Unsetenv(envVar)
|
os.Unsetenv(envVar)
|
||||||
// should not be OK as environment variable
|
// should not be OK as environment variable
|
||||||
// value does not validate the rule x >= 6.
|
// value does not validate the rule x >= 6.
|
||||||
@@ -201,7 +201,7 @@ func TestFloat64FromEnv(t *testing.T) {
|
|||||||
v, err = Float64FromEnv(envVar, defaultValue, rule)
|
v, err = Float64FromEnv(envVar, defaultValue, rule)
|
||||||
expected = defaultValue
|
expected = defaultValue
|
||||||
assert.Equal(t, expected, v)
|
assert.Equal(t, expected, v)
|
||||||
xerrortest.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
os.Unsetenv(envVar)
|
os.Unsetenv(envVar)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,7 +237,7 @@ func TestBool(t *testing.T) {
|
|||||||
v, err = Bool("foo", "foo", defaultValue)
|
v, err = Bool("foo", "foo", defaultValue)
|
||||||
expected = defaultValue
|
expected = defaultValue
|
||||||
assert.Equal(t, expected, v)
|
assert.Equal(t, expected, v)
|
||||||
xerrortest.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBoolFromEnv(t *testing.T) {
|
func TestBoolFromEnv(t *testing.T) {
|
||||||
@@ -284,6 +284,6 @@ func TestBoolFromEnv(t *testing.T) {
|
|||||||
v, err = BoolFromEnv(envVar, defaultValue)
|
v, err = BoolFromEnv(envVar, defaultValue)
|
||||||
expected = defaultValue
|
expected = defaultValue
|
||||||
assert.Equal(t, expected, v)
|
assert.Equal(t, expected, v)
|
||||||
xerrortest.AssertError(t, err)
|
test.AssertError(t, err)
|
||||||
os.Unsetenv(envVar)
|
os.Unsetenv(envVar)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,13 +8,12 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/thecodingmachine/gotenberg/internal/pkg/xerror"
|
"github.com/thecodingmachine/gotenberg/internal/pkg/xerror"
|
||||||
"github.com/thecodingmachine/gotenberg/internal/pkg/xtime"
|
"github.com/thecodingmachine/gotenberg/internal/pkg/xtime"
|
||||||
"github.com/thecodingmachine/gotenberg/test/internalpkg/xerrortest"
|
"github.com/thecodingmachine/gotenberg/test"
|
||||||
"github.com/thecodingmachine/gotenberg/test/internalpkg/xlogtest"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMustHandleError(t *testing.T) {
|
func TestMustHandleError(t *testing.T) {
|
||||||
previousErr := errors.New("previous error")
|
previousErr := errors.New("previous error")
|
||||||
logger := xlogtest.DebugLogger()
|
logger := test.DebugLogger()
|
||||||
// context should not have an error.
|
// context should not have an error.
|
||||||
ctx, cancel := WithTimeout(logger, 5)
|
ctx, cancel := WithTimeout(logger, 5)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
@@ -31,13 +30,13 @@ func TestMustHandleError(t *testing.T) {
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
time.Sleep(xtime.Duration(1))
|
time.Sleep(xtime.Duration(1))
|
||||||
err = MustHandleError(ctx, previousErr)
|
err = MustHandleError(ctx, previousErr)
|
||||||
xerr := xerrortest.AssertError(t, err)
|
xerr := test.AssertError(t, err)
|
||||||
assert.Equal(t, xerror.TimeoutCode, xerror.Code(xerr))
|
assert.Equal(t, xerror.TimeoutCode, xerror.Code(xerr))
|
||||||
// context should have an error different
|
// context should have an error different
|
||||||
// than context.DeadlineExceeded.
|
// than context.DeadlineExceeded.
|
||||||
ctx, cancel = WithTimeout(logger, 5)
|
ctx, cancel = WithTimeout(logger, 5)
|
||||||
cancel()
|
cancel()
|
||||||
err = MustHandleError(ctx, previousErr)
|
err = MustHandleError(ctx, previousErr)
|
||||||
xerr = xerrortest.AssertError(t, err)
|
xerr = test.AssertError(t, err)
|
||||||
assert.Equal(t, xerror.InternalCode, xerror.Code(xerr))
|
assert.Equal(t, xerror.InternalCode, xerror.Code(xerr))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/thecodingmachine/gotenberg/test/internalpkg/xlogtest"
|
"github.com/thecodingmachine/gotenberg/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCommand(t *testing.T) {
|
func TestCommand(t *testing.T) {
|
||||||
logger := xlogtest.DebugLogger()
|
logger := test.DebugLogger()
|
||||||
// should pipe command output as
|
// should pipe command output as
|
||||||
// xlog.Logger has a xlog.DebugLevel.
|
// xlog.Logger has a xlog.DebugLevel.
|
||||||
cmd, err := Command(logger, "echo", "Hello", "World")
|
cmd, err := Command(logger, "echo", "Hello", "World")
|
||||||
@@ -17,14 +17,14 @@ func TestCommand(t *testing.T) {
|
|||||||
LogBeforeExecute(logger, cmd)
|
LogBeforeExecute(logger, cmd)
|
||||||
// should not pipe command output as
|
// should not pipe command output as
|
||||||
// xlog.Logger has a xlog.InfoLevel.
|
// xlog.Logger has a xlog.InfoLevel.
|
||||||
logger = xlogtest.InfoLogger()
|
logger = test.InfoLogger()
|
||||||
cmd, err = Command(logger, "echo", "Hello", "World")
|
cmd, err = Command(logger, "echo", "Hello", "World")
|
||||||
LogBeforeExecute(logger, cmd)
|
LogBeforeExecute(logger, cmd)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCommandContext(t *testing.T) {
|
func TestCommandContext(t *testing.T) {
|
||||||
logger := xlogtest.DebugLogger()
|
logger := test.DebugLogger()
|
||||||
// should pipe command output as
|
// should pipe command output as
|
||||||
// xlog.Logger has a xlog.DebugLevel.
|
// xlog.Logger has a xlog.DebugLevel.
|
||||||
cmd, err := CommandContext(context.Background(), logger, "echo", "Hello", "World")
|
cmd, err := CommandContext(context.Background(), logger, "echo", "Hello", "World")
|
||||||
@@ -32,7 +32,7 @@ func TestCommandContext(t *testing.T) {
|
|||||||
LogBeforeExecute(logger, cmd)
|
LogBeforeExecute(logger, cmd)
|
||||||
// should not pipe command output as
|
// should not pipe command output as
|
||||||
// xlog.Logger has a xlog.InfoLevel.
|
// xlog.Logger has a xlog.InfoLevel.
|
||||||
logger = xlogtest.InfoLogger()
|
logger = test.InfoLogger()
|
||||||
cmd, err = CommandContext(context.Background(), logger, "echo", "Hello", "World")
|
cmd, err = CommandContext(context.Background(), logger, "echo", "Hello", "World")
|
||||||
LogBeforeExecute(logger, cmd)
|
LogBeforeExecute(logger, cmd)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/thecodingmachine/gotenberg/internal/pkg/pm2"
|
"github.com/thecodingmachine/gotenberg/internal/pkg/pm2"
|
||||||
"github.com/thecodingmachine/gotenberg/test/internalpkg/xlogtest"
|
"github.com/thecodingmachine/gotenberg/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
logger := xlogtest.DebugLogger()
|
logger := test.DebugLogger()
|
||||||
process := pm2.NewChromeProcess(logger)
|
process := pm2.NewChromeProcess(logger)
|
||||||
if err := process.Start(); err != nil {
|
if err := process.Start(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|||||||
29
test/context.go
Normal file
29
test/context.go
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
|
)
|
||||||
|
|
||||||
|
// DummyEchoContext creates a
|
||||||
|
// echo.Context without anything.
|
||||||
|
func DummyEchoContext() echo.Context {
|
||||||
|
e := echo.New()
|
||||||
|
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
||||||
|
rec := httptest.NewRecorder()
|
||||||
|
return e.NewContext(req, rec)
|
||||||
|
}
|
||||||
|
|
||||||
|
// EchoContextMultipart creates a
|
||||||
|
// echo.Context with form files.
|
||||||
|
func EchoContextMultipart(t *testing.T) echo.Context {
|
||||||
|
e := echo.New()
|
||||||
|
body, contentType := MergeMultipartForm(t, nil)
|
||||||
|
req := httptest.NewRequest(http.MethodPost, "/", body)
|
||||||
|
req.Header.Set(echo.HeaderContentType, contentType)
|
||||||
|
rec := httptest.NewRecorder()
|
||||||
|
return e.NewContext(req, rec)
|
||||||
|
}
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
/*
|
|
||||||
Package printertest contains useful
|
|
||||||
functions for tests related
|
|
||||||
to printer package.
|
|
||||||
*/
|
|
||||||
package printertest
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
/*
|
|
||||||
Package xerrortest contains useful
|
|
||||||
functions for tests related
|
|
||||||
to xerror package.
|
|
||||||
*/
|
|
||||||
package xerrortest
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
/*
|
|
||||||
Package xlogtest contains useful
|
|
||||||
functions for tests related
|
|
||||||
to xlog package.
|
|
||||||
*/
|
|
||||||
package xlogtest
|
|
||||||
80
test/multipartform.go
Normal file
80
test/multipartform.go
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"io"
|
||||||
|
"mime/multipart"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MergeMultipartForm returns the body
|
||||||
|
// for a multipart/form-data request with all
|
||||||
|
// files under "pdf" folder.
|
||||||
|
func MergeMultipartForm(t *testing.T, formValues map[string]string) (*bytes.Buffer, string) {
|
||||||
|
fpaths := MergeFpaths(t)
|
||||||
|
return multipartForm(t, "pdf", formValues, fpaths)
|
||||||
|
}
|
||||||
|
|
||||||
|
// HTMLMultipartForm returns the body
|
||||||
|
// for a multipart/form-data request with all
|
||||||
|
// files under "html" folder.
|
||||||
|
func HTMLMultipartForm(t *testing.T, formValues map[string]string) (*bytes.Buffer, string) {
|
||||||
|
// TODO
|
||||||
|
return multipartForm(t, "html", formValues, []string{})
|
||||||
|
}
|
||||||
|
|
||||||
|
// URLMultipartForm returns the body
|
||||||
|
// for a multipart/form-data request with all
|
||||||
|
// files under "url" folder.
|
||||||
|
func URLMultipartForm(t *testing.T, formValues map[string]string) (*bytes.Buffer, string) {
|
||||||
|
// TODO
|
||||||
|
return multipartForm(t, "url", formValues, []string{})
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarkdownMultipartForm returns the body
|
||||||
|
// for a multipart/form-data request with all
|
||||||
|
// files under "markdown" folder.
|
||||||
|
func MarkdownMultipartForm(t *testing.T, formValues map[string]string) (*bytes.Buffer, string) {
|
||||||
|
// TODO
|
||||||
|
return multipartForm(t, "markdown", formValues, []string{})
|
||||||
|
}
|
||||||
|
|
||||||
|
// OfficeMultipartForm returns the body
|
||||||
|
// for a multipart/form-data request with all
|
||||||
|
// files under "office" folder.
|
||||||
|
func OfficeMultipartForm(t *testing.T, formValues map[string]string) (*bytes.Buffer, string) {
|
||||||
|
fpaths := OfficeFpaths(t)
|
||||||
|
return multipartForm(t, "office", formValues, fpaths)
|
||||||
|
}
|
||||||
|
|
||||||
|
func multipartForm(
|
||||||
|
t *testing.T,
|
||||||
|
kind string,
|
||||||
|
formValues map[string]string,
|
||||||
|
formFilePaths []string,
|
||||||
|
) (*bytes.Buffer, string) {
|
||||||
|
body := &bytes.Buffer{}
|
||||||
|
writer := multipart.NewWriter(body)
|
||||||
|
defer writer.Close()
|
||||||
|
for _, fpath := range formFilePaths {
|
||||||
|
file, err := os.Open(fpath)
|
||||||
|
require.Nil(t, err)
|
||||||
|
part, err := writer.CreateFormFile("foo", filepath.Base(fpath))
|
||||||
|
require.Nil(t, err)
|
||||||
|
_, err = io.Copy(part, file)
|
||||||
|
require.Nil(t, err)
|
||||||
|
}
|
||||||
|
if kind == "url" {
|
||||||
|
err := writer.WriteField("remoteURL", "http://google.com")
|
||||||
|
require.Nil(t, err)
|
||||||
|
}
|
||||||
|
for k, v := range formValues {
|
||||||
|
err := writer.WriteField(k, v)
|
||||||
|
require.Nil(t, err)
|
||||||
|
}
|
||||||
|
return body, writer.FormDataContentType()
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package printertest
|
package test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -1,21 +1,13 @@
|
|||||||
package test
|
package test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"mime/multipart"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
|
||||||
"path/filepath"
|
|
||||||
"runtime"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
"github.com/thecodingmachine/gotenberg/internal/pkg/xerror"
|
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -51,94 +43,3 @@ func AssertConcurrent(t *testing.T, fn func() error, amount int) {
|
|||||||
err := eg.Wait()
|
err := eg.Wait()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AssertStandardError validates that given error
|
|
||||||
// is of an instance of xerror.Error.
|
|
||||||
// If so, returns the instance of xerror.Error.
|
|
||||||
func AssertStandardError(t *testing.T, err error) *xerror.Error {
|
|
||||||
assert.NotNil(t, err)
|
|
||||||
standardized, ok := err.(*xerror.Error)
|
|
||||||
assert.Equal(t, true, ok)
|
|
||||||
return standardized
|
|
||||||
}
|
|
||||||
|
|
||||||
// HTMLTestMultipartForm returns the body
|
|
||||||
// for a multipate/form-data request with all
|
|
||||||
// files under "html" folder.
|
|
||||||
func HTMLTestMultipartForm(t *testing.T, formValues map[string]string) (*bytes.Buffer, string) {
|
|
||||||
return multipartForm(t, "html", formValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
// URLTestMultipartForm returns the body
|
|
||||||
// for a multipate/form-data request with all
|
|
||||||
// files under "url" folder.
|
|
||||||
func URLTestMultipartForm(t *testing.T, formValues map[string]string) (*bytes.Buffer, string) {
|
|
||||||
return multipartForm(t, "url", formValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarkdownTestMultipartForm returns the body
|
|
||||||
// for a multipate/form-data request with all
|
|
||||||
// files under "markdown" folder.
|
|
||||||
func MarkdownTestMultipartForm(t *testing.T, formValues map[string]string) (*bytes.Buffer, string) {
|
|
||||||
return multipartForm(t, "markdown", formValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
// OfficeTestMultipartForm returns the body
|
|
||||||
// for a multipate/form-data request with all
|
|
||||||
// files under "office" folder.
|
|
||||||
func OfficeTestMultipartForm(t *testing.T, formValues map[string]string) (*bytes.Buffer, string) {
|
|
||||||
return multipartForm(t, "office", formValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
// PDFTestMultipartForm returns the body
|
|
||||||
// for a multipate/form-data request with all
|
|
||||||
// files under "pdf" folder.
|
|
||||||
func PDFTestMultipartForm(t *testing.T, formValues map[string]string) (*bytes.Buffer, string) {
|
|
||||||
return multipartForm(t, "pdf", formValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
func multipartForm(t *testing.T, kind string, formValues map[string]string) (*bytes.Buffer, string) {
|
|
||||||
body := &bytes.Buffer{}
|
|
||||||
writer := multipart.NewWriter(body)
|
|
||||||
defer writer.Close()
|
|
||||||
dirPath := abs(t, kind, "")
|
|
||||||
fpaths := make(map[string]string)
|
|
||||||
err := filepath.Walk(dirPath, func(path string, info os.FileInfo, _ error) error {
|
|
||||||
if info.IsDir() {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
fpaths[info.Name()] = abs(t, kind, info.Name())
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
require.Nil(t, err)
|
|
||||||
for filename, fpath := range fpaths {
|
|
||||||
file, err := os.Open(fpath)
|
|
||||||
require.Nil(t, err)
|
|
||||||
part, err := writer.CreateFormFile("foo", filename)
|
|
||||||
require.Nil(t, err)
|
|
||||||
_, err = io.Copy(part, file)
|
|
||||||
require.Nil(t, err)
|
|
||||||
}
|
|
||||||
if kind == "url" {
|
|
||||||
err := writer.WriteField("remoteURL", "http://google.com")
|
|
||||||
require.Nil(t, err)
|
|
||||||
}
|
|
||||||
for k, v := range formValues {
|
|
||||||
err := writer.WriteField(k, v)
|
|
||||||
require.Nil(t, err)
|
|
||||||
}
|
|
||||||
return body, writer.FormDataContentType()
|
|
||||||
}
|
|
||||||
|
|
||||||
func abs(t *testing.T, kind, filename string) string {
|
|
||||||
_, gofilename, _, ok := runtime.Caller(0)
|
|
||||||
require.Equal(t, ok, true, "got no caller information")
|
|
||||||
if filename == "" {
|
|
||||||
path, err := filepath.Abs(fmt.Sprintf("%s/testdata/%s", path.Dir(gofilename), kind))
|
|
||||||
require.Nil(t, err, `getting the absolute path of "%s"`, kind)
|
|
||||||
return path
|
|
||||||
}
|
|
||||||
path, err := filepath.Abs(fmt.Sprintf("%s/testdata/%s/%s", path.Dir(gofilename), kind, filename))
|
|
||||||
require.Nil(t, err, `getting the absolute path of "%s"`, filename)
|
|
||||||
return path
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package xerrortest
|
package test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package xlogtest
|
package test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/thecodingmachine/gotenberg/internal/pkg/xlog"
|
"github.com/thecodingmachine/gotenberg/internal/pkg/xlog"
|
||||||
Reference in New Issue
Block a user