-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkey_internal_test.go
63 lines (52 loc) · 1.11 KB
/
key_internal_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
package statter
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestKey(t *testing.T) {
tests := []struct {
name string
keyName string
keyTags []Tag
want string
}{
{
name: "key with tags",
keyName: "some.key",
keyTags: []Tag{{"first", "tag1"}, {"second", "tag2"}},
want: "some.key:first=tag1:second=tag2",
},
{
name: "key with tags out of order",
keyName: "some.key",
keyTags: []Tag{{"second", "tag2"}, {"first", "tag1"}},
want: "some.key:first=tag1:second=tag2",
},
{
name: "key without tags",
keyName: "some.key",
keyTags: nil,
want: "some.key",
},
}
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
k := newKey(test.keyName, test.keyTags)
defer putKey(k)
assert.Equal(t, test.want, k.String())
})
}
}
func BenchmarkKey(b *testing.B) {
tags := []Tag{{"second", "tag2"}, {"first", "tag1"}, {"third", "tag3"}, {"forth", "tag4"}}
b.ReportAllocs()
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
k := newKey("test", tags)
putKey(k)
}
})
}