-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstore_test.go
56 lines (52 loc) · 974 Bytes
/
store_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
package meter_test
import (
"context"
"testing"
"time"
meter "github.com/alxarch/go-meter/v2"
)
func Test_MemoryStore(t *testing.T) {
m := new(meter.MemoryStore)
m.Event = "test"
r1 := meter.StoreRequest{
Time: time.Now(),
Event: "test",
Labels: []string{"color", "taste"},
Counters: []meter.Counter{
{
Values: []string{"blue", "sour"},
Count: 3,
},
{
Values: []string{"blue", "bitter"},
Count: 10,
},
{
Values: []string{"green", "bitter"},
Count: 12,
},
},
}
if err := m.Store(&r1); err != nil {
t.Fatal(err)
}
ctx := context.Background()
q1 := meter.Query{
TimeRange: meter.TimeRange{
Start: time.Now().Add(-1 * time.Hour),
End: time.Now().Add(time.Hour),
},
Match: meter.Fields{
{Label: "color", Value: "blue"},
},
}
it := m.Scan(ctx, &q1)
var n int64
for it.Next() {
item := it.Item()
n += item.Count
}
if n != 13 {
t.Errorf("Invalid number of items %d", n)
}
}