-
Notifications
You must be signed in to change notification settings - Fork 31
/
utils_test.go
52 lines (40 loc) · 1.44 KB
/
utils_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package errorx
import (
"errors"
"testing"
"github.com/stretchr/testify/require"
)
func TestIgnoreWithTrait(t *testing.T) {
t.Run("Empty", func(t *testing.T) {
require.Error(t, IgnoreWithTrait(TimeoutElapsed.NewWithNoMessage()))
})
t.Run("AnotherTrait", func(t *testing.T) {
require.Error(t, IgnoreWithTrait(TimeoutElapsed.NewWithNoMessage(), NotFound()))
})
t.Run("Positive", func(t *testing.T) {
require.NoError(t, IgnoreWithTrait(TimeoutElapsed.NewWithNoMessage(), Timeout()))
})
t.Run("OneOfMany", func(t *testing.T) {
require.NoError(t, IgnoreWithTrait(TimeoutElapsed.NewWithNoMessage(), NotFound(), Timeout()))
})
}
func TestGetTypeName(t *testing.T) {
t.Run("Simple", func(t *testing.T) {
require.EqualValues(t, "common.assertion_failed", GetTypeName(AssertionFailed.NewWithNoMessage()))
})
t.Run("Wrap", func(t *testing.T) {
require.EqualValues(t, "common.illegal_state", GetTypeName(IllegalState.WrapWithNoMessage(AssertionFailed.NewWithNoMessage())))
})
t.Run("Decorate", func(t *testing.T) {
require.EqualValues(t, "common.assertion_failed", GetTypeName(Decorate(AssertionFailed.NewWithNoMessage(), "")))
})
t.Run("Nil", func(t *testing.T) {
require.EqualValues(t, "", GetTypeName(nil))
})
t.Run("Raw", func(t *testing.T) {
require.EqualValues(t, "", GetTypeName(errors.New("test")))
})
t.Run("DecoratedRaw", func(t *testing.T) {
require.EqualValues(t, "", GetTypeName(Decorate(errors.New("test"), "")))
})
}