38 lines
817 B
Go
38 lines
817 B
Go
package handler
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"testing"
|
|
|
|
rErrors "codeberg.org/danjones000/responsable-errors"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
var someErr error = errors.New("I am a teapot")
|
|
|
|
var noop Transformer = func(err error) rErrors.ResponsableError {
|
|
return nil
|
|
}
|
|
|
|
func TestWithTrans(t *testing.T) {
|
|
c := config{}
|
|
c = WithTransformer(noop)(c)
|
|
assert.Len(t, c.transformers, 1)
|
|
exp := fmt.Sprintf("%p", noop)
|
|
fd := fmt.Sprintf("%p", c.transformers[0])
|
|
assert.Equal(t, exp, fd)
|
|
}
|
|
|
|
func TestWithDef(t *testing.T) {
|
|
c := config{}
|
|
c = WithDefaultTransformer()(c)
|
|
assert.Len(t, c.transformers, 1)
|
|
exp := fmt.Sprintf("%p", ginTransformer)
|
|
fd := fmt.Sprintf("%p", c.transformers[0])
|
|
assert.Equal(t, exp, fd)
|
|
}
|
|
|
|
func TestGinTransNotGinError(t *testing.T) {
|
|
assert.Nil(t, ginTransformer(someErr))
|
|
}
|