Files
threshold/internal/errors/option_test.go
T

40 lines
882 B
Go
Raw Normal View History

package errors
import (
2020-11-17 18:54:23 -08:00
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
// Test_getOpts provides unit tests for GetOpts and all the options
func Test_getOpts(t *testing.T) {
t.Parallel()
t.Run("WithMsg", func(t *testing.T) {
assert := assert.New(t)
// test default
opts := GetOpts()
testOpts := getDefaultOptions()
testOpts.withErrMsg = ""
assert.Equal(opts, testOpts)
// try setting it
opts = GetOpts(WithMsg("test msg"))
testOpts.withErrMsg = "test msg"
assert.Equal(opts, testOpts)
})
t.Run("WithWrap", func(t *testing.T) {
assert := assert.New(t)
// test default
opts := GetOpts()
testOpts := getDefaultOptions()
testOpts.withErrWrapped = nil
assert.Equal(opts, testOpts)
// try setting it
2020-11-17 18:54:23 -08:00
err := fmt.Errorf("test error")
opts = GetOpts(WithWrap(err))
testOpts.withErrWrapped = err
assert.Equal(opts, testOpts)
})
}