huge refactoring

This commit is contained in:
Julien Neuhart
2019-07-23 13:57:18 +02:00
parent f6b357691c
commit 7bfbda4490
105 changed files with 4051 additions and 2667 deletions

18
test/cmd/pm2/pm2.go Normal file
View File

@@ -0,0 +1,18 @@
package main
import (
"github.com/thecodingmachine/gotenberg/internal/pkg/pm2"
"github.com/thecodingmachine/gotenberg/test/internalpkg/xlogtest"
)
func main() {
logger := xlogtest.DebugLogger()
process := pm2.NewChromeProcess(logger)
if err := process.Start(); err != nil {
panic(err)
}
process = pm2.NewUnoconvProcess(logger)
if err := process.Start(); err != nil {
panic(err)
}
}

3
test/doc.go Normal file
View File

@@ -0,0 +1,3 @@
// Package test contains useful
// functions used across tests.
package test

View File

@@ -0,0 +1,6 @@
/*
Package xerrortest contains useful
functions for tests related
to xerror package.
*/
package xerrortest

View File

@@ -0,0 +1,18 @@
package xerrortest
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/thecodingmachine/gotenberg/internal/pkg/xerror"
)
// AssertError validates that given error
// is of an instance of xerror.Error.
// If so, returns the instance of xerror.Error.
func AssertError(t *testing.T, err error) *xerror.Error {
assert.NotNil(t, err)
standardized, ok := err.(*xerror.Error)
assert.Equal(t, true, ok)
return standardized
}

View File

@@ -0,0 +1,6 @@
/*
Package xlogtest contains useful
functions for tests related
to xlog package.
*/
package xlogtest

View File

@@ -0,0 +1,23 @@
package xlogtest
import (
"github.com/thecodingmachine/gotenberg/internal/pkg/xlog"
)
// DebugLogger creates a xlog.Logger
// with xlog.DebugLevel for our tests.
func DebugLogger() xlog.Logger {
return xlog.New(xlog.DebugLevel, "tests")
}
// InfoLogger creates a xlog.Logger
// with xlog.InfoLevel for our tests.
func InfoLogger() xlog.Logger {
return xlog.New(xlog.DebugLevel, "tests")
}
// ErrorLogger creates a xlog.Logger
// with xlog.ErrorLevel for our tests.
func ErrorLogger() xlog.Logger {
return xlog.New(xlog.ErrorLevel, "tests")
}

View File

@@ -1,4 +1,3 @@
// Package test contains useful functions used across tests.
package test
import (
@@ -14,11 +13,9 @@ import (
"runtime"
"testing"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/thecodingmachine/gotenberg/internal/pkg/logger"
"github.com/thecodingmachine/gotenberg/internal/pkg/standarderror"
"github.com/thecodingmachine/gotenberg/internal/pkg/xerror"
"golang.org/x/sync/errgroup"
)
@@ -55,21 +52,16 @@ func AssertConcurrent(t *testing.T, fn func() error, amount int) {
assert.NoError(t, err)
}
// RequireStandardError validates that given error
// is of an instance of standarderror.Error.
// If so, returns the instance of standarderror.Error.
func RequireStandardError(t *testing.T, err error) *standarderror.Error {
standardized, ok := err.(*standarderror.Error)
require.Equal(t, true, ok)
// 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
}
// CreateTestLogger create a default logger
// for our tests.
func CreateTestLogger() *logger.Logger {
return logger.New(logrus.DebugLevel, "tests")
}
// HTMLTestMultipartForm returns the body
// for a multipate/form-data request with all
// files under "html" folder.