| 1 |
package transactional |
| 2 |
|
| 3 |
import ( |
| 4 |
"testing" |
| 5 |
|
| 6 |
"github.com/go-git/go-billy/v5/memfs" |
| 7 |
"github.com/go-git/go-git/v5/plumbing" |
| 8 |
"github.com/go-git/go-git/v5/plumbing/cache" |
| 9 |
"github.com/go-git/go-git/v5/plumbing/storer" |
| 10 |
"github.com/go-git/go-git/v5/storage" |
| 11 |
"github.com/go-git/go-git/v5/storage/filesystem" |
| 12 |
"github.com/go-git/go-git/v5/storage/memory" |
| 13 |
"github.com/go-git/go-git/v5/storage/test" |
| 14 |
. "gopkg.in/check.v1" |
| 15 |
) |
| 16 |
|
| 17 |
func Test(t *testing.T) { TestingT(t) } |
| 18 |
|
| 19 |
type StorageSuite struct { |
| 20 |
test.BaseStorageSuite |
| 21 |
temporal func() storage.Storer |
| 22 |
} |
| 23 |
|
| 24 |
var _ = Suite(&StorageSuite{ |
| 25 |
temporal: func() storage.Storer { |
| 26 |
return memory.NewStorage() |
| 27 |
}, |
| 28 |
}) |
| 29 |
|
| 30 |
var _ = Suite(&StorageSuite{ |
| 31 |
temporal: func() storage.Storer { |
| 32 |
fs := memfs.New() |
| 33 |
return filesystem.NewStorage(fs, cache.NewObjectLRUDefault()) |
| 34 |
}, |
| 35 |
}) |
| 36 |
|
| 37 |
func (s *StorageSuite) SetUpTest(c *C) { |
| 38 |
base := memory.NewStorage() |
| 39 |
temporal := s.temporal() |
| 40 |
|
| 41 |
s.BaseStorageSuite = test.NewBaseStorageSuite(NewStorage(base, temporal)) |
| 42 |
} |
| 43 |
|
| 44 |
func (s *StorageSuite) TestCommit(c *C) { |
| 45 |
base := memory.NewStorage() |
| 46 |
temporal := s.temporal() |
| 47 |
st := NewStorage(base, temporal) |
| 48 |
|
| 49 |
commit := base.NewEncodedObject() |
| 50 |
commit.SetType(plumbing.CommitObject) |
| 51 |
|
| 52 |
_, err := st.SetEncodedObject(commit) |
| 53 |
c.Assert(err, IsNil) |
| 54 |
|
| 55 |
ref := plumbing.NewHashReference("refs/a", commit.Hash()) |
| 56 |
c.Assert(st.SetReference(ref), IsNil) |
| 57 |
|
| 58 |
err = st.Commit() |
| 59 |
c.Assert(err, IsNil) |
| 60 |
|
| 61 |
ref, err = base.Reference(ref.Name()) |
| 62 |
c.Assert(err, IsNil) |
| 63 |
c.Assert(ref.Hash(), Equals, commit.Hash()) |
| 64 |
|
| 65 |
obj, err := base.EncodedObject(plumbing.AnyObject, commit.Hash()) |
| 66 |
c.Assert(err, IsNil) |
| 67 |
c.Assert(obj.Hash(), Equals, commit.Hash()) |
| 68 |
} |
| 69 |
|
| 70 |
func (s *StorageSuite) TestTransactionalPackfileWriter(c *C) { |
| 71 |
base := memory.NewStorage() |
| 72 |
temporal := s.temporal() |
| 73 |
st := NewStorage(base, temporal) |
| 74 |
|
| 75 |
_, tmpOK := temporal.(storer.PackfileWriter) |
| 76 |
_, ok := st.(storer.PackfileWriter) |
| 77 |
c.Assert(ok, Equals, tmpOK) |
| 78 |
} |