aboutsummaryrefslogtreecommitdiffstats
path: root/library/go/core/metrics/prometheus/gauge_test.go
blob: aebb7586c17e09c5d1b645f741a2b33fac2408c0 (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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package prometheus

import (
	"testing"

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

func TestGauge_Add(t *testing.T) {
	g := &Gauge{gg: prometheus.NewGauge(prometheus.GaugeOpts{
		Name: "test_gauge_add",
	})}

	var expectValue float64 = 42
	g.Add(expectValue)

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

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

func TestGauge_Set(t *testing.T) {
	g := &Gauge{gg: prometheus.NewGauge(prometheus.GaugeOpts{
		Name: "test_gauge_set",
	})}

	var expectValue float64 = 42
	g.Set(expectValue)

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

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