(t *testing.T)
| 290 | } |
| 291 | |
| 292 | func TestMetricNotFound(t *testing.T) { |
| 293 | const metadata = ` |
| 294 | # HELP some_other_metric A value that represents a counter. |
| 295 | # TYPE some_other_metric counter |
| 296 | ` |
| 297 | |
| 298 | c := prometheus.NewCounter(prometheus.CounterOpts{ |
| 299 | Name: "some_total", |
| 300 | Help: "A value that represents a counter.", |
| 301 | ConstLabels: prometheus.Labels{ |
| 302 | "label1": "value1", |
| 303 | }, |
| 304 | }) |
| 305 | |
| 306 | c.Inc() |
| 307 | |
| 308 | expected := ` |
| 309 | some_other_metric{label1="value1"} 1 |
| 310 | ` |
| 311 | |
| 312 | expectedError := `-# HELP some_total A value that represents a counter. |
| 313 | -# TYPE some_total counter |
| 314 | -some_total{label1="value1"} 1 |
| 315 | +# HELP some_other_metric A value that represents a counter. |
| 316 | +# TYPE some_other_metric counter |
| 317 | +some_other_metric{label1="value1"} 1 |
| 318 | ` |
| 319 | |
| 320 | err := CollectAndCompare(c, strings.NewReader(metadata+expected)) |
| 321 | if err == nil { |
| 322 | t.Error("Expected error, got no error.") |
| 323 | } |
| 324 | |
| 325 | if err.Error() != expectedError { |
| 326 | t.Errorf("Expected\n%#+v\nGot:\n%#+v", expectedError, err.Error()) |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | func TestScrapeAndCompare(t *testing.T) { |
| 331 | const expected = ` |
nothing calls this directly
no test coverage detected