Add optional name property to testgroup for better test failure output

Signed-off-by: misha <DL-OTTCloudPlatform-Nova@bskyb.internal>
pull/8440/head
misha 4 years ago
parent 67edfc6054
commit c2c5aeb16b

@ -1,6 +1,7 @@
tests: tests:
# Simple failing test. # Simple failing test.
- interval: 1m - interval: 1m
name: "Failing test"
input_series: input_series:
- series: test - series: test
values: '0' values: '0'

@ -146,6 +146,7 @@ type testGroup struct {
AlertRuleTests []alertTestCase `yaml:"alert_rule_test,omitempty"` AlertRuleTests []alertTestCase `yaml:"alert_rule_test,omitempty"`
PromqlExprTests []promqlTestCase `yaml:"promql_expr_test,omitempty"` PromqlExprTests []promqlTestCase `yaml:"promql_expr_test,omitempty"`
ExternalLabels labels.Labels `yaml:"external_labels,omitempty"` ExternalLabels labels.Labels `yaml:"external_labels,omitempty"`
TestGroupName string `yaml:"name,omitempty"`
} }
// test performs the unit tests. // test performs the unit tests.
@ -300,15 +301,25 @@ func (tg *testGroup) test(evalInterval time.Duration, groupOrderMap map[string]i
} }
if gotAlerts.Len() != expAlerts.Len() { if gotAlerts.Len() != expAlerts.Len() {
errs = append(errs, errors.Errorf(" alertname:%s, time:%s, \n exp:%#v, \n got:%#v", if tg.TestGroupName == "" {
testcase.Alertname, testcase.EvalTime.String(), expAlerts.String(), gotAlerts.String())) errs = append(errs, errors.Errorf(" alertname:%s, time:%s, \n exp:%#v, \n got:%#v",
testcase.Alertname, testcase.EvalTime.String(), expAlerts.String(), gotAlerts.String()))
} else {
errs = append(errs, errors.Errorf(" name: %s,\n alertname:%s, time:%s, \n exp:%#v, \n got:%#v",
tg.TestGroupName, testcase.Alertname, testcase.EvalTime.String(), expAlerts.String(), gotAlerts.String()))
}
} else { } else {
sort.Sort(gotAlerts) sort.Sort(gotAlerts)
sort.Sort(expAlerts) sort.Sort(expAlerts)
if !reflect.DeepEqual(expAlerts, gotAlerts) { if !reflect.DeepEqual(expAlerts, gotAlerts) {
errs = append(errs, errors.Errorf(" alertname:%s, time:%s, \n exp:%#v, \n got:%#v", if tg.TestGroupName == "" {
testcase.Alertname, testcase.EvalTime.String(), expAlerts.String(), gotAlerts.String())) errs = append(errs, errors.Errorf(" alertname:%s, time:%s, \n exp:%#v, \n got:%#v",
testcase.Alertname, testcase.EvalTime.String(), expAlerts.String(), gotAlerts.String()))
} else {
errs = append(errs, errors.Errorf(" name: %s,\n alertname:%s, time:%s, \n exp:%#v, \n got:%#v",
tg.TestGroupName, testcase.Alertname, testcase.EvalTime.String(), expAlerts.String(), gotAlerts.String()))
}
} }
} }
} }

Loading…
Cancel
Save