-
Notifications
You must be signed in to change notification settings - Fork 0
/
new_test.go
48 lines (43 loc) · 1022 Bytes
/
new_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
package err
import (
"errors"
"github.com/stretchr/testify/assert"
"testing"
)
func TestNewErr(t *testing.T) {
nErr := NewErr("NewErr", 1)
err := Err{}
err.message = "NewErr"
err.code = 1
assert.Equal(t, err, *nErr)
}
func TestNewErrWithCause(t *testing.T) {
causeErr := errors.New("causeErr")
nErr := NewErrWithCause("NewErr", 2, causeErr)
err := Err{}
err.message = "NewErr"
err.code = 2
err.previous = causeErr
assert.Equal(t, err, *nErr)
}
func TestNewWebErr(t *testing.T) {
nErr := NewWebErr(500, "NewWebErr", 3)
err := Err{}
err.message = "NewWebErr"
err.code = 3
err.statusCode = 500
err.isWebErr = true
assert.Equal(t, err, *nErr)
}
func TestNewWebErrWithCause(t *testing.T) {
causeErr := errors.New("causeWebErr")
nErr := NewWebErrWithCause(504, "NewWebErrWithCause", 4, causeErr)
err := Err{}
err.message = "NewWebErrWithCause"
err.code = 4
err.statusCode = 504
err.isWebErr = true
err.previous = causeErr
assert.Equal(t, err, *nErr)
assert.Equal(t, true, nErr.IsWebErr())
}