-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmulticollector_test.go
More file actions
61 lines (54 loc) · 1.33 KB
/
multicollector_test.go
File metadata and controls
61 lines (54 loc) · 1.33 KB
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
package main
import (
"errors"
"io"
"log"
"testing"
"github.com/google/go-cmp/cmp"
)
func newMultiCollectorForTest(t *testing.T, m multiCollectorMember) *multiCollector {
t.Helper()
c := newMultiCollector(m)
c.logger = log.New(io.Discard, "", 0)
return c
}
func TestFormatWarnings(t *testing.T) {
errTest := errors.New("test error")
errTest2 := errors.New("second error")
for _, tc := range []struct {
name string
warnings map[warningCategory][]error
want string
}{
{name: "empty"},
{
name: "empty slices",
warnings: map[warningCategory][]error{
warningCategoryUnspecified: nil,
warningCategoryGetRemoteVersion: nil,
},
},
{
name: "single",
warnings: map[warningCategory][]error{
warningCategoryUnspecified: nil,
warningCategoryGetRemoteVersion: []error{errTest},
},
want: `get_remote_version: ["test error"]`,
},
{
name: "multiple",
warnings: map[warningCategory][]error{
warningCategoryUnspecified: nil,
warningCategoryGetRemoteVersion: []error{errTest, errTest2},
},
want: `get_remote_version: ["second error" "test error"]`,
},
} {
t.Run(tc.name, func(t *testing.T) {
if diff := cmp.Diff(tc.want, formatWarnings(tc.warnings)); diff != "" {
t.Errorf("formatWarnings(%q) diff (-want +got):\n%s", tc.warnings, diff)
}
})
}
}