From 3f3f79670bafe47f6ec9e7d3c4b2e388d5a97cc9 Mon Sep 17 00:00:00 2001 From: Casey Davenport Date: Fri, 10 May 2024 10:49:11 -0700 Subject: [PATCH] Update Fake to support listing all rules --- fake.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/fake.go b/fake.go index 694c970..6849b7e 100644 --- a/fake.go +++ b/fake.go @@ -120,13 +120,23 @@ func (fake *Fake) List(_ context.Context, objectType string) ([]string, error) { // ListRules is part of Interface func (fake *Fake) ListRules(_ context.Context, chain string) ([]*Rule, error) { if fake.Table == nil { - return nil, notFoundError("no such chain %q", chain) + return nil, notFoundError("no such table %q", fake.table) } - ch := fake.Table.Chains[chain] - if ch == nil { - return nil, notFoundError("no such chain %q", chain) + + rules := []*Rule{} + if chain == "" { + // Include all rules across all chains. + for _, ch := range fake.Table.Chains { + rules = append(rules, ch.Rules...) + } + } else { + ch := fake.Table.Chains[chain] + if ch == nil { + return nil, notFoundError("no such chain %q", chain) + } + rules = append(rules, ch.Rules...) } - return ch.Rules, nil + return rules, nil } // ListElements is part of Interface