From 8d21ab2d99d9df839dcd618c5a3e1370315bab5a Mon Sep 17 00:00:00 2001 From: Anton Nikiforov Date: Fri, 26 Jan 2024 17:25:59 +0300 Subject: [PATCH] [#43] engine: Extend with target listing method Signed-off-by: Anton Nikiforov --- pkg/engine/inmemory/local_storage.go | 11 +++++++++++ pkg/engine/inmemory/local_storage_test.go | 3 +++ pkg/engine/interface.go | 2 ++ 3 files changed, 16 insertions(+) diff --git a/pkg/engine/inmemory/local_storage.go b/pkg/engine/inmemory/local_storage.go index 30553bd..0324df2 100644 --- a/pkg/engine/inmemory/local_storage.go +++ b/pkg/engine/inmemory/local_storage.go @@ -136,3 +136,14 @@ func (s *inmemoryLocalStorage) DropAllOverrides(name chain.Name) error { s.nameToResourceChains[name] = make(targetToChain) return nil } + +func (s *inmemoryLocalStorage) ListOverrideDefinedTargets(name chain.Name) ([]engine.Target, error) { + s.guard.RLock() + defer s.guard.RUnlock() + ttc := s.nameToResourceChains[name] + var keys []engine.Target + for k := range ttc { + keys = append(keys, k) + } + return keys, nil +} diff --git a/pkg/engine/inmemory/local_storage_test.go b/pkg/engine/inmemory/local_storage_test.go index 5c37879..c6ad0c9 100644 --- a/pkg/engine/inmemory/local_storage_test.go +++ b/pkg/engine/inmemory/local_storage_test.go @@ -184,6 +184,9 @@ func TestListOverrides(t *testing.T) { inmem.AddOverride(chain.Ingress, resrc, addChain) l, _ := inmem.ListOverrides(chain.Ingress, resrc) require.Len(t, l, 1) + targets, err := inmem.ListOverrideDefinedTargets(chain.Ingress) + require.NoError(t, err) + require.Equal(t, []engine.Target{resrc}, targets) }) t.Run("list after drop", func(t *testing.T) { diff --git a/pkg/engine/interface.go b/pkg/engine/interface.go index 8d11466..e6290c8 100644 --- a/pkg/engine/interface.go +++ b/pkg/engine/interface.go @@ -24,6 +24,8 @@ type LocalOverrideStorage interface { ListOverrides(name chain.Name, target Target) ([]*chain.Chain, error) DropAllOverrides(name chain.Name) error + + ListOverrideDefinedTargets(name chain.Name) ([]Target, error) } type TargetType rune