Skip to content

Commit

Permalink
add purge function
Browse files Browse the repository at this point in the history
  • Loading branch information
kelseyhightower committed Dec 9, 2014
1 parent 0277ca1 commit 3adb8cf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions store.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ func (s Store) Set(key string, value string) {
s.Unlock()
}

func (s *Store) Purge() {
s.Lock()
newMap := make(map[string]KVPair)
s.m = newMap
s.Unlock()
}

func stripKey(key, prefix string) string {
return strings.TrimPrefix(strings.TrimPrefix(key, prefix), "/")
}
22 changes: 22 additions & 0 deletions store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,28 @@ func TestDel(t *testing.T) {
s.Del("/app/port")
}

func TestPurge(t *testing.T) {
s := New()
s.Set("/app/port", "8080")
want := KVPair{"/app/port", "8080"}
got, err := s.Get("/app/port")
if err != nil || got != want {
t.Errorf("Get(%q) = %v, %v, want %v, %v", "/app/port", got, err, want, true)
}
s.Purge()
want = KVPair{}
got, err = s.Get("/app/port")
if err != ErrNotExist || got != want {
t.Errorf("Get(%q) = %v, %v, want %v, %v", "/app/port", got, err, want, false)
}
s.Set("/app/port", "8080")
want = KVPair{"/app/port", "8080"}
got, err = s.Get("/app/port")
if err != nil || got != want {
t.Errorf("Get(%q) = %v, %v, want %v, %v", "/app/port", got, err, want, true)
}
}

var listTestMap = map[string]string{
"/deis/database/user": "user",
"/deis/database/pass": "pass",
Expand Down

0 comments on commit 3adb8cf

Please sign in to comment.