aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/cache/object_test.go
diff options
context:
space:
mode:
authorSantiago M. Mola <santi@mola.io>2017-07-24 13:36:41 +0200
committerSantiago M. Mola <santi@mola.io>2017-07-27 14:15:09 +0200
commitf07672f5c3cad2e73596ab3d7ca16660f6881df6 (patch)
treec3e6162aacf6ee1c38bd3a3915dcb040b5006627 /plumbing/cache/object_test.go
parent854ffa16f650706200a6ebb5505bb448b5c64035 (diff)
downloadgo-git-f07672f5c3cad2e73596ab3d7ca16660f6881df6.tar.gz
plumbing/cache: use more explicit interface
* renamed Add to Put * Get returns a second bool value to indicate if there was hit or miss.
Diffstat (limited to 'plumbing/cache/object_test.go')
-rw-r--r--plumbing/cache/object_test.go30
1 files changed, 19 insertions, 11 deletions
diff --git a/plumbing/cache/object_test.go b/plumbing/cache/object_test.go
index 80cd17b..2a55acf 100644
--- a/plumbing/cache/object_test.go
+++ b/plumbing/cache/object_test.go
@@ -31,14 +31,14 @@ func (s *ObjectSuite) SetUpTest(c *C) {
}
func (s *ObjectSuite) TestAdd_SameObject(c *C) {
- s.c.Add(s.aObject)
+ s.c.Put(s.aObject)
c.Assert(s.c.actualSize, Equals, 1*Byte)
- s.c.Add(s.aObject)
+ s.c.Put(s.aObject)
c.Assert(s.c.actualSize, Equals, 1*Byte)
}
func (s *ObjectSuite) TestAdd_BigObject(c *C) {
- s.c.Add(s.bObject)
+ s.c.Put(s.bObject)
c.Assert(s.c.actualSize, Equals, 0*Byte)
c.Assert(s.c.actualSize, Equals, 0*KiByte)
c.Assert(s.c.actualSize, Equals, 0*MiByte)
@@ -47,24 +47,32 @@ func (s *ObjectSuite) TestAdd_BigObject(c *C) {
}
func (s *ObjectSuite) TestAdd_CacheOverflow(c *C) {
- s.c.Add(s.aObject)
+ s.c.Put(s.aObject)
c.Assert(s.c.actualSize, Equals, 1*Byte)
- s.c.Add(s.cObject)
+ s.c.Put(s.cObject)
c.Assert(len(s.c.objects), Equals, 2)
- s.c.Add(s.dObject)
+ s.c.Put(s.dObject)
c.Assert(len(s.c.objects), Equals, 2)
- c.Assert(s.c.Get(s.aObject.Hash()), IsNil)
- c.Assert(s.c.Get(s.cObject.Hash()), NotNil)
- c.Assert(s.c.Get(s.dObject.Hash()), NotNil)
+ obj, ok := s.c.Get(s.aObject.Hash())
+ c.Assert(ok, Equals, false)
+ c.Assert(obj, IsNil)
+ obj, ok = s.c.Get(s.cObject.Hash())
+ c.Assert(ok, Equals, true)
+ c.Assert(obj, NotNil)
+ obj, ok = s.c.Get(s.dObject.Hash())
+ c.Assert(ok, Equals, true)
+ c.Assert(obj, NotNil)
}
func (s *ObjectSuite) TestClear(c *C) {
- s.c.Add(s.aObject)
+ s.c.Put(s.aObject)
c.Assert(s.c.actualSize, Equals, 1*Byte)
s.c.Clear()
c.Assert(s.c.actualSize, Equals, 0*Byte)
- c.Assert(s.c.Get(s.aObject.Hash()), IsNil)
+ obj, ok := s.c.Get(s.aObject.Hash())
+ c.Assert(ok, Equals, false)
+ c.Assert(obj, IsNil)
}
type dummyObject struct {