Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
37 lines
1 KiB
Go
37 lines
1 KiB
Go
package collector
|
|
|
|
import (
|
|
"log/slog"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"github.com/prometheus/client_golang/prometheus/testutil"
|
|
)
|
|
|
|
func TestBackupCollector(t *testing.T) {
|
|
client := newTestClient(t, map[string]string{
|
|
"/cluster/backup-info/not-backed-up": "backup_not_backed_up.json",
|
|
})
|
|
|
|
collector := newBackupCollector(slog.Default())
|
|
adapter := &testCollectorAdapter{client: client, collector: collector}
|
|
|
|
reg := prometheus.NewRegistry()
|
|
reg.MustRegister(adapter)
|
|
|
|
expected := `
|
|
# HELP pve_not_backed_up_info Information about a guest that is not backed up.
|
|
# TYPE pve_not_backed_up_info gauge
|
|
pve_not_backed_up_info{id="qemu/100"} 1
|
|
# HELP pve_not_backed_up_total Whether a guest is not backed up (1 = not backed up).
|
|
# TYPE pve_not_backed_up_total gauge
|
|
pve_not_backed_up_total{id="qemu/100"} 1
|
|
`
|
|
|
|
if err := testutil.GatherAndCompare(reg, strings.NewReader(expected),
|
|
"pve_not_backed_up_total", "pve_not_backed_up_info",
|
|
); err != nil {
|
|
t.Errorf("unexpected metrics: %s", err)
|
|
}
|
|
}
|