-
Notifications
You must be signed in to change notification settings - Fork 0
/
multi_errors_test.go
37 lines (29 loc) · 1.06 KB
/
multi_errors_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
package errors
import "testing"
func TestNewMulti(t *testing.T) {
t.Run("when NewMulti is provided with 3 errors, it should return a new error with the message indicating the number of errors and highlighting the first error", func(t *testing.T) {
err1 := New("failed 1")
err2 := New("failed 2")
err3 := New("failed 3")
multiErr := NewMulti(err1, err2, err3)
expected := "first of 3 errors: failed 1"
if got := multiErr.Error(); got != expected {
t.Errorf(`wrong error message, got "%s", expected "%s"`, got, expected)
return
}
})
}
func TestAppendMulti(t *testing.T) {
t.Run("when AppendMulti is provided with a multi error and a new error, it should append the new error to the multi error", func(t *testing.T) {
multiErr := NewMulti()
if err := AppendMulti(multiErr, New("failed 1")); err != nil {
t.Errorf("failed to append an error: %v", err)
return
}
expected := "first of 1 errors: failed 1"
if got := multiErr.Error(); got != expected {
t.Errorf(`wrong error message, got "%s", expected "%s"`, got, expected)
return
}
})
}