-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror_test.go
44 lines (35 loc) · 853 Bytes
/
error_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
package goerr_test
import (
"fmt"
"testing"
"github.com/brad-jones/goerr/v2"
"github.com/stretchr/testify/assert"
)
func TestErrorNewFromString(t *testing.T) {
e := goerr.New("abc")
assert.Equal(t, "abc", e.Error())
}
func TestErrorNewFromNumber(t *testing.T) {
e := goerr.New(123)
assert.Equal(t, "123", e.Error())
}
type Foo struct {
Bar string
}
func TestErrorNewFromStruct(t *testing.T) {
e := goerr.New(&Foo{Bar: "abc"})
assert.Equal(t, "&{Bar:abc}", e.Error())
}
func TestErrorNewFromError(t *testing.T) {
e := goerr.New(fmt.Errorf("abc"))
assert.Equal(t, "abc", e.Error())
}
func TestErrorNewFromGoErr(t *testing.T) {
e := goerr.New(goerr.New("abc"))
assert.Equal(t, "abc", e.Error())
}
func TestErrorUnwrap(t *testing.T) {
innerErr := fmt.Errorf("abc")
e := goerr.New(innerErr)
assert.Equal(t, innerErr, e.Unwrap())
}