(t *testing.T)
| 23 | ) |
| 24 | |
| 25 | func TestTimerObserve(t *testing.T) { |
| 26 | var ( |
| 27 | his = NewHistogram(HistogramOpts{Name: "test_histogram"}) |
| 28 | sum = NewSummary(SummaryOpts{Name: "test_summary"}) |
| 29 | gauge = NewGauge(GaugeOpts{Name: "test_gauge"}) |
| 30 | ) |
| 31 | |
| 32 | func() { |
| 33 | hisTimer := NewTimer(his) |
| 34 | sumTimer := NewTimer(sum) |
| 35 | gaugeTimer := NewTimer(ObserverFunc(gauge.Set)) |
| 36 | defer hisTimer.ObserveDuration() |
| 37 | defer sumTimer.ObserveDuration() |
| 38 | defer gaugeTimer.ObserveDuration() |
| 39 | }() |
| 40 | |
| 41 | m := &dto.Metric{} |
| 42 | his.Write(m) |
| 43 | if want, got := uint64(1), m.GetHistogram().GetSampleCount(); want != got { |
| 44 | t.Errorf("want %d observations for histogram, got %d", want, got) |
| 45 | } |
| 46 | m.Reset() |
| 47 | sum.Write(m) |
| 48 | if want, got := uint64(1), m.GetSummary().GetSampleCount(); want != got { |
| 49 | t.Errorf("want %d observations for summary, got %d", want, got) |
| 50 | } |
| 51 | m.Reset() |
| 52 | gauge.Write(m) |
| 53 | if got := m.GetGauge().GetValue(); got <= 0 { |
| 54 | t.Errorf("want value > 0 for gauge, got %f", got) |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | func TestTimerObserveWithExemplar(t *testing.T) { |
| 59 | var ( |
nothing calls this directly
no test coverage detected