| 1 |
package filesystem |
| 2 |
|
| 3 |
import ( |
| 4 |
"testing" |
| 5 |
|
| 6 |
"github.com/go-git/go-git/v5/plumbing/cache" |
| 7 |
"github.com/go-git/go-git/v5/plumbing/storer" |
| 8 |
"github.com/go-git/go-git/v5/storage/test" |
| 9 |
|
| 10 |
"github.com/go-git/go-billy/v5" |
| 11 |
"github.com/go-git/go-billy/v5/memfs" |
| 12 |
"github.com/go-git/go-billy/v5/osfs" |
| 13 |
"github.com/go-git/go-billy/v5/util" |
| 14 |
. "gopkg.in/check.v1" |
| 15 |
) |
| 16 |
|
| 17 |
func Test(t *testing.T) { TestingT(t) } |
| 18 |
|
| 19 |
type StorageSuite struct { |
| 20 |
test.BaseStorageSuite |
| 21 |
dir string |
| 22 |
fs billy.Filesystem |
| 23 |
} |
| 24 |
|
| 25 |
var _ = Suite(&StorageSuite{}) |
| 26 |
|
| 27 |
func (s *StorageSuite) SetUpTest(c *C) { |
| 28 |
tmp, err := util.TempDir(osfs.Default, "", "go-git-filestystem-config") |
| 29 |
c.Assert(err, IsNil) |
| 30 |
|
| 31 |
s.dir = tmp |
| 32 |
s.fs = osfs.New(s.dir) |
| 33 |
storage := NewStorage(s.fs, cache.NewObjectLRUDefault()) |
| 34 |
|
| 35 |
setUpTest(s, c, storage) |
| 36 |
} |
| 37 |
|
| 38 |
func setUpTest(s *StorageSuite, c *C, storage *Storage) { |
| 39 |
// ensure that right interfaces are implemented |
| 40 |
var _ storer.EncodedObjectStorer = storage |
| 41 |
var _ storer.IndexStorer = storage |
| 42 |
var _ storer.ReferenceStorer = storage |
| 43 |
var _ storer.ShallowStorer = storage |
| 44 |
var _ storer.DeltaObjectStorer = storage |
| 45 |
var _ storer.PackfileWriter = storage |
| 46 |
|
| 47 |
s.BaseStorageSuite = test.NewBaseStorageSuite(storage) |
| 48 |
} |
| 49 |
|
| 50 |
func (s *StorageSuite) TestFilesystem(c *C) { |
| 51 |
fs := memfs.New() |
| 52 |
storage := NewStorage(fs, cache.NewObjectLRUDefault()) |
| 53 |
|
| 54 |
c.Assert(storage.Filesystem(), Equals, fs) |
| 55 |
} |
| 56 |
|
| 57 |
func (s *StorageSuite) TestNewStorageShouldNotAddAnyContentsToDir(c *C) { |
| 58 |
fis, err := s.fs.ReadDir("/") |
| 59 |
c.Assert(err, IsNil) |
| 60 |
c.Assert(fis, HasLen, 0) |
| 61 |
} |
| 62 |
|
| 63 |
type StorageExclusiveSuite struct { |
| 64 |
StorageSuite |
| 65 |
} |
| 66 |
|
| 67 |
var _ = Suite(&StorageExclusiveSuite{}) |
| 68 |
|
| 69 |
func (s *StorageExclusiveSuite) SetUpTest(c *C) { |
| 70 |
tmp, err := util.TempDir(osfs.Default, "", "go-git-filestystem-config") |
| 71 |
c.Assert(err, IsNil) |
| 72 |
|
| 73 |
s.dir = tmp |
| 74 |
s.fs = osfs.New(s.dir) |
| 75 |
|
| 76 |
storage := NewStorageWithOptions( |
| 77 |
s.fs, |
| 78 |
cache.NewObjectLRUDefault(), |
| 79 |
Options{ExclusiveAccess: true}) |
| 80 |
|
| 81 |
setUpTest(&s.StorageSuite, c, storage) |
| 82 |
} |