diff options
author | cmal <paul@cmal.info> | 2018-03-17 00:13:23 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-03-17 00:13:23 +0100 |
commit | e46ab29bd24caa9e2cfa51f24ba15037750850d6 (patch) | |
tree | f5fb38d843bdd7a9daadc5c8eb84de7d58ade6a5 /hugolib | |
parent | 10fef32de6e6cf20f8054e9833b1ad09fba6d5cb (diff) |
hugolib: Add Reset method to delete key from Scratch
Diffstat (limited to 'hugolib')
-rw-r--r-- | hugolib/scratch.go | 8 | ||||
-rw-r--r-- | hugolib/scratch_test.go | 9 |
2 files changed, 17 insertions, 0 deletions
diff --git a/hugolib/scratch.go b/hugolib/scratch.go index ca2c9d6a8..37ed5df35 100644 --- a/hugolib/scratch.go +++ b/hugolib/scratch.go @@ -73,6 +73,14 @@ func (c *Scratch) Set(key string, value interface{}) string { return "" } +// Reset deletes the given key +func (c *Scratch) Delete(key string) string { + c.mu.Lock() + delete(c.values, key) + c.mu.Unlock() + return "" +} + // Get returns a value previously set by Add or Set func (c *Scratch) Get(key string) interface{} { c.mu.RLock() diff --git a/hugolib/scratch_test.go b/hugolib/scratch_test.go index f65c2ddfe..5ec2b89c8 100644 --- a/hugolib/scratch_test.go +++ b/hugolib/scratch_test.go @@ -87,6 +87,15 @@ func TestScratchSet(t *testing.T) { assert.Equal(t, "val", scratch.Get("key")) } +func TestScratchDelete(t *testing.T) { + t.Parallel() + scratch := newScratch() + scratch.Set("key", "val") + scratch.Delete("key") + scratch.Add("key", "Lucy Parsons") + assert.Equal(t, "Lucy Parsons", scratch.Get("key")) +} + // Issue #2005 func TestScratchInParallel(t *testing.T) { var wg sync.WaitGroup |