Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package collector
|
|
|
|
import (
|
|
"log/slog"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"github.com/prometheus/client_golang/prometheus/testutil"
|
|
)
|
|
|
|
func TestNodeConfigCollector(t *testing.T) {
|
|
client := newTestClient(t, map[string]string{
|
|
"/nodes/node01/qemu": "node_qemu.json",
|
|
"/nodes/node01/qemu/100/config": "node_qemu_config_100.json",
|
|
"/nodes/node01/qemu/101/config": "node_qemu_config_101.json",
|
|
"/nodes/node01/lxc": "node_lxc.json",
|
|
})
|
|
|
|
collector := newNodeConfigCollector(slog.Default())
|
|
collector.SetNodes([]string{"node01"})
|
|
adapter := &testCollectorAdapter{client: client, collector: collector}
|
|
|
|
reg := prometheus.NewRegistry()
|
|
reg.MustRegister(adapter)
|
|
|
|
expected := `
|
|
# HELP pve_onboot_status Whether a guest is configured to start on boot.
|
|
# TYPE pve_onboot_status gauge
|
|
pve_onboot_status{id="qemu/100",node="node01",type="qemu"} 1
|
|
pve_onboot_status{id="qemu/101",node="node01",type="qemu"} 0
|
|
`
|
|
|
|
if err := testutil.GatherAndCompare(reg, strings.NewReader(expected),
|
|
"pve_onboot_status",
|
|
); err != nil {
|
|
t.Errorf("unexpected metrics: %s", err)
|
|
}
|
|
}
|