fix(ippolicy): clear to empty evaluator

This commit is contained in:
AJ ONeal 2026-09-10 02:35:57 -06:00
parent 4b8425c1ac
commit 04aaadff75
No known key found for this signature in database
2 changed files with 14 additions and 1 deletions

View File

@ -213,7 +213,7 @@ func (p *Policy) Set(e *Evaluator) error {
}
func (p *Policy) Clear() error {
p.current.Store(nil)
p.current.Store(&Evaluator{})
p.loadedAt.Store(nil)
return nil
}

View File

@ -27,6 +27,19 @@ func TestEnumStrings(t *testing.T) {
}
}
func TestPolicyClearPublishesEmptyEvaluator(t *testing.T) {
p := New(t.Context(), Config{})
if err := p.Clear(); err != nil {
t.Fatal(err)
}
if evaluator := p.Current(); evaluator == nil {
t.Fatal("Clear published nil evaluator")
}
if got := p.Current().Evaluate(netip.MustParseAddr("192.0.2.1")); got != Unlisted {
t.Fatalf("empty evaluator decision = %s, want %s", got, Unlisted)
}
}
func TestPolicyKeepsSnapshotAfterFailedRefresh(t *testing.T) {
path := filepath.Join(t.TempDir(), "allowed.tsv")
if err := os.WriteFile(path, []byte("192.0.2.1\n"), 0o600); err != nil {