MCPcopy
hub / github.com/prometheus/client_golang / TestMetricNotFound

Function TestMetricNotFound

prometheus/testutil/testutil_test.go:292–328  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

290}
291
292func 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
330func TestScrapeAndCompare(t *testing.T) {
331 const expected = `

Callers

nothing calls this directly

Calls 4

IncMethod · 0.95
NewCounterFunction · 0.92
CollectAndCompareFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected