mirror of
https://github.com/therootcompany/golib.git
synced 2026-11-04 06:55:00 +00:00
fix(ippolicy): clear to empty evaluator
This commit is contained in:
parent
4b8425c1ac
commit
04aaadff75
@ -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
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user