示例#1
0
func TestPrometheusGeneratesMetrics(t *testing.T) {
	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintln(w, sampleTextFormat)
	}))
	defer ts.Close()

	p := &Prometheus{
		Urls: []string{ts.URL},
	}

	var acc testutil.Accumulator

	err := p.Gather(&acc)
	require.NoError(t, err)

	expected := []struct {
		name  string
		value float64
		tags  map[string]string
	}{
		{"go_gc_duration_seconds_count", 7, map[string]string{}},
		{"go_goroutines", 15, map[string]string{}},
	}

	for _, e := range expected {
		assert.NoError(t, acc.ValidateValue(e.name, e.value))
	}
}