Files
2026-11-01 14:34:23 -05:00

62 lines
1.9 KiB
Go

package bot
import (
"strings"
"testing"
"slackerbot/internal/balance"
"slackerbot/internal/testutil/clustertest"
)
func TestVersionWarning(t *testing.T) {
views := func(versions ...string) []balance.NodeView {
names := []string{"master", "a", "b"}
var out []balance.NodeView
for i, v := range versions {
out = append(out, balance.NodeView{Name: names[i], Version: v})
}
return out
}
if got := versionWarning("master", views("v1", "v1", "v1")); got != "" {
t.Fatalf("matching versions should not warn: %q", got)
}
if got := versionWarning("master", views("v1")); got != "" {
t.Fatalf("a lone master should not warn: %q", got)
}
got := versionWarning("master", views("v1", "v2", "v1"))
if !strings.Contains(got, "Version mismatch") || !strings.Contains(got, "a runs `v2`") || strings.Contains(got, "b runs") {
t.Fatalf("only the odd node should be named: %q", got)
}
got = versionWarning("master", views("v1", ""))
if !strings.Contains(got, "a runs an older version that doesn't report one") {
t.Fatalf("a slave reporting no version is a mismatch: %q", got)
}
}
func TestVersionMismatchShownInNodesAndHelp(t *testing.T) {
c := clustertest.New(t)
b := &Bot{cfg: c.Cfg, store: c.Store, mgr: c.Mgr}
if got := b.nodesList(c.Ctx, "C1"); strings.Contains(got, "Version mismatch") {
t.Fatalf("unexpected warning when no node reports a version: %s", got)
}
c.Master.Mu.Lock()
c.Master.Version = "2026.11.01-abc"
c.Master.Mu.Unlock()
got := b.nodesList(c.Ctx, "C1")
if !strings.Contains(got, "Version mismatch") || !strings.Contains(got, "slave-1 runs an older version") {
t.Fatalf("nodes should flag the mismatch: %s", got)
}
if !strings.Contains(got, ":warning: version") {
t.Fatalf("the odd node's line should be flagged: %s", got)
}
if help := b.versionWarning(c.Ctx); !strings.Contains(help, "Version mismatch") {
t.Fatalf("help should flag the mismatch: %s", help)
}
}