Adding List(path) to object storage definition and accompanying definition to fs

This commit is contained in:
Frederick F. Kautz IV
2014-12-10 18:54:04 -08:00
parent 9142de1dd5
commit cae9b288b0
6 changed files with 78 additions and 55 deletions
+44 -8
View File
@@ -3,6 +3,7 @@ package fsstorage
import (
"io/ioutil"
"os"
"testing"
"github.com/minio-io/minio/pkgs/storage"
. "gopkg.in/check.v1"
@@ -12,6 +13,8 @@ type FileSystemStorageSuite struct{}
var _ = Suite(&FileSystemStorageSuite{})
func Test(t *testing.T) { TestingT(t) }
func makeTempTestDir() (string, error) {
return ioutil.TempDir("/tmp", "minio-test-")
}
@@ -21,17 +24,21 @@ func (s *FileSystemStorageSuite) TestFileStoragePutAtRootPath(c *C) {
c.Assert(err, IsNil)
defer os.RemoveAll(rootDir)
var storage storage.ObjectStorage
storage = FileSystemStorage{
var objectStorage storage.ObjectStorage
objectStorage = FileSystemStorage{
RootDir: rootDir,
}
storage.Put("path1", []byte("object1"))
objectStorage.Put("path1", []byte("object1"))
// assert object1 was created in correct path
object1, err := storage.Get("path1")
object1, err := objectStorage.Get("path1")
c.Assert(err, IsNil)
c.Assert(string(object1), Equals, "object1")
objectList, err := objectStorage.List("/")
c.Assert(err, IsNil)
c.Assert(objectList[0].Path, Equals, "path1")
}
func (s *FileSystemStorageSuite) TestFileStoragePutDirPath(c *C) {
@@ -39,15 +46,44 @@ func (s *FileSystemStorageSuite) TestFileStoragePutDirPath(c *C) {
c.Assert(err, IsNil)
defer os.RemoveAll(rootDir)
var storage storage.ObjectStorage
storage = FileSystemStorage{
var objectStorage storage.ObjectStorage
objectStorage = FileSystemStorage{
RootDir: rootDir,
}
storage.Put("path1/path2/path3", []byte("object"))
objectStorage.Put("path1/path2/path3", []byte("object"))
// assert object1 was created in correct path
object1, err := storage.Get("path1/path2/path3")
object1, err := objectStorage.Get("path1/path2/path3")
c.Assert(err, IsNil)
c.Assert(string(object1), Equals, "object")
// add second object
err = objectStorage.Put("path2/path2/path2", []byte("object2"))
c.Assert(err, IsNil)
// add third object
err = objectStorage.Put("object3", []byte("object3"))
c.Assert(err, IsNil)
objectList, err := objectStorage.List("/")
c.Assert(err, IsNil)
c.Assert(objectList[0], Equals, storage.ObjectDescription{Path: "object3", IsDir: false, Hash: ""})
c.Assert(objectList[1], Equals, storage.ObjectDescription{Path: "path1", IsDir: true, Hash: ""})
c.Assert(objectList[2], Equals, storage.ObjectDescription{Path: "path2", IsDir: true, Hash: ""})
c.Assert(len(objectList), Equals, 3)
objectList, err = objectStorage.List("/path1")
c.Assert(err, IsNil)
c.Assert(objectList[0], Equals, storage.ObjectDescription{Path: "path2", IsDir: true, Hash: ""})
c.Assert(len(objectList), Equals, 1)
objectList, err = objectStorage.List("/path1/path2")
c.Assert(err, IsNil)
c.Assert(objectList[0], Equals, storage.ObjectDescription{Path: "path3", IsDir: false, Hash: ""})
c.Assert(len(objectList), Equals, 1)
objectList, err = objectStorage.List("/path1/path2/path3")
c.Assert(err, Not(IsNil))
c.Assert(objectList, IsNil)
}