mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-08 00:22:14 +01:00
adding merge printer tests
This commit is contained in:
46
internal/pkg/printer/merge_test.go
Normal file
46
internal/pkg/printer/merge_test.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package printer
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/thecodingmachine/gotenberg/internal/pkg/xerror"
|
||||
"github.com/thecodingmachine/gotenberg/internal/pkg/xlog"
|
||||
"github.com/thecodingmachine/gotenberg/test/internalpkg/printertest"
|
||||
"github.com/thecodingmachine/gotenberg/test/internalpkg/xerrortest"
|
||||
"github.com/thecodingmachine/gotenberg/test/internalpkg/xlogtest"
|
||||
)
|
||||
|
||||
func TestMergePrinter(t *testing.T) {
|
||||
var (
|
||||
logger xlog.Logger = xlogtest.DebugLogger()
|
||||
fpaths []string = printertest.MergeFpaths(t)
|
||||
opts MergePrinterOptions
|
||||
dest string
|
||||
p Printer
|
||||
err error
|
||||
)
|
||||
// default options.
|
||||
opts = MergePrinterOptions{
|
||||
WaitTimeout: 10.0,
|
||||
}
|
||||
p = NewMergePrinter(logger, fpaths, opts)
|
||||
dest = printertest.GenerateDestination()
|
||||
err = p.Print(dest)
|
||||
assert.Nil(t, err)
|
||||
err = os.RemoveAll(dest)
|
||||
assert.Nil(t, err)
|
||||
// should not be OK as context.Context
|
||||
// should timeout.
|
||||
opts = MergePrinterOptions{
|
||||
WaitTimeout: 0.1,
|
||||
}
|
||||
p = NewMergePrinter(logger, fpaths, opts)
|
||||
dest = printertest.GenerateDestination()
|
||||
err = p.Print(dest)
|
||||
xerrortest.AssertError(t, err)
|
||||
assert.Equal(t, xerror.TimeoutCode, xerror.Code(err))
|
||||
err = os.RemoveAll(dest)
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
@@ -8,6 +8,11 @@ import (
|
||||
"github.com/thecodingmachine/gotenberg/internal/pkg/xrand"
|
||||
)
|
||||
|
||||
/*
|
||||
testdataDirectoryPath should be
|
||||
the absolute of the testdata INSIDE
|
||||
the Docker image.
|
||||
*/
|
||||
const testdataDirectoryPath string = "/gotenberg/tests/test/testdata"
|
||||
|
||||
// GenerateDestination simply generates
|
||||
@@ -16,6 +21,15 @@ func GenerateDestination() string {
|
||||
return fmt.Sprintf("/tmp/%s.pdf", xrand.Get())
|
||||
}
|
||||
|
||||
// MergeFpaths return the paths
|
||||
// of the PDF files used in tests.
|
||||
func MergeFpaths(t *testing.T) []string {
|
||||
return []string{
|
||||
fpath(t, "pdf", "gotenberg.pdf"),
|
||||
fpath(t, "pdf", "gotenberg_bis.pdf"),
|
||||
}
|
||||
}
|
||||
|
||||
// OfficeFpaths return the paths
|
||||
// of the Office documents used in tests.
|
||||
func OfficeFpaths(t *testing.T) []string {
|
||||
|
||||
Reference in New Issue
Block a user