...
1 package expvar
2
3 import (
4 "strconv"
5 "testing"
6
7 "github.com/go-kit/kit/metrics/teststat"
8 )
9
10 func TestCounter(t *testing.T) {
11 counter := NewCounter("expvar_counter").With("label values", "not supported").(*Counter)
12 value := func() float64 { f, _ := strconv.ParseFloat(counter.f.String(), 64); return f }
13 if err := teststat.TestCounter(counter, value); err != nil {
14 t.Fatal(err)
15 }
16 }
17
18 func TestGauge(t *testing.T) {
19 gauge := NewGauge("expvar_gauge").With("label values", "not supported").(*Gauge)
20 value := func() []float64 { f, _ := strconv.ParseFloat(gauge.f.String(), 64); return []float64{f} }
21 if err := teststat.TestGauge(gauge, value); err != nil {
22 t.Fatal(err)
23 }
24 }
25
26 func TestHistogram(t *testing.T) {
27 histogram := NewHistogram("expvar_histogram", 50).With("label values", "not supported").(*Histogram)
28 quantiles := func() (float64, float64, float64, float64) {
29 p50, _ := strconv.ParseFloat(histogram.p50.String(), 64)
30 p90, _ := strconv.ParseFloat(histogram.p90.String(), 64)
31 p95, _ := strconv.ParseFloat(histogram.p95.String(), 64)
32 p99, _ := strconv.ParseFloat(histogram.p99.String(), 64)
33 return p50, p90, p95, p99
34 }
35 if err := teststat.TestHistogram(histogram, quantiles, 0.01); err != nil {
36 t.Fatal(err)
37 }
38 }
39
View as plain text