2023-04-10 10:28:16 +00:00
|
|
|
// Copyright (c) Tailscale Inc & AUTHORS
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package promvarz
|
|
|
|
|
|
|
|
import (
|
|
|
|
"expvar"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
|
|
|
"github.com/prometheus/client_golang/prometheus/testutil"
|
|
|
|
)
|
|
|
|
|
2023-05-05 18:37:24 +00:00
|
|
|
var (
|
|
|
|
testVar1 = expvar.NewInt("gauge_promvarz_test_expvar")
|
|
|
|
testVar2 = promauto.NewGauge(prometheus.GaugeOpts{Name: "promvarz_test_native"})
|
|
|
|
)
|
|
|
|
|
2023-04-10 10:28:16 +00:00
|
|
|
func TestHandler(t *testing.T) {
|
2023-05-05 18:37:24 +00:00
|
|
|
testVar1.Set(42)
|
|
|
|
testVar2.Set(4242)
|
2023-04-10 10:28:16 +00:00
|
|
|
|
|
|
|
svr := httptest.NewServer(http.HandlerFunc(Handler))
|
|
|
|
defer svr.Close()
|
|
|
|
|
|
|
|
want := `
|
|
|
|
# TYPE promvarz_test_expvar gauge
|
|
|
|
promvarz_test_expvar 42
|
|
|
|
# TYPE promvarz_test_native gauge
|
|
|
|
promvarz_test_native 4242
|
|
|
|
`
|
|
|
|
if err := testutil.ScrapeAndCompare(svr.URL, strings.NewReader(want), "promvarz_test_expvar", "promvarz_test_native"); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|