summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/prometheus/client_golang/prometheus/gauge_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/prometheus/client_golang/prometheus/gauge_test.go')
-rw-r--r--vendor/github.com/prometheus/client_golang/prometheus/gauge_test.go24
1 files changed, 22 insertions, 2 deletions
diff --git a/vendor/github.com/prometheus/client_golang/prometheus/gauge_test.go b/vendor/github.com/prometheus/client_golang/prometheus/gauge_test.go
index 48cab4636..a2e3c1416 100644
--- a/vendor/github.com/prometheus/client_golang/prometheus/gauge_test.go
+++ b/vendor/github.com/prometheus/client_golang/prometheus/gauge_test.go
@@ -19,6 +19,7 @@ import (
"sync"
"testing"
"testing/quick"
+ "time"
dto "github.com/prometheus/client_model/go"
)
@@ -82,7 +83,7 @@ func TestGaugeConcurrency(t *testing.T) {
}
start.Done()
- if expected, got := <-result, math.Float64frombits(gge.(*value).valBits); math.Abs(expected-got) > 0.000001 {
+ if expected, got := <-result, math.Float64frombits(gge.(*gauge).valBits); math.Abs(expected-got) > 0.000001 {
t.Fatalf("expected approx. %f, got %f", expected, got)
return false
}
@@ -146,7 +147,7 @@ func TestGaugeVecConcurrency(t *testing.T) {
start.Done()
for i := range sStreams {
- if expected, got := <-results[i], math.Float64frombits(gge.WithLabelValues(string('A'+i)).(*value).valBits); math.Abs(expected-got) > 0.000001 {
+ if expected, got := <-results[i], math.Float64frombits(gge.WithLabelValues(string('A'+i)).(*gauge).valBits); math.Abs(expected-got) > 0.000001 {
t.Fatalf("expected approx. %f, got %f", expected, got)
return false
}
@@ -180,3 +181,22 @@ func TestGaugeFunc(t *testing.T) {
t.Errorf("expected %q, got %q", expected, got)
}
}
+
+func TestGaugeSetCurrentTime(t *testing.T) {
+ g := NewGauge(GaugeOpts{
+ Name: "test_name",
+ Help: "test help",
+ })
+ g.SetToCurrentTime()
+ unixTime := float64(time.Now().Unix())
+
+ m := &dto.Metric{}
+ g.Write(m)
+
+ delta := unixTime - m.GetGauge().GetValue()
+ // This is just a smoke test to make sure SetToCurrentTime is not
+ // totally off. Tests with current time involved are hard...
+ if math.Abs(delta) > 5 {
+ t.Errorf("Gauge set to current time deviates from current time by more than 5s, delta is %f seconds", delta)
+ }
+}