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

Function TestAlertValidate

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

AddMethod · 0.80
ErrorMethod · 0.80
ValidateMethod · 0.45

Tested by

no test coverage detected