-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
groups_test.go
60 lines (56 loc) · 1.69 KB
/
groups_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
package slogcommon
import (
"log/slog"
"testing"
"github.com/stretchr/testify/assert"
)
func TestAppendAttrsToGroup(t *testing.T) {
tests := map[string]struct {
groups []string
actualAttrs []slog.Attr
newAttrs []slog.Attr
expected []slog.Attr
}{
"NoGroups": {
groups: []string{},
actualAttrs: []slog.Attr{slog.String("key1", "value1")},
newAttrs: []slog.Attr{slog.String("key2", "value2")},
expected: []slog.Attr{slog.String("key1", "value1"), slog.String("key2", "value2")},
},
"SingleGroup": {
groups: []string{"group1"},
actualAttrs: []slog.Attr{
slog.Group("group1", slog.String("key1", "value1")),
},
newAttrs: []slog.Attr{slog.String("key2", "value2")},
expected: []slog.Attr{
slog.Group("group1", slog.String("key1", "value1"), slog.String("key2", "value2")),
},
},
"NestedGroups": {
groups: []string{"group1", "group2"},
actualAttrs: []slog.Attr{
slog.Group("group1", slog.Group("group2", slog.String("key1", "value1"))),
},
newAttrs: []slog.Attr{slog.String("key2", "value2")},
expected: []slog.Attr{
slog.Group("group1", slog.Group("group2", slog.String("key1", "value1"), slog.String("key2", "value2"))),
},
},
"NewGroup": {
groups: []string{"group1"},
actualAttrs: []slog.Attr{slog.String("key1", "value1")},
newAttrs: []slog.Attr{slog.String("key2", "value2")},
expected: []slog.Attr{
slog.String("key1", "value1"),
slog.Group("group1", slog.String("key2", "value2")),
},
},
}
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
actual := AppendAttrsToGroup(tc.groups, tc.actualAttrs, tc.newAttrs...)
assert.Equal(t, tc.expected, actual)
})
}
}