From a63f8f91f8e8c9086e69dc2b72dae973f35546bc Mon Sep 17 00:00:00 2001 From: Kelsey Hightower Date: Mon, 8 Dec 2014 22:29:17 -0800 Subject: [PATCH] don't cache k/v values between runs --- Godeps/Godeps.json | 2 +- .../github.com/kelseyhightower/memkv/store.go | 8 +++++++ .../kelseyhightower/memkv/store_test.go | 22 +++++++++++++++++++ resource/template/resource.go | 1 + 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 1eff029f8..480d9625e 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -17,7 +17,7 @@ }, { "ImportPath": "github.com/kelseyhightower/memkv", - "Rev": "0277ca1f88c172bd2aefcd2d177fa907528bb33b" + "Rev": "7f9c7f36f45ba80c62fe22779ee78d9b4ca36580" } ] } diff --git a/Godeps/_workspace/src/github.com/kelseyhightower/memkv/store.go b/Godeps/_workspace/src/github.com/kelseyhightower/memkv/store.go index 4eaa6ae6a..67b6587c8 100644 --- a/Godeps/_workspace/src/github.com/kelseyhightower/memkv/store.go +++ b/Godeps/_workspace/src/github.com/kelseyhightower/memkv/store.go @@ -162,6 +162,14 @@ func (s Store) Set(key string, value string) { s.Unlock() } +func (s Store) Purge() { + s.Lock() + for k := range s.m { + delete(s.m, k) + } + s.Unlock() +} + func stripKey(key, prefix string) string { return strings.TrimPrefix(strings.TrimPrefix(key, prefix), "/") } diff --git a/Godeps/_workspace/src/github.com/kelseyhightower/memkv/store_test.go b/Godeps/_workspace/src/github.com/kelseyhightower/memkv/store_test.go index 3f7522b94..4aabdea29 100644 --- a/Godeps/_workspace/src/github.com/kelseyhightower/memkv/store_test.go +++ b/Godeps/_workspace/src/github.com/kelseyhightower/memkv/store_test.go @@ -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", diff --git a/resource/template/resource.go b/resource/template/resource.go index f14b44f2f..275c60b5d 100644 --- a/resource/template/resource.go +++ b/resource/template/resource.go @@ -93,6 +93,7 @@ func (t *TemplateResource) setVars() error { if err != nil { return err } + t.store.Purge() for k, v := range result { t.store.Set(filepath.Join("/", strings.TrimPrefix(k, t.prefix)), v) }