MCPcopy Create free account
hub / github.com/prometheus/common / TestAlertValidate

Function TestAlertValidate

model/alert_test.go:24–125  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

22)
23
24func TestAlertValidate(t *testing.T) {
25 oldScheme := NameValidationScheme
26 NameValidationScheme = LegacyValidation
27 defer func() {
28 NameValidationScheme = oldScheme
29 }()
30 ts := time.Now()
31
32 cases := []struct {
33 alert *Alert
34 err string
35 }{
36 {
37 alert: &Alert{
38 Labels: LabelSet{"a": "b"},
39 StartsAt: ts,
40 },
41 },
42 {
43 alert: &Alert{
44 Labels: LabelSet{"a": "b"},
45 },
46 err: "start time missing",
47 },
48 {
49 alert: &Alert{
50 Labels: LabelSet{"a": "b"},
51 StartsAt: ts,
52 EndsAt: ts,
53 },
54 },
55 {
56 alert: &Alert{
57 Labels: LabelSet{"a": "b"},
58 StartsAt: ts,
59 EndsAt: ts.Add(1 * time.Minute),
60 },
61 },
62 {
63 alert: &Alert{
64 Labels: LabelSet{"a": "b"},
65 StartsAt: ts,
66 EndsAt: ts.Add(-1 * time.Minute),
67 },
68 err: "start time must be before end time",
69 },
70 {
71 alert: &Alert{
72 StartsAt: ts,
73 },
74 err: "at least one label pair required",
75 },
76 {
77 alert: &Alert{
78 Labels: LabelSet{"a": "b", "!bad": "label"},
79 StartsAt: ts,
80 },
81 err: "invalid label set: invalid name",

Callers

nothing calls this directly

Calls 3

AddMethod · 0.80
ErrorMethod · 0.80
ValidateMethod · 0.45

Tested by

no test coverage detected