✨ Add options, mostly transformers
This commit is contained in:
parent
b1e4c28dfe
commit
b4b4f041d7
4 changed files with 121 additions and 11 deletions
38
options_test.go
Normal file
38
options_test.go
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
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))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue