-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathbuilder_test.go
58 lines (49 loc) · 1.57 KB
/
builder_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
53
54
55
56
57
58
package errorx
import (
"errors"
"fmt"
"testing"
"github.com/stretchr/testify/require"
)
func TestBuilderTransparency(t *testing.T) {
t.Run("Raw", func(t *testing.T) {
err := NewErrorBuilder(testType).WithCause(errors.New("bad thing")).Transparent().Create()
require.False(t, err.IsOfType(testType))
require.NotEqual(t, testType, err.Type())
})
t.Run("RawWithModifier", func(t *testing.T) {
err := NewErrorBuilder(testTypeTransparent).WithCause(errors.New("bad thing")).Create()
require.False(t, err.IsOfType(testType))
require.NotEqual(t, testType, err.Type())
})
}
func testBuilderRespectsNoStackTraceMarkerFrame() error {
return testType.NewWithNoMessage()
}
func TestBuilderRespectsNoStackTrace(t *testing.T) {
wrapperErrorTypes := []*Type{testTypeSilent, testTypeSilentTransparent}
for _, et := range wrapperErrorTypes {
t.Run(et.String(), func(t *testing.T) {
t.Run("Naked", func(t *testing.T) {
err := NewErrorBuilder(et).
WithCause(errors.New("naked error")).
Create()
require.Nil(t, err.stackTrace)
})
t.Run("WithoutStacktrace", func(t *testing.T) {
err := NewErrorBuilder(et).
WithCause(testTypeSilent.NewWithNoMessage()).
Create()
require.Nil(t, err.stackTrace)
})
t.Run("WithStacktrace", func(t *testing.T) {
cause := testBuilderRespectsNoStackTraceMarkerFrame()
err := NewErrorBuilder(et).
WithCause(cause).
Create()
require.Same(t, err.stackTrace, Cast(cause).stackTrace)
require.Contains(t, fmt.Sprintf("%+v", err), "testBuilderRespectsNoStackTraceMarkerFrame")
})
})
}
}