-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
errors_test.go
67 lines (53 loc) · 1.69 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package do
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestShutdownErrors_Add(t *testing.T) {
is := assert.New(t)
se := newShutdownErrors()
is.Equal(0, len(*se))
is.Equal(0, se.Len())
se.Add("scope-1", "scope-a", "service-a", nil)
is.Equal(0, len(*se))
is.Equal(0, se.Len())
is.EqualValues(&ShutdownErrors{}, se)
se.Add("scope-2", "scope-b", "service-b", assert.AnError)
is.Equal(1, len(*se))
is.Equal(1, se.Len())
is.EqualValues(&ShutdownErrors{
{ScopeID: "scope-2", ScopeName: "scope-b", Service: "service-b"}: assert.AnError,
}, se)
}
func TestShutdownErrors_Error(t *testing.T) {
is := assert.New(t)
se := newShutdownErrors()
is.Equal(0, len(*se))
is.Equal(0, se.Len())
is.EqualValues("DI: no shutdown errors", se.Error())
se.Add("scope-1", "scope-a", "service-a", nil)
is.Equal(0, len(*se))
is.Equal(0, se.Len())
is.EqualValues("DI: no shutdown errors", se.Error())
se.Add("scope-2", "scope-b", "service-b", assert.AnError)
is.Equal(1, len(*se))
is.Equal(1, se.Len())
is.EqualValues("DI: shutdown errors:\n - scope-b > service-b: assert.AnError general error for testing", se.Error())
}
func TestMergeShutdownErrors(t *testing.T) {
is := assert.New(t)
se1 := newShutdownErrors()
se2 := newShutdownErrors()
se3 := newShutdownErrors()
se1.Add("scope-1", "scope-a", "service-a", assert.AnError)
se2.Add("scope-2", "scope-b", "service-b", assert.AnError)
result := mergeShutdownErrors(se1, se2, se3, nil)
is.Equal(2, result.Len())
is.EqualValues(
&ShutdownErrors{
{ScopeID: "scope-1", ScopeName: "scope-a", Service: "service-a"}: assert.AnError,
{ScopeID: "scope-2", ScopeName: "scope-b", Service: "service-b"}: assert.AnError,
},
result,
)
}