| 40 | } |
| 41 | |
| 42 | func TestCache(t *testing.T) { |
| 43 | var c *Cache |
| 44 | |
| 45 | var ( |
| 46 | key = cacheableT{"foo"} |
| 47 | value = "bar" |
| 48 | ) |
| 49 | |
| 50 | t.Run("New", func(t *testing.T) { |
| 51 | c = NewCache() |
| 52 | assert.NotNil(t, c) |
| 53 | }) |
| 54 | |
| 55 | t.Run("ReadNonExistentValue", func(t *testing.T) { |
| 56 | _, ok := c.Read(&key) |
| 57 | assert.False(t, ok) |
| 58 | }) |
| 59 | |
| 60 | t.Run("Write", func(t *testing.T) { |
| 61 | c.Write(&key, value) |
| 62 | c.Write(&key, value) |
| 63 | }) |
| 64 | |
| 65 | t.Run("ReadExistentValue", func(t *testing.T) { |
| 66 | v, ok := c.Read(&key) |
| 67 | assert.True(t, ok) |
| 68 | assert.Equal(t, value, v) |
| 69 | }) |
| 70 | } |
| 71 | |
| 72 | func BenchmarkNewCache(b *testing.B) { |
| 73 | for i := 0; i < b.N; i++ { |