pve-exporter/collector/corosync_test.go
2026-03-20 11:32:00 +00:00

48 lines
1.5 KiB
Go

package collector
import (
"log/slog"
"strings"
"testing"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/testutil"
)
func TestCorosyncCollector(t *testing.T) {
client := newTestClient(t, map[string]string{
"/cluster/status": "cluster_status.json",
"/cluster/config/nodes": "cluster_config_nodes.json",
})
collector := newCorosyncCollector(slog.Default())
adapter := &testCollectorAdapter{client: client, collector: collector}
reg := prometheus.NewRegistry()
reg.MustRegister(adapter)
expected := `
# HELP pve_cluster_expected_votes Total expected votes in the cluster.
# TYPE pve_cluster_expected_votes gauge
pve_cluster_expected_votes 5
# HELP pve_cluster_nodes_total Total number of nodes in the cluster.
# TYPE pve_cluster_nodes_total gauge
pve_cluster_nodes_total 5
# HELP pve_cluster_quorate Whether the cluster is quorate.
# TYPE pve_cluster_quorate gauge
pve_cluster_quorate 1
# HELP pve_node_online Whether a node is online.
# TYPE pve_node_online gauge
pve_node_online{name="node01",nodeid="1"} 1
pve_node_online{name="node02",nodeid="2"} 1
pve_node_online{name="node03",nodeid="3"} 1
pve_node_online{name="node04",nodeid="4"} 1
pve_node_online{name="node05",nodeid="5"} 1
`
if err := testutil.GatherAndCompare(reg, strings.NewReader(expected),
"pve_cluster_quorate", "pve_cluster_nodes_total", "pve_cluster_expected_votes", "pve_node_online",
); err != nil {
t.Errorf("unexpected metrics: %s", err)
}
}