Debian Codegraph @

gauge_float64_test.go

raw
1 package metrics
2
3 import "testing"
4
5 func BenchmarkGuageFloat64(b *testing.B) {
6 g := NewGaugeFloat64()
7 b.ResetTimer()
8 for i := 0; i < b.N; i++ {
9 g.Update(float64(i))
10 }
11 }
12
13 func TestGaugeFloat64(t *testing.T) {
14 g := NewGaugeFloat64()
15 g.Update(float64(47.0))
16 if v := g.Value(); float64(47.0) != v {
17 t.Errorf("g.Value(): 47.0 != %v\n", v)
18 }
19 }
20
21 func TestGaugeFloat64Snapshot(t *testing.T) {
22 g := NewGaugeFloat64()
23 g.Update(float64(47.0))
24 snapshot := g.Snapshot()
25 g.Update(float64(0))
26 if v := snapshot.Value(); float64(47.0) != v {
27 t.Errorf("g.Value(): 47.0 != %v\n", v)
28 }
29 }
30
31 func TestGetOrRegisterGaugeFloat64(t *testing.T) {
32 r := NewRegistry()
33 NewRegisteredGaugeFloat64("foo", r).Update(float64(47.0))
34 t.Logf("registry: %v", r)
35 if g := GetOrRegisterGaugeFloat64("foo", r); float64(47.0) != g.Value() {
36 t.Fatal(g)
37 }
38 }
39
40 func TestFunctionalGaugeFloat64(t *testing.T) {
41 var counter float64
42 fg := NewFunctionalGaugeFloat64(func() float64 {
43 counter++
44 return counter
45 })
46 fg.Value()
47 fg.Value()
48 if counter != 2 {
49 t.Error("counter != 2")
50 }
51 }
52
53 func TestGetOrRegisterFunctionalGaugeFloat64(t *testing.T) {
54 r := NewRegistry()
55 NewRegisteredFunctionalGaugeFloat64("foo", r, func() float64 { return 47 })
56 if g := GetOrRegisterGaugeFloat64("foo", r); 47 != g.Value() {
57 t.Fatal(g)
58 }
59 }