adding merge printer tests

This commit is contained in:
Julien Neuhart
2019-07-23 16:50:24 +02:00
parent 08e7a2c065
commit 5feff0d0ec
2 changed files with 60 additions and 0 deletions

View 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)
}

View File

@@ -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 {