aboutsummaryrefslogtreecommitdiffstats
path: root/storage/filesystem/internal/dotgit/dotgit_test.go
diff options
context:
space:
mode:
authorsona-tar <sona.zip@gmail.com>2016-08-31 05:13:12 +0900
committerMáximo Cuadros <mcuadros@gmail.com>2016-08-30 22:13:12 +0200
commitd72a19796ef0f556db93b553547f2ac085b59a1a (patch)
tree0c5cc404852b0fd46d35f50cbb3afddff49f7018 /storage/filesystem/internal/dotgit/dotgit_test.go
parent6d846503013f5a9cde0597698c998b6c0e0dc055 (diff)
downloadgo-git-d72a19796ef0f556db93b553547f2ac085b59a1a.tar.gz
Support non packed objects (#68)
* Support non packed git objects * Support non packed git objects for Iterator * Fix error handling from Writer() in FillObject() * Fix format in func (r *Reader) FillObject(obj core.Object) error * Fix to return d.addRefsFromPackedRefs() error And if packed-refs dosen't exist not to return error in d.addRefsFromPackedRefs * Remove debug code * Add GoDoc for func (d *DotGit) Objectfile(h core.Hash) (fs.FS, string, error) * Add GoDoc for func (r *Reader) FillObject(obj core.Object) error * Add GoDoc for func (d *DotGit) Objectfiles() (fs.FS, []core.Hash, error) * Fix format in func (d *DotGit) Objectfile(h core.Hash) (fs.FS, string, error) * Rename value dotGitobjcts -> objsDir * Change regexp.Compile -> regexp.MustCompile * Move regexp to variable initialization * Rename regexp value to be more coherent * Fix object directory name and object file name to correct character * Faster Objectfiles func * Add test for FillObject * Add GoDoc for func (s *ObjectStorage) Get(h core.Hash) (core.Object, error) * defer Close() * Return name values for defer function overwrite the error value. * Fix error handling in func (s *ObjectStorage) Get() Return error that gets error except for ErrObjfileNotFound from getFromUnpacked() * Rename getFromObject -> getFromUnpacked * Add test for func (d *DotGit) Objectfile(h core.Hash) (fs.FS, string, error) * Add test for func (d *DotGit) Objectfiles() (fs.FS, []core.Hash, error) * Faster check git object name * Faster dotgit_test.go * Fix Godoc for Objectfiles func * Refactor variable name in Objectfiles func * Fix GoDoc for objectfile func * Fix TestObjectfile func and TestObjectfiles func * Rename fixobj -> fixObj in Test Objectfile func * Fix test compare method * Refactor Get func in object.go * Refactor getFromUnpacked func in object.go * Fix GoDoc for ErrObjfileNotFound * Fix TestObjectfiles for not guarantee the slice order * Change error no such file or directory to target file not found * Change spec func (s *ObjectStorage) Get(h core.Hash) (core.Object, error) return core.ErrObjectNotFound, if index pointer is nil. * Add space * storage: Add object type hint parameter to ObjectStorage.getFromUnpacked
Diffstat (limited to 'storage/filesystem/internal/dotgit/dotgit_test.go')
-rw-r--r--storage/filesystem/internal/dotgit/dotgit_test.go125
1 files changed, 123 insertions, 2 deletions
diff --git a/storage/filesystem/internal/dotgit/dotgit_test.go b/storage/filesystem/internal/dotgit/dotgit_test.go
index 7c39c87..954eef1 100644
--- a/storage/filesystem/internal/dotgit/dotgit_test.go
+++ b/storage/filesystem/internal/dotgit/dotgit_test.go
@@ -22,6 +22,7 @@ var initFixtures = [...]struct {
capabilities [][2]string
packfile string
idxfile string
+ objectfiles []fixtureObject
}{
{
name: "spinnaker",
@@ -37,7 +38,47 @@ var initFixtures = [...]struct {
}, {
name: "empty",
tgz: "fixtures/empty-gitdir.tgz",
+ }, {
+ name: "unpacked",
+ tgz: "fixtures/unpacked-objects-no-packfile-no-idx.tgz",
+ objectfiles: []fixtureObject{
+ fixtureObject{
+ path: "objects/1e/0304e3cb54d0ad612ad70f1f15a285a65a4b8e",
+ hash: "1e0304e3cb54d0ad612ad70f1f15a285a65a4b8e",
+ },
+ fixtureObject{
+ path: "objects/5e/fb9bc29c482e023e40e0a2b3b7e49cec842034",
+ hash: "5efb9bc29c482e023e40e0a2b3b7e49cec842034",
+ },
+ fixtureObject{
+ path: "objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391",
+ hash: "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
+ },
+ },
},
+ {
+ name: "unpacked-dummy",
+ tgz: "fixtures/unpacked-objects-exist-one-dummy-object-no-packfile-no-idx.tgz",
+ objectfiles: []fixtureObject{
+ fixtureObject{
+ path: "objects/1e/0304e3cb54d0ad612ad70f1f15a285a65a4b8e",
+ hash: "1e0304e3cb54d0ad612ad70f1f15a285a65a4b8e",
+ },
+ fixtureObject{
+ path: "objects/5e/fb9bc29c482e023e40e0a2b3b7e49cec842034",
+ hash: "5efb9bc29c482e023e40e0a2b3b7e49cec842034",
+ },
+ fixtureObject{
+ path: "objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391",
+ hash: "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
+ },
+ },
+ },
+}
+
+type fixtureObject struct {
+ path string
+ hash string
}
type fixture struct {
@@ -47,6 +88,7 @@ type fixture struct {
capabilities *common.Capabilities // expected capabilities
packfile string // path of the packfile
idxfile string // path of the idxfile
+ objectfiles []fixtureObject // path and hash of the object files
}
type SuiteDotGit struct {
@@ -77,6 +119,7 @@ func (s *SuiteDotGit) SetUpSuite(c *C) {
f.packfile = init.packfile
f.idxfile = init.idxfile
+ f.objectfiles = init.objectfiles
s.fixtures[init.name] = f
}
@@ -193,11 +236,11 @@ func (s *SuiteDotGit) TestPackfile(c *C) {
}, {
fixture: "empty",
fn: packfile,
- err: ".* no such file or directory",
+ err: "packfile not found",
}, {
fixture: "empty",
fn: idxfile,
- err: ".* no such file or directory",
+ err: "idx file not found",
}, {
fixture: "no-packfile-no-idx",
fn: packfile,
@@ -224,9 +267,87 @@ func (s *SuiteDotGit) TestPackfile(c *C) {
}
}
+func (s *SuiteDotGit) TestObjectfiles(c *C) {
+ for _, test := range [...]struct {
+ fixture string
+ err error
+ }{
+ {
+ fixture: "unpacked",
+ },
+ {
+ fixture: "unpacked-dummy",
+ }, {
+ fixture: "empty",
+ err: ErrObjfileNotFound,
+ }, {
+ fixture: "no-packfile-no-idx",
+ },
+ } {
+ com := Commentf("fixture = %s", test.fixture)
+
+ fix, dir := s.newFixtureDir(c, test.fixture)
+
+ _, hashes, err := dir.Objectfiles()
+
+ if test.err != nil {
+ c.Assert(err, Equals, test.err, com)
+ } else {
+ c.Assert(err, IsNil, com)
+ c.Assert(len(hashes), Equals, len(fix.objectfiles), com)
+
+ for _, hash := range hashes {
+ c.Assert(containsObject(fix.objectfiles, hash), Equals, true, com)
+ }
+ }
+ }
+}
+
+func (s *SuiteDotGit) TestObjectfile(c *C) {
+ for _, test := range [...]struct {
+ fixture string
+ err error
+ }{
+ {
+ fixture: "unpacked",
+ }, {
+ fixture: "empty",
+ err: ErrObjfileNotFound,
+ }, {
+ fixture: "no-packfile-no-idx",
+ err: ErrObjfileNotFound,
+ },
+ } {
+ com := Commentf("fixture = %s", test.fixture)
+
+ fix, dir := s.newFixtureDir(c, test.fixture)
+
+ for _, fixObj := range fix.objectfiles {
+ _, path, err := dir.Objectfile(core.NewHash(fixObj.hash))
+
+ if test.err != nil {
+ c.Assert(err, Equals, test.err, com)
+ } else {
+ c.Assert(err, IsNil, com)
+ c.Assert(strings.HasSuffix(path, fixObj.path),
+ Equals, true, com)
+ }
+ }
+ }
+}
+
type getPathFn func(*DotGit) (fs.FS, string, error)
func noExt(path string) string {
ext := filepath.Ext(path)
return path[0 : len(path)-len(ext)]
}
+
+func containsObject(objs []fixtureObject, hash core.Hash) bool {
+ for _, o := range objs {
+ if strings.ToLower(o.hash) == strings.ToLower(hash.String()) {
+ return true
+ }
+ }
+ return false
+}