diff options
author | Javi Fontan <jfontan@gmail.com> | 2018-01-16 13:12:58 +0000 |
---|---|---|
committer | Javi Fontan <jfontan@gmail.com> | 2018-01-16 13:12:58 +0000 |
commit | 0f6c06db068acb7a8eab639df20b72fa717232c8 (patch) | |
tree | 571dc4b1531475c8dd0cf8e7492b2a58eb5a126f /plumbing/cache | |
parent | c281165b48d9901d391c583b6d7c28d37edb4ff5 (diff) | |
download | go-git-0f6c06db068acb7a8eab639df20b72fa717232c8.tar.gz |
Test eviction of more than one object
Signed-off-by: Javi Fontan <jfontan@gmail.com>
Diffstat (limited to 'plumbing/cache')
-rw-r--r-- | plumbing/cache/object_test.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/plumbing/cache/object_test.go b/plumbing/cache/object_test.go index ec01d60..ac3f0a3 100644 --- a/plumbing/cache/object_test.go +++ b/plumbing/cache/object_test.go @@ -19,6 +19,7 @@ type ObjectSuite struct { bObject plumbing.EncodedObject cObject plumbing.EncodedObject dObject plumbing.EncodedObject + eObject plumbing.EncodedObject } var _ = Suite(&ObjectSuite{}) @@ -28,6 +29,7 @@ func (s *ObjectSuite) SetUpTest(c *C) { s.bObject = newObject("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", 3*Byte) s.cObject = newObject("cccccccccccccccccccccccccccccccccccccccc", 1*Byte) s.dObject = newObject("dddddddddddddddddddddddddddddddddddddddd", 1*Byte) + s.eObject = newObject("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", 2*Byte) s.c = make(map[string]Object) s.c["two_bytes"] = NewObjectLRU(2 * Byte) @@ -70,6 +72,24 @@ func (s *ObjectSuite) TestPutCacheOverflow(c *C) { c.Assert(obj, NotNil) } +func (s *ObjectSuite) TestEvictMultipleObjects(c *C) { + o := s.c["two_bytes"] + + o.Put(s.cObject) + o.Put(s.dObject) // now cache is full with two objects + o.Put(s.eObject) // this put should evict all previous objects + + obj, ok := o.Get(s.cObject.Hash()) + c.Assert(ok, Equals, false) + c.Assert(obj, IsNil) + obj, ok = o.Get(s.dObject.Hash()) + c.Assert(ok, Equals, false) + c.Assert(obj, IsNil) + obj, ok = o.Get(s.eObject.Hash()) + c.Assert(ok, Equals, true) + c.Assert(obj, NotNil) +} + func (s *ObjectSuite) TestClear(c *C) { for _, o := range s.c { o.Put(s.aObject) |