-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathfields_test.go
90 lines (68 loc) · 1.54 KB
/
fields_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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package logger_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/smartcontractkit/chainlink/v2/core/logger"
)
func TestFields_Merge(t *testing.T) {
t.Parallel()
f1 := make(logger.Fields)
f1["key1"] = "value1"
f2 := make(logger.Fields)
f2["key2"] = "value2"
merged := f1.Merge(f2)
assert.Len(t, merged, 2)
v1, ok1 := merged["key1"]
assert.True(t, ok1)
assert.Equal(t, "value1", v1)
v2, ok2 := merged["key2"]
assert.True(t, ok2)
assert.Equal(t, "value2", v2)
t.Run("self merge", func(t *testing.T) {
t.Parallel()
merged := f1.Merge(f1)
assert.Len(t, merged, 1)
assert.Equal(t, f1, merged)
})
}
func TestFields_Slice(t *testing.T) {
t.Parallel()
f := make(logger.Fields)
f["str"] = "foo"
f["int"] = 123
s := f.Slice()
assert.Len(t, s, 4)
for i := 0; i < len(s); i += 2 {
switch s[i] {
case "int":
assert.Equal(t, 123, s[i+1])
case "str":
assert.Equal(t, "foo", s[i+1])
}
}
t.Run("empty", func(t *testing.T) {
t.Parallel()
empty := make(logger.Fields)
assert.Empty(t, empty.Slice())
})
}
func TestFields_With(t *testing.T) {
t.Parallel()
f := make(logger.Fields)
f["str"] = "foo"
f["int"] = 123
w := f.With("bool", true, "float", 3.14)
assert.Len(t, w, 4)
t.Run("single", func(t *testing.T) {
t.Parallel()
assert.Panics(t, func() {
//lint:ignore SA5012 we expect panic here
_ = f.With("xyz")
}, "expected even number of arguments")
})
t.Run("empty", func(t *testing.T) {
t.Parallel()
empty := make(logger.Fields).With()
assert.Empty(t, empty)
})
}