-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
85 lines (76 loc) · 1.81 KB
/
main_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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (C) 2017 Kazumasa Kohtaka <[email protected]> All right reserved
// This file is available under the MIT license.
package main_test
import (
"io/ioutil"
"testing"
"github.com/prometheus/common/log"
"github.com/prometheus/prometheus/promql"
"github.com/prometheus/prometheus/rules"
)
func TestAlertRules(t *testing.T) {
type testCase struct {
DataFile string
RulesFile string
// TODO: Add parameters to check an expected behaviour
}
tcs := []testCase{
testCase{
"./testdata/case_001.dat",
"./testdata/case_001.rules",
},
}
for _, tc := range tcs {
content, err := ioutil.ReadFile(tc.DataFile)
if err != nil {
t.Fatal(err)
}
suite, err := promql.NewTest(t, string(content))
for err != nil {
t.Fatal(err)
}
defer suite.Close()
if err := suite.Run(); err != nil {
t.Fatal(err)
}
alertRules := []rules.Rule{}
content, err = ioutil.ReadFile(tc.RulesFile)
if err != nil {
t.Fatal(err)
}
statements, err := promql.ParseStmts(string(content))
if err != nil {
t.Fatal(err)
}
for _, statement := range statements {
var rule rules.Rule
switch r := statement.(type) {
case *promql.AlertStmt:
rule = rules.NewAlertingRule(
r.Name,
r.Expr,
r.Duration,
r.Labels,
r.Annotations,
log.Base())
default:
t.Fatal("Invalid statement type")
}
alertRules = append(alertRules, rule)
}
// TODO: Check an expected behaviour
// for _, alertRule := range alertRules {
// evalTime := time.Unix(0, 0)
// samples, err := alertRule.Eval(suite.Context(), evalTime, suite.QueryEngine(), nil)
// if err != nil {
// t.Fatal(err)
// }
//
// fmt.Println(len(samples))
// for _, sample := range samples {
// fmt.Println(sample.Metric)
// fmt.Println(sample.Point.T, sample.Point.V)
// }
// }
}
}