added store.RemoveAll() helper method
This commit is contained in:
parent
6749559a22
commit
d129959098
|
@ -13,6 +13,14 @@ func New[T any](data map[string]T) *Store[T] {
|
||||||
return &Store[T]{data: data}
|
return &Store[T]{data: data}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RemoveAll removes all the existing store entries.
|
||||||
|
func (s *Store[T]) RemoveAll() {
|
||||||
|
s.mux.Lock()
|
||||||
|
defer s.mux.Unlock()
|
||||||
|
|
||||||
|
s.data = make(map[string]T)
|
||||||
|
}
|
||||||
|
|
||||||
// Remove removes a single entry from the store.
|
// Remove removes a single entry from the store.
|
||||||
//
|
//
|
||||||
// Remove does nothing if key doesn't exist in the store.
|
// Remove does nothing if key doesn't exist in the store.
|
||||||
|
|
|
@ -14,6 +14,20 @@ func TestNew(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRemoveAll(t *testing.T) {
|
||||||
|
s := store.New(map[string]bool{"test1": true, "test2": true})
|
||||||
|
|
||||||
|
keys := []string{"test1", "test2"}
|
||||||
|
|
||||||
|
s.RemoveAll()
|
||||||
|
|
||||||
|
for i, key := range keys {
|
||||||
|
if s.Has(key) {
|
||||||
|
t.Errorf("(%d) Expected %q to be removed", i, key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestRemove(t *testing.T) {
|
func TestRemove(t *testing.T) {
|
||||||
s := store.New(map[string]bool{"test": true})
|
s := store.New(map[string]bool{"test": true})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue