-
Notifications
You must be signed in to change notification settings - Fork 11
/
multierror_test.go
58 lines (42 loc) · 1.2 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package valkyrie
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestMultiErrorValidation(t *testing.T) {
me := &MultiError{}
me.Push("one")
me.Push("two")
res := me.HasError()
assert.Error(t, res, "expected populated multi-error validation to be non-nil")
}
func TestMultiErrorRespresentation(t *testing.T) {
me := &MultiError{}
me.Push("one")
me.Push("two")
require.Error(t, me, "no multierror occured")
res := me.Error()
assert.Equal(t, "one, two", res)
}
func TestMultiErrorWithoutErrorsValidationIsNil(t *testing.T) {
me := &MultiError{}
err := me.HasError()
assert.NoError(t, err, "expected empty multi-error validation to be nil")
}
func TestMultiErrorRespresentationIsEmpty(t *testing.T) {
me := &MultiError{}
res := me.Error()
assert.Empty(t, res, "expected empty multi-error representation to be empty")
}
func TestMultiErrorWhileConcurrentPushShouldNotPanic(t *testing.T) {
me := &MultiError{}
concurrentPushAndErrors := func() {
for i := 0; i < 100; i++ {
go func(errValue int) { me.Push(fmt.Sprintf("Error %d", errValue)) }(i)
go func() { _ = me.Error() }()
}
}
assert.NotPanics(t, concurrentPushAndErrors)
}