package proxmox import ( "encoding/json" "testing" ) func TestPveClusterStatusGetClusterModeNumeric(t *testing.T) { tests := []struct { name string status PveClusterStatus want float64 }{ { name: "cluster mode", status: PveClusterStatus{Type: "cluster"}, want: 1, }, { name: "standalone node", status: PveClusterStatus{}, want: 0, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := tt.status.GetClusterModeNumeric(); got != tt.want { t.Fatalf("GetClusterModeNumeric() = %v, want %v", got, tt.want) } }) } } func TestPveSubscriptionGetStatusNumeric(t *testing.T) { tests := []struct { status string want float64 }{ {status: "notfound", want: 0}, {status: "active", want: 1}, {status: "expired", want: 2}, {status: "invalid", want: 2}, {status: "suspended", want: 2}, {status: "new", want: 2}, {status: "unknown", want: 2}, } for _, tt := range tests { t.Run(tt.status, func(t *testing.T) { subscription := PveSubscription{Status: tt.status} if got := subscription.GetStatusNumeric(); got != tt.want { t.Fatalf("GetStatusNumeric() = %v, want %v", got, tt.want) } }) } } func TestPveZfsPoolStatusUnmarshal(t *testing.T) { payload := []byte(`{ "errors": "No known data errors", "state": "ONLINE", "leaf": 0, "name": "hdd", "children": [ { "name": "hdd", "state": "ONLINE", "read": 0, "write": 0, "cksum": 0, "children": [ { "name": "/dev/disk/by-id/disk-1-part1", "state": "ONLINE", "leaf": 1, "read": 0, "write": 0, "cksum": 0 } ] }, { "name": "cache", "leaf": 0 } ] }`) var status PveZfsPoolStatus if err := json.Unmarshal(payload, &status); err != nil { t.Fatalf("unable to unmarshal ZFS pool status: %v", err) } if status.Name != "hdd" || status.State != "ONLINE" || status.Errors != "No known data errors" { t.Fatalf("unexpected pool status: %+v", status) } if len(status.Children) != 2 || len(status.Children[0].Children) != 1 { t.Fatalf("unexpected ZFS topology: %+v", status.Children) } leaf := status.Children[0].Children[0] if leaf.Leaf != 1 || leaf.Read == nil || leaf.Write == nil || leaf.Checksum == nil { t.Fatal("leaf component is missing its type or error counters") } if *leaf.Read != 0 || *leaf.Write != 0 || *leaf.Checksum != 0 { t.Fatalf("unexpected leaf error counters: read=%d write=%d checksum=%d", *leaf.Read, *leaf.Write, *leaf.Checksum) } cache := status.Children[1] if cache.Read != nil || cache.Write != nil || cache.Checksum != nil { t.Fatal("missing cache counters must stay absent instead of becoming zero metrics") } }