diff --git a/internal/pkg/printer/merge_test.go b/internal/pkg/printer/merge_test.go new file mode 100644 index 00000000..94b6136f --- /dev/null +++ b/internal/pkg/printer/merge_test.go @@ -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) +} diff --git a/test/internalpkg/printertest/printertest.go b/test/internalpkg/printertest/printertest.go index 9c909856..bfa2a92f 100644 --- a/test/internalpkg/printertest/printertest.go +++ b/test/internalpkg/printertest/printertest.go @@ -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 {