mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-10 09:32:13 +01:00
typo in timeout tests + adding tests for standarderror
This commit is contained in:
@@ -9,6 +9,7 @@ go test github.com/thecodingmachine/gotenberg/internal/pkg/pm2 -run TestChromeSt
|
||||
go test github.com/thecodingmachine/gotenberg/internal/pkg/pm2 -run TestUnoconvStart
|
||||
|
||||
# Running others tests.
|
||||
go test -race -cover -covermode=atomic github.com/thecodingmachine/gotenberg/internal/pkg
|
||||
go test -race -cover -covermode=atomic github.com/thecodingmachine/gotenberg/internal/app/api
|
||||
|
||||
# Finally testing processes shutdown.
|
||||
|
||||
@@ -64,6 +64,8 @@ func Code(err error) string {
|
||||
return Internal
|
||||
}
|
||||
|
||||
const defaultMessage = "an internal error has occurred: please contact technical support"
|
||||
|
||||
// Message returns the human-readable message of the error, if available.
|
||||
// Otherwise returns a generic error message.
|
||||
func Message(err error) string {
|
||||
@@ -77,7 +79,7 @@ func Message(err error) string {
|
||||
if ok && e.Err != nil {
|
||||
return Message(e.Err)
|
||||
}
|
||||
return "An internal error has occurred. Please contact technical support."
|
||||
return defaultMessage
|
||||
}
|
||||
|
||||
// Op returns the logical operation of the error, if available.
|
||||
|
||||
70
internal/pkg/standarderror/standarderror_test.go
Normal file
70
internal/pkg/standarderror/standarderror_test.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package standarderror
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func scenario1() error {
|
||||
rootErr := errors.New("root error")
|
||||
nestedErr := &Error{
|
||||
Code: Invalid,
|
||||
Op: "bar",
|
||||
Message: "nested error",
|
||||
Err: rootErr,
|
||||
}
|
||||
err := &Error{
|
||||
Op: "foo",
|
||||
Err: nestedErr,
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func scenario2() error {
|
||||
nestedErr := &Error{
|
||||
Code: Invalid,
|
||||
Op: "bar",
|
||||
Message: "nested error",
|
||||
}
|
||||
err := &Error{
|
||||
Code: Internal,
|
||||
Op: "foo",
|
||||
Err: nestedErr,
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func TestError(t *testing.T) {
|
||||
err := scenario1()
|
||||
assert.Equal(t, "root error", err.Error())
|
||||
err = scenario2()
|
||||
assert.Equal(t, "<invalid> nested error", err.Error())
|
||||
}
|
||||
|
||||
func TestCode(t *testing.T) {
|
||||
assert.Equal(t, "", Code(nil))
|
||||
err := scenario1()
|
||||
assert.Equal(t, Invalid, Code(err))
|
||||
err = scenario2()
|
||||
assert.Equal(t, Internal, Code(err))
|
||||
err = errors.New("some error")
|
||||
assert.Equal(t, Internal, Code(err))
|
||||
}
|
||||
|
||||
func TestMessage(t *testing.T) {
|
||||
assert.Equal(t, "", Message(nil))
|
||||
err := scenario1()
|
||||
assert.Equal(t, "nested error", Message(err))
|
||||
err = errors.New("some error")
|
||||
assert.Equal(t, defaultMessage, Message(err))
|
||||
}
|
||||
|
||||
func TestOp(t *testing.T) {
|
||||
assert.Equal(t, "", Op(nil))
|
||||
err := scenario1()
|
||||
assert.Equal(t, "foo: bar", Op(err))
|
||||
err = errors.New("some error")
|
||||
assert.Equal(t, "", Op(err))
|
||||
}
|
||||
@@ -27,12 +27,12 @@ func TestErr(t *testing.T) {
|
||||
err := Err(ctx)
|
||||
assert.NotNil(t, err)
|
||||
standardized := test.RequireStandardError(t, err)
|
||||
assert.Equal(t, standardized.Code, standarderror.Timeout)
|
||||
assert.Equal(t, standarderror.Timeout, standardized.Code)
|
||||
// should failed.
|
||||
ctx, cancel = Context(5)
|
||||
cancel()
|
||||
err = Err(ctx)
|
||||
assert.NotNil(t, err)
|
||||
standardized = test.RequireStandardError(t, err)
|
||||
assert.Equal(t, standarderror.Code(err), standarderror.Internal)
|
||||
assert.Equal(t, standarderror.Internal, standarderror.Code(err))
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ func AssertConcurrent(t *testing.T, fn func() error, amount int) {
|
||||
// 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, ok, true)
|
||||
require.Equal(t, true, ok)
|
||||
return standardized
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user