2024-08-01 11:00:36 +00:00
|
|
|
// Copyright (c) Tailscale Inc & AUTHORS
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
|
|
|
|
package usermetric
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGauge(t *testing.T) {
|
2024-09-23 16:34:00 +00:00
|
|
|
var reg Registry
|
|
|
|
g := reg.NewGauge("test_gauge", "This is a test gauge")
|
2024-08-01 11:00:36 +00:00
|
|
|
g.Set(15)
|
|
|
|
|
|
|
|
var buf bytes.Buffer
|
|
|
|
g.WritePrometheus(&buf, "test_gauge")
|
|
|
|
const want = `# TYPE test_gauge gauge
|
|
|
|
# HELP test_gauge This is a test gauge
|
|
|
|
test_gauge 15
|
|
|
|
`
|
|
|
|
if got := buf.String(); got != want {
|
|
|
|
t.Errorf("got %q; want %q", got, want)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|