forked from vearch/vearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
multierror_test.go
43 lines (36 loc) · 886 Bytes
/
multierror_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
package multierror
import (
"errors"
"reflect"
"testing"
)
func TestErrors(t *testing.T) {
errors := []error{errors.New("foo"), errors.New("bar")}
multi := &MultiError{errors: errors}
if !reflect.DeepEqual(errors, multi.Errors()) {
t.Fatalf("bad: %s", multi.Errors())
}
}
func TestErrorErrorOrNil(t *testing.T) {
errs := new(MultiError)
if errs.ErrorOrNil() != nil {
t.Fatalf("bad: %#v", errs.ErrorOrNil())
}
errs.errors = []error{errors.New("foo")}
if v := errs.ErrorOrNil(); v == nil {
t.Fatal("should not be nil")
} else if !reflect.DeepEqual(v, errs) {
t.Fatalf("bad: %#v", v)
}
}
func TestAppendError(t *testing.T) {
expected := `the following errors occurred:
-- foo
-- bar
-- test`
multi := Combine(errors.New("foo"), errors.New("bar"))
multi.Append(errors.New("test"))
if multi.Error() != expected {
t.Fatalf("bad: %s", multi.Error())
}
}