-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathadd_error_test.go
More file actions
36 lines (29 loc) · 832 Bytes
/
add_error_test.go
File metadata and controls
36 lines (29 loc) · 832 Bytes
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
package changeset
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
func TestAddError(t *testing.T) {
ch := &Changeset{}
assert.Nil(t, ch.Error())
assert.Nil(t, ch.Errors())
assert.Equal(t, 0, len(ch.Errors()))
AddError(ch, "field1", "field1 is required")
assert.NotNil(t, ch.Error())
assert.NotNil(t, ch.Errors())
assert.Equal(t, 1, len(ch.Errors()))
assert.Equal(t, "field1 is required", ch.Error().Error())
AddError(ch, "field2", "field2 is not valid")
assert.NotNil(t, ch.Error())
assert.NotNil(t, ch.Errors())
assert.Equal(t, 2, len(ch.Errors()))
assert.Equal(t, "field2 is not valid", ch.Errors()[1].Error())
}
func TestError_Unwrap(t *testing.T) {
var (
wrappedError = errors.New("error")
err = Error{Err: wrappedError}
)
assert.Equal(t, wrappedError, err.Unwrap())
}