(t *testing.T)
| 125 | } |
| 126 | |
| 127 | func TestAlert(t *testing.T) { |
| 128 | // Verifying that an alert with no EndsAt field is unresolved and has firing status. |
| 129 | alert := &Alert{ |
| 130 | Labels: LabelSet{"foo": "bar", "lorem": "ipsum"}, |
| 131 | StartsAt: time.Now(), |
| 132 | } |
| 133 | |
| 134 | actual := fmt.Sprint(alert) |
| 135 | expected := "[d181d0f][active]" |
| 136 | |
| 137 | if actual != expected { |
| 138 | t.Errorf("expected %s, but got %s", expected, actual) |
| 139 | } |
| 140 | |
| 141 | actualStatus := alert.Status() |
| 142 | expectedStatus := AlertStatus("firing") |
| 143 | |
| 144 | if actualStatus != expectedStatus { |
| 145 | t.Errorf("expected alertStatus %s, but got %s", expectedStatus, actualStatus) |
| 146 | } |
| 147 | |
| 148 | // Verifying that an alert with an EndsAt time before the current time is resolved and has resolved status. |
| 149 | ts := time.Now() |
| 150 | ts1 := ts.Add(-2 * time.Minute) |
| 151 | ts2 := ts.Add(-1 * time.Minute) |
| 152 | alert = &Alert{ |
| 153 | Labels: LabelSet{"foo": "bar", "lorem": "ipsum"}, |
| 154 | StartsAt: ts1, |
| 155 | EndsAt: ts2, |
| 156 | } |
| 157 | |
| 158 | if !alert.Resolved() { |
| 159 | t.Error("expected alert to be resolved, but it was not") |
| 160 | } |
| 161 | |
| 162 | actual = fmt.Sprint(alert) |
| 163 | expected = "[d181d0f][resolved]" |
| 164 | |
| 165 | if actual != expected { |
| 166 | t.Errorf("expected %s, but got %s", expected, actual) |
| 167 | } |
| 168 | |
| 169 | actualStatus = alert.Status() |
| 170 | expectedStatus = "resolved" |
| 171 | |
| 172 | if actualStatus != expectedStatus { |
| 173 | t.Errorf("expected alertStatus %s, but got %s", expectedStatus, actualStatus) |
| 174 | } |
| 175 | |
| 176 | // Verifying that ResolvedAt works for different times |
| 177 | if alert.ResolvedAt(ts1) { |
| 178 | t.Error("unexpected alert was resolved at start time") |
| 179 | } |
| 180 | if alert.ResolvedAt(ts2.Add(-time.Millisecond)) { |
| 181 | t.Error("unexpected alert was resolved before it ended") |
| 182 | } |
| 183 | if !alert.ResolvedAt(ts2) { |
| 184 | t.Error("expected alert to be resolved at end time") |
nothing calls this directly
no test coverage detected