aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/cache/buffer_test.go
diff options
context:
space:
mode:
authorkuba-- <kuba@sourced.tech>2018-09-17 22:20:50 +0200
committerkuba-- <kuba@sourced.tech>2018-09-17 22:20:50 +0200
commit4896974b4daf86f53d782c868d408f830f84c294 (patch)
treec0668f6aeb4f95c5d75bef0e2aa469b563d10810 /plumbing/cache/buffer_test.go
parent2fb32d2a8601213b6db109d3e9028c6b64af1874 (diff)
downloadgo-git-4896974b4daf86f53d782c868d408f830f84c294.tar.gz
Fix potential LRU cache size issue.
Signed-off-by: kuba-- <kuba@sourced.tech>
Diffstat (limited to 'plumbing/cache/buffer_test.go')
-rw-r--r--plumbing/cache/buffer_test.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/plumbing/cache/buffer_test.go b/plumbing/cache/buffer_test.go
index 262138a..3e3adc2 100644
--- a/plumbing/cache/buffer_test.go
+++ b/plumbing/cache/buffer_test.go
@@ -1,6 +1,7 @@
package cache
import (
+ "bytes"
"sync"
. "gopkg.in/check.v1"
@@ -38,6 +39,28 @@ func (s *BufferSuite) TestPutSameBuffer(c *C) {
}
}
+func (s *ObjectSuite) TestPutSameBufferWithDifferentSize(c *C) {
+ aBuffer := []byte("a")
+ bBuffer := []byte("bbb")
+ cBuffer := []byte("ccccc")
+ dBuffer := []byte("ddddddd")
+
+ cache := NewBufferLRU(7 * Byte)
+ cache.Put(1, aBuffer)
+ cache.Put(1, bBuffer)
+ cache.Put(1, cBuffer)
+ cache.Put(1, dBuffer)
+
+ c.Assert(cache.MaxSize, Equals, 7*Byte)
+ c.Assert(cache.actualSize, Equals, 7*Byte)
+ c.Assert(cache.ll.Len(), Equals, 1)
+
+ buf, ok := cache.Get(1)
+ c.Assert(bytes.Equal(buf, dBuffer), Equals, true)
+ c.Assert(FileSize(len(buf)), Equals, 7*Byte)
+ c.Assert(ok, Equals, true)
+}
+
func (s *BufferSuite) TestPutBigBuffer(c *C) {
for _, o := range s.c {
o.Put(1, s.bBuffer)