forked from arp242/goatcounter
/
memstore_test.go
49 lines (41 loc) · 982 Bytes
/
memstore_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
// Copyright © 2019 Martin Tournoij – This file is part of GoatCounter and
// published under the terms of a slightly modified EUPL v1.2 license, which can
// be found in the LICENSE file or at https://license.goatcounter.com
package goatcounter_test
import (
"context"
"testing"
. "zgo.at/goatcounter"
"zgo.at/goatcounter/gctest"
"zgo.at/zdb"
)
func TestMemstore(t *testing.T) {
ctx, clean := gctest.DB(t)
defer clean()
for i := 0; i < 2000; i++ {
Memstore.Append(gen(ctx))
}
_, err := Memstore.Persist(ctx)
if err != nil {
t.Fatal(err)
}
var count int
err = zdb.MustGet(ctx).GetContext(ctx, &count, `select count(*) from hits`)
if err != nil {
t.Fatal(err)
}
if count != 2000 {
t.Errorf("wrong count; wanted 2000 but got %d", count)
}
}
func gen(ctx context.Context) Hit {
s := MustGetSite(ctx)
one := int64(1)
return Hit{
Site: s.ID,
Session: &one,
Path: "/test",
Ref: "https://example.com/test",
Browser: "test",
}
}