-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherr_test.go
More file actions
43 lines (36 loc) · 1.01 KB
/
Copy patherr_test.go
File metadata and controls
43 lines (36 loc) · 1.01 KB
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
package fault_test
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
"github.com/marcelofabianov/fault"
)
func TestError(t *testing.T) {
t.Run("Should implement standard error interface", func(t *testing.T) {
err := &fault.Error{
Message: "test message",
}
assert.Implements(t, (*error)(nil), err)
})
t.Run("Error method should return message only when no wrapped error", func(t *testing.T) {
err := &fault.Error{
Message: "test message",
}
assert.Equal(t, "test message", err.Error())
})
t.Run("Error method should return message and wrapped error", func(t *testing.T) {
wrappedErr := errors.New("original error")
err := &fault.Error{
Message: "test message",
Err: wrappedErr,
}
assert.Equal(t, "test message: original error", err.Error())
})
t.Run("Unwrap method should return the wrapped error", func(t *testing.T) {
wrappedErr := errors.New("original error")
err := &fault.Error{
Err: wrappedErr,
}
assert.Equal(t, wrappedErr, err.Unwrap())
})
}