refactoring tests util methods + adding context tests

This commit is contained in:
Julien Neuhart
2019-07-24 14:56:12 +02:00
parent 2be9ae7868
commit 554474776c
23 changed files with 295 additions and 234 deletions

View File

@@ -8,13 +8,12 @@ import (
"github.com/stretchr/testify/assert"
"github.com/thecodingmachine/gotenberg/internal/pkg/xerror"
"github.com/thecodingmachine/gotenberg/internal/pkg/xtime"
"github.com/thecodingmachine/gotenberg/test/internalpkg/xerrortest"
"github.com/thecodingmachine/gotenberg/test/internalpkg/xlogtest"
"github.com/thecodingmachine/gotenberg/test"
)
func TestMustHandleError(t *testing.T) {
previousErr := errors.New("previous error")
logger := xlogtest.DebugLogger()
logger := test.DebugLogger()
// context should not have an error.
ctx, cancel := WithTimeout(logger, 5)
defer cancel()
@@ -31,13 +30,13 @@ func TestMustHandleError(t *testing.T) {
defer cancel()
time.Sleep(xtime.Duration(1))
err = MustHandleError(ctx, previousErr)
xerr := xerrortest.AssertError(t, err)
xerr := test.AssertError(t, err)
assert.Equal(t, xerror.TimeoutCode, xerror.Code(xerr))
// context should have an error different
// than context.DeadlineExceeded.
ctx, cancel = WithTimeout(logger, 5)
cancel()
err = MustHandleError(ctx, previousErr)
xerr = xerrortest.AssertError(t, err)
xerr = test.AssertError(t, err)
assert.Equal(t, xerror.InternalCode, xerror.Code(xerr))
}