-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmetricmonitor_test.go
54 lines (48 loc) · 1.13 KB
/
metricmonitor_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
package ddqp
import (
"testing"
"github.com/alecthomas/repr"
"github.com/stretchr/testify/require"
)
func Test_MetricMonitor(t *testing.T) {
parser := NewMetricMonitorParser()
tests := []struct {
name string
query string
wantErr bool
printAST bool // For debugging, can opt in to print AST
}{
{
name: "test simple monitor",
query: "avg(last_5m):max:system.disk.in_use{*} by {host} > 1",
wantErr: false,
printAST: false,
},
{
name: "test simple monitor with float",
query: "avg(last_5m):max:system.disk.in_use{*} by {host} > 1.2",
wantErr: false,
printAST: false,
},
{
name: "test evaluation double-digit evaluation window",
query: "avg(last_15m):max:system.disk.in_use{*} by {host} > 1.2",
wantErr: false,
printAST: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ast, err := parser.Parse(tt.query)
if (err != nil) != tt.wantErr {
require.NoError(t, err)
}
if tt.printAST {
repr.Println(ast)
}
// test re-stringification
restring := ast.String()
require.Equal(t, tt.query, restring)
})
}
}