-
Notifications
You must be signed in to change notification settings - Fork 0
/
field_test.go
75 lines (62 loc) · 1.56 KB
/
field_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
package clogger
import (
"testing"
"github.com/stretchr/testify/require"
)
func Test_fieldCollection_add(t *testing.T) {
fc := newFieldCollection()
fc.add("add", "value")
require.Equal(t, fc.retrieve("add"), "value")
require.Empty(t, fc.retrieve("some-unknown-key"))
}
func Test_fieldCollection_addField(t *testing.T) {
fc := newFieldCollection()
fc.addField(field{key: "addField", value: "value"})
require.Equal(t, fc.retrieve("addField"), "value")
require.Empty(t, fc.retrieve("some-unknown-key"))
}
func Test_fieldCollection_fields(t *testing.T) {
fc := newFieldCollection()
fs := []field{
{
key: "key1",
value: "value1",
},
{
key: "key2",
value: "value2",
},
}
for _, f := range fs {
fc.add(f.key, f.value)
}
require.Empty(t, fc.retrieve("add0"))
found := fc.fields()
for _, f := range found {
require.Equal(t, fc.retrieve(f.key), f.value)
}
}
func Test_fieldCollection_len(t *testing.T) {
fc := newFieldCollection()
fc.add("k", "v")
fc.add("key", "val")
require.Equal(t, 2, fc.len())
}
func Test_fieldCollection_merge(t *testing.T) {
fc := newFieldCollection()
fc.add("k1", "v1")
fc.add("k2", "v2")
ff := newFieldCollection()
ff.add("k2", "v3") // ! when merging, identical keys will be overwritten in original fc
ff.add("k3", "v3")
fc.merge(ff)
require.Equal(t, fc.retrieve("k1"), "v1")
require.Equal(t, fc.retrieve("k2"), "v3")
require.Equal(t, fc.retrieve("k3"), "v3")
}
func Test_newFieldCollection(t *testing.T) {
fc := newFieldCollection()
require.NotNil(t, fc)
require.NotNil(t, fc.m)
require.NotNil(t, fc.mu)
}