-
Notifications
You must be signed in to change notification settings - Fork 0
/
error_test.go
49 lines (41 loc) · 946 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
41
42
43
44
45
46
47
48
49
package shutdown
import (
"errors"
"testing"
)
func TestShutdownError(t *testing.T) {
t.Parallel()
tests := []struct {
name string
err error
expectedString []string
}{
{
name: "happy path",
err: shutdownError(map[string]error{
"test1": errors.New("dummy error 1"),
"test2": errors.New("dummy error 2"),
}),
expectedString: []string{
"test1 err: dummy error 1, test2 err: dummy error 2",
"test2 err: dummy error 2, test1 err: dummy error 1",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
// everytime we do Error(), might be different order
gotErr := tt.err.Error()
found := false
for _, expectedString := range tt.expectedString {
if expectedString == gotErr {
found = true
}
}
if !found {
t.Errorf("got error string = %v, want error string in %v", gotErr, tt.expectedString)
}
})
}
}