35 lines
746 B
Go
35 lines
746 B
Go
package metrics
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
)
|
|
|
|
func TestMetricsExposeRegistered(t *testing.T) {
|
|
m := New()
|
|
m.CheckRuns.WithLabelValues("c1", "ok").Inc()
|
|
m.SpoolDepth.Set(7)
|
|
srv := httptest.NewServer(promhttp.HandlerFor(m.Registry, promhttp.HandlerOpts{}))
|
|
defer srv.Close()
|
|
resp, err := http.Get(srv.URL)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer resp.Body.Close()
|
|
body, _ := io.ReadAll(resp.Body)
|
|
s := string(body)
|
|
for _, want := range []string{
|
|
`monlet_agent_check_runs_total{check_id="c1",status="ok"} 1`,
|
|
`monlet_agent_spool_events 7`,
|
|
} {
|
|
if !strings.Contains(s, want) {
|
|
t.Errorf("missing %q in output", want)
|
|
}
|
|
}
|
|
}
|