Debian Codegraph @

cmd/promtool/unittest_test.go

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 // Copyright 2018 The Prometheus Authors
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13
14 package main
15
16 import (
17 "testing"
18
19 "github.com/stretchr/testify/require"
20
21 "github.com/prometheus/prometheus/promql/promqltest"
•22 "github.com/prometheus/prometheus/util/testutil"
23 )
24
25 func TestRulesUnitTest(t *testing.T) {
•26 testutil.Skip32bit(t)
27 type args struct {
28 files []string
29 }
30 tests := []struct {
31 name string
32 args args
33 queryOpts promqltest.LazyLoaderOpts
34 want int
35 }{
36 {
37 name: "Passing Unit Tests",
38 args: args{
39 files: []string{"./testdata/unittest.yml"},
40 },
41 want: 0,
42 },
43 {
44 name: "Long evaluation interval",
45 args: args{
46 files: []string{"./testdata/long-period.yml"},
47 },
48 want: 0,
49 },
50 {
51 name: "Bad input series",
52 args: args{
53 files: []string{"./testdata/bad-input-series.yml"},
54 },
55 want: 1,
56 },
57 {
58 name: "Bad PromQL",
59 args: args{
60 files: []string{"./testdata/bad-promql.yml"},
61 },
62 want: 1,
63 },
64 {
65 name: "Bad rules (syntax error)",
66 args: args{
67 files: []string{"./testdata/bad-rules-syntax-test.yml"},
68 },
69 want: 1,
70 },
71 {
72 name: "Bad rules (error evaluating)",
73 args: args{
74 files: []string{"./testdata/bad-rules-error-test.yml"},
75 },
76 want: 1,
77 },
78 {
79 name: "Simple failing test",
80 args: args{
81 files: []string{"./testdata/failing.yml"},
82 },
83 want: 1,
84 },
85 {
86 name: "Disabled feature (@ modifier)",
87 args: args{
88 files: []string{"./testdata/at-modifier-test.yml"},
89 },
90 want: 1,
91 },
92 {
93 name: "Enabled feature (@ modifier)",
94 args: args{
95 files: []string{"./testdata/at-modifier-test.yml"},
96 },
97 queryOpts: promqltest.LazyLoaderOpts{
98 EnableAtModifier: true,
99 },
100 want: 0,
101 },
102 {
103 name: "Disabled feature (negative offset)",
104 args: args{
105 files: []string{"./testdata/negative-offset-test.yml"},
106 },
107 want: 1,
108 },
109 {
110 name: "Enabled feature (negative offset)",
111 args: args{
112 files: []string{"./testdata/negative-offset-test.yml"},
113 },
114 queryOpts: promqltest.LazyLoaderOpts{
115 EnableNegativeOffset: true,
116 },
117 want: 0,
118 },
119 {
120 name: "No test group interval",
121 args: args{
122 files: []string{"./testdata/no-test-group-interval.yml"},
123 },
124 queryOpts: promqltest.LazyLoaderOpts{
125 EnableNegativeOffset: true,
126 },
127 want: 0,
128 },
129 }
130 for _, tt := range tests {
131 t.Run(tt.name, func(t *testing.T) {
132 if got := RulesUnitTest(tt.queryOpts, nil, false, tt.args.files...); got != tt.want {
133 t.Errorf("RulesUnitTest() = %v, want %v", got, tt.want)
134 }
135 })
136 }
137 }
138
139 func TestRulesUnitTestRun(t *testing.T) {
•140 testutil.Skip32bit(t)
141 type args struct {
142 run []string
143 files []string
144 }
145 tests := []struct {
146 name string
147 args args
148 queryOpts promqltest.LazyLoaderOpts
149 want int
150 }{
151 {
152 name: "Test all without run arg",
153 args: args{
154 run: nil,
155 files: []string{"./testdata/rules_run.yml"},
156 },
157 want: 1,
158 },
159 {
160 name: "Test all with run arg",
161 args: args{
162 run: []string{"correct", "wrong"},
163 files: []string{"./testdata/rules_run.yml"},
164 },
165 want: 1,
166 },
167 {
168 name: "Test correct",
169 args: args{
170 run: []string{"correct"},
171 files: []string{"./testdata/rules_run.yml"},
172 },
173 want: 0,
174 },
175 {
176 name: "Test wrong",
177 args: args{
178 run: []string{"wrong"},
179 files: []string{"./testdata/rules_run.yml"},
180 },
181 want: 1,
182 },
183 }
184 for _, tt := range tests {
185 t.Run(tt.name, func(t *testing.T) {
186 got := RulesUnitTest(tt.queryOpts, tt.args.run, false, tt.args.files...)
187 require.Equal(t, tt.want, got)
188 })
189 }
190 }