-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext_test.go
43 lines (31 loc) · 1.35 KB
/
context_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
package stats_test
import (
"context"
"testing"
"github.com/bool64/stats"
"github.com/stretchr/testify/assert"
)
func TestAddKeysAndValues(t *testing.T) {
ctx := stats.AddKeysAndValues(context.Background(), "k1", "one", "k2", "two")
assert.Equal(t, []string{"k1", "one", "k2", "two"}, stats.KeysAndValues(ctx))
ctx2 := stats.AddKeysAndValues(ctx, "k3", "three")
assert.Equal(t, []string{"k1", "one", "k2", "two", "k3", "three"}, stats.KeysAndValues(ctx2))
ctx3 := stats.AddKeysAndValues(ctx2, "k4", "four")
assert.Equal(t, []string{"k1", "one", "k2", "two", "k3", "three", "k4", "four"}, stats.KeysAndValues(ctx3))
ctx4 := stats.AddKeysAndValues(ctx2, "k4a", "four-a")
assert.Equal(t, []string{"k1", "one", "k2", "two", "k3", "three", "k4a", "four-a"}, stats.KeysAndValues(ctx4))
assert.Equal(t, []string{"k1", "one", "k2", "two", "k3", "three", "k4", "four"}, stats.KeysAndValues(ctx3))
}
func BenchmarkAddKeysAndValues(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
ctx := stats.AddKeysAndValues(context.Background(), "k1", "one", "k2", "two")
_ = stats.KeysAndValues(ctx)
ctx2 := stats.AddKeysAndValues(ctx, "k3", "three")
_ = stats.KeysAndValues(ctx2)
ctx3 := stats.AddKeysAndValues(ctx2, "k4", "four")
_ = stats.KeysAndValues(ctx3)
ctx4 := stats.AddKeysAndValues(ctx2, "k4a", "four-a")
_ = stats.KeysAndValues(ctx4)
}
}