-
Notifications
You must be signed in to change notification settings - Fork 4
/
error_test.go
40 lines (36 loc) · 1020 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
package herd
import (
"fmt"
"testing"
)
func TestEmptyError(t *testing.T) {
e := &MultiError{Subject: "Test error"}
if e.HasErrors() {
t.Error("Empty multierror seems to have an error")
}
if e.Error() != "" {
t.Errorf("Empty multierror has a non-empty string: %s", e.Error())
}
}
func TestNoSubject(t *testing.T) {
e := &MultiError{}
e.Add(fmt.Errorf("Test error 1"))
if e.Error() != "Test error 1" {
t.Errorf("Unexpected single-error string: %s", e.Error())
}
e.Add(fmt.Errorf("Test error 2"))
if e.Error() != "Test error 1\nTest error 2" {
t.Errorf("Unexpected single-error string: %s", e.Error())
}
}
func TestWithSubject(t *testing.T) {
e := &MultiError{Subject: "Test subject"}
e.Add(fmt.Errorf("Test error 1"))
if e.Error() != "Test subject:\nTest error 1" {
t.Errorf("Unexpected single-error string: %s", e.Error())
}
e.Add(fmt.Errorf("Test error 2"))
if e.Error() != "Test subject:\nTest error 1\nTest error 2" {
t.Errorf("Unexpected single-error string: %s", e.Error())
}
}