aboutsummaryrefslogtreecommitdiffstats
path: root/library/go/core/metrics/prometheus/timer_test.go
blob: a520b6f47707545463c693c68f115fcbf667a376 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package prometheus

import (
	"testing"
	"time"

	"github.com/prometheus/client_golang/prometheus"
	dto "github.com/prometheus/client_model/go"
	"github.com/stretchr/testify/assert"
)

func TestTimer_RecordDuration(t *testing.T) {
	g := &Timer{gg: prometheus.NewGauge(prometheus.GaugeOpts{
		Name: "test_timer_record_duration",
	})}

	g.RecordDuration(42 * time.Second)

	var res dto.Metric
	err := g.gg.Write(&res)

	assert.NoError(t, err)
	assert.Equal(t, float64(42), res.GetGauge().GetValue())
}