-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenality_test.go
69 lines (59 loc) · 1.34 KB
/
genality_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
package genality
import (
"context"
"database/sql"
"log"
"os"
"testing"
"time"
"github.com/google/uuid"
"github.com/infiniteloopcloud/genality/migration"
)
const (
testConnection = "postgres://genality:genality@localhost:5435/genality?sslmode=disable"
)
func TestMain(m *testing.M) {
conn, err := sql.Open(driverName, testConnection)
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
if err := migration.Up(ctx, conn); err != nil {
log.Fatal(err)
}
exitVal := m.Run()
//migration.Down(ctx, conn)
os.Exit(exitVal)
}
func TestExample(t *testing.T) {
random := uuid.New().String()
m, err := newGenality(Opts{
ConnectionString: testConnection,
})
if err != nil {
t.Fatal(err)
}
for i := 0; i < 100; i++ {
if err := m.Add(context.Background(), random); err != nil {
t.Fatal(err)
}
}
for i := 0; i < 50; i++ {
tim := time.Now().UTC().Add(time.Duration(-(i * 15)) * time.Minute)
if err := m.add(context.Background(), random, tim); err != nil {
t.Fatal(err)
}
}
count, err := m.GetCountFrom(context.Background(), random, time.Now().UTC().Add(-1*time.Hour))
if err != nil {
t.Fatal(err)
}
if count != 104 {
t.Fatal("count should be 104")
}
resp, err := m.GetCountBuckets(context.Background(), random, time.Now().UTC().Add(-10*time.Hour), time.Hour)
if err != nil {
t.Fatal(err)
}
t.Log(resp)
}