diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2016-09-05 07:59:20 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-09-05 07:59:20 +0200 |
commit | 65427f64599e9383ab926aed75fc02f2db32022d (patch) | |
tree | 5c81c00bc9dcfb54e0c6d0038ab2cbd8cddde389 /storage/test | |
parent | 440cfd96cf88ffc9d04bbd32ec8a3b1afb42144c (diff) | |
download | go-git-65427f64599e9383ab926aed75fc02f2db32022d.tar.gz |
core: ObjectStorage.Begin and TxObjectStorage
Diffstat (limited to 'storage/test')
-rw-r--r-- | storage/test/storage_suite.go | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/storage/test/storage_suite.go b/storage/test/storage_suite.go index c68a089..b4ba306 100644 --- a/storage/test/storage_suite.go +++ b/storage/test/storage_suite.go @@ -114,3 +114,48 @@ func (s *BaseStorageSuite) TestObjectStorageIter(c *C) { c.Assert(found, Equals, true, Commentf("Object of type %s not found", to.Type.String())) } } + +func (s *BaseStorageSuite) TestTxObjectStorageSetAndCommit(c *C) { + tx := s.ObjectStorage.Begin() + for _, o := range s.testObjects { + h, err := tx.Set(o.Object) + c.Assert(err, IsNil) + c.Assert(h.String(), Equals, o.Hash) + } + + iter, err := s.ObjectStorage.Iter(core.AnyObject) + c.Assert(err, IsNil) + _, err = iter.Next() + c.Assert(err, Equals, io.EOF) + + err = tx.Commit() + c.Assert(err, IsNil) + + iter, err = s.ObjectStorage.Iter(core.AnyObject) + c.Assert(err, IsNil) + + var count int + iter.ForEach(func(o core.Object) error { + count++ + return nil + }) + + c.Assert(count, Equals, 4) +} + +func (s *BaseStorageSuite) TestTxObjectStorageSetAndRollback(c *C) { + tx := s.ObjectStorage.Begin() + for _, o := range s.testObjects { + h, err := tx.Set(o.Object) + c.Assert(err, IsNil) + c.Assert(h.String(), Equals, o.Hash) + } + + err := tx.Rollback() + c.Assert(err, IsNil) + + iter, err := s.ObjectStorage.Iter(core.AnyObject) + c.Assert(err, IsNil) + _, err = iter.Next() + c.Assert(err, Equals, io.EOF) +} |