-
Notifications
You must be signed in to change notification settings - Fork 0
/
tools_test.go
60 lines (48 loc) · 1.3 KB
/
tools_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
package mtsdb
import (
"context"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/stretchr/testify/require"
"testing"
"time"
)
func TestGenerateSql(t *testing.T) {
t.Parallel()
assert := require.New(t)
type testData struct {
labels []string
tableName string
result string
}
metrics := []testData{
{
labels: []string{"one"},
tableName: "test",
result: "INSERT" + " INTO test (one,cnt) VALUES ($1,$2)",
},
{
labels: []string{"one", "two"},
tableName: "test2",
result: "INSERT" + " INTO test2 (one,two,cnt) VALUES ($1,$2,$3)",
}, {
labels: []string{"one", "two", "three", "four", "five"},
tableName: "test3",
result: "INSERT" + " INTO test3 (one,two,three,four,five,cnt) VALUES ($1,$2,$3,$4,$5,$6)",
},
}
for _, metric := range metrics {
tstConfig := DefaultConfig()
tstConfig.InsertDuration = 10 * time.Minute
ctx := context.Background()
m, err := newMtsdb(ctx, &pgxpool.Pool{}, tstConfig)
assert.NoError(err)
counter, err := NewMetricCounter(ctx, "testCounter", MetricCounterConfig{
TableName: metric.tableName,
Description: "desc",
}, metric.labels...)
assert.NoError(err)
m.MustRegister(counter)
_ = counter.Inc(metric.labels...)
assert.Equal(metric.result, m.generateSql(metric.tableName, metric.labels))
}
}