test startup intent guard helpers
This commit is contained in:
parent
1935c5eb3f
commit
ad4361322d
@ -5,8 +5,10 @@ import (
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"scm.bstein.dev/bstein/hecate/internal/config"
|
||||
"scm.bstein.dev/bstein/hecate/internal/state"
|
||||
)
|
||||
|
||||
func TestParseVaultSealed(t *testing.T) {
|
||||
@ -82,3 +84,36 @@ func TestFallbackWorkersFromInventoryFallsBackToHosts(t *testing.T) {
|
||||
t.Fatalf("fallback workers mismatch: got=%v want=%v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIntentFreshTreatsZeroTimestampAsFresh(t *testing.T) {
|
||||
if !intentFresh(state.Intent{}, 30*time.Second) {
|
||||
t.Fatalf("zero updated_at intent should be treated as fresh")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIntentFreshRespectsAge(t *testing.T) {
|
||||
stale := state.Intent{UpdatedAt: time.Now().Add(-2 * time.Minute)}
|
||||
fresh := state.Intent{UpdatedAt: time.Now().Add(-20 * time.Second)}
|
||||
if intentFresh(stale, 30*time.Second) {
|
||||
t.Fatalf("expected stale intent to be considered not fresh")
|
||||
}
|
||||
if !intentFresh(fresh, 30*time.Second) {
|
||||
t.Fatalf("expected recent intent to be considered fresh")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCoordinationPeersDedupesAndIncludesForwardHost(t *testing.T) {
|
||||
orch := &Orchestrator{
|
||||
cfg: config.Config{
|
||||
Coordination: config.Coordination{
|
||||
PeerHosts: []string{"titan-24", "titan-db", "titan-24", " "},
|
||||
ForwardShutdownHost: "titan-db",
|
||||
},
|
||||
},
|
||||
}
|
||||
got := orch.coordinationPeers()
|
||||
want := []string{"titan-24", "titan-db"}
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("coordination peers mismatch: got=%v want=%v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user