Skip to content

Commit

Permalink
Update Fake to support listing all rules
Browse files Browse the repository at this point in the history
  • Loading branch information
caseydavenport committed Jun 18, 2024
1 parent 57f949e commit 3f3f796
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3f3f796

Please sign in to comment.