Add HostConfig + Cluster fields to models and update docs

This commit is contained in:
Rongsong Shen 2026-04-16 09:24:22 +00:00
parent 960ef62342
commit 00c4472d6c
9 changed files with 1805 additions and 9 deletions

View file

@ -0,0 +1,61 @@
package models
import "testing"
func TestHostStateStr(t *testing.T) {
tests := []struct {
name string
state int
want string
}{
{
name: "zero value returns UNKNOWN when no worker has reported",
state: 0,
want: "UNKNOWN",
},
{
name: "UNAVAIL flag",
state: HOSTSTAT["UNAVAIL"],
want: "UNAVAIL",
},
{
name: "CLOSED flag",
state: HOSTSTAT["CLOSED"],
want: "CLOSED",
},
{
name: "BUSY flag",
state: HOSTSTAT["BUSY"],
want: "BUSY",
},
{
name: "LOCKEDU flag",
state: HOSTSTAT["LOCKEDU"],
want: "LOCKU",
},
{
name: "LOCKEDW flag",
state: HOSTSTAT["LOCKEDW"],
want: "LOCKW",
},
{
name: "no flags set returns OK for real host status",
state: 0x00000001, // some non-zero, non-flag value
want: "OK",
},
{
name: "combined UNAVAIL+CLOSED flags",
state: HOSTSTAT["UNAVAIL"] | HOSTSTAT["CLOSED"],
want: "UNAVAIL", // UNAVAIL takes priority
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := HostStateStr(tt.state)
if got != tt.want {
t.Errorf("HostStateStr(%d) = %q, want %q", tt.state, got, tt.want)
}
})
}
}