forked from TrueCloudLab/policy-engine
[#43] engine: Extend with target listing method
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
parent
0a28f0a992
commit
8d21ab2d99
3 changed files with 16 additions and 0 deletions
|
@ -136,3 +136,14 @@ func (s *inmemoryLocalStorage) DropAllOverrides(name chain.Name) error {
|
||||||
s.nameToResourceChains[name] = make(targetToChain)
|
s.nameToResourceChains[name] = make(targetToChain)
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -184,6 +184,9 @@ func TestListOverrides(t *testing.T) {
|
||||||
inmem.AddOverride(chain.Ingress, resrc, addChain)
|
inmem.AddOverride(chain.Ingress, resrc, addChain)
|
||||||
l, _ := inmem.ListOverrides(chain.Ingress, resrc)
|
l, _ := inmem.ListOverrides(chain.Ingress, resrc)
|
||||||
require.Len(t, l, 1)
|
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) {
|
t.Run("list after drop", func(t *testing.T) {
|
||||||
|
|
|
@ -24,6 +24,8 @@ type LocalOverrideStorage interface {
|
||||||
ListOverrides(name chain.Name, target Target) ([]*chain.Chain, error)
|
ListOverrides(name chain.Name, target Target) ([]*chain.Chain, error)
|
||||||
|
|
||||||
DropAllOverrides(name chain.Name) error
|
DropAllOverrides(name chain.Name) error
|
||||||
|
|
||||||
|
ListOverrideDefinedTargets(name chain.Name) ([]Target, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type TargetType rune
|
type TargetType rune
|
||||||
|
|
Loading…
Reference in a new issue