You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
117 lines
3.3 KiB
117 lines
3.3 KiB
10 years ago
|
package appendstorage
|
||
|
|
||
|
import (
|
||
10 years ago
|
"bytes"
|
||
10 years ago
|
"io/ioutil"
|
||
|
"os"
|
||
|
"testing"
|
||
|
|
||
10 years ago
|
"github.com/minio-io/minio/pkg/storage"
|
||
|
"github.com/minio-io/minio/pkg/utils"
|
||
10 years ago
|
. "gopkg.in/check.v1"
|
||
|
)
|
||
|
|
||
|
type AppendStorageSuite struct{}
|
||
|
|
||
|
var _ = Suite(&AppendStorageSuite{})
|
||
|
|
||
|
func Test(t *testing.T) { TestingT(t) }
|
||
|
|
||
|
func (s *AppendStorageSuite) TestAppendStoragePutAtRootPath(c *C) {
|
||
10 years ago
|
rootDir, err := utils.MakeTempTestDir()
|
||
10 years ago
|
c.Assert(err, IsNil)
|
||
|
defer os.RemoveAll(rootDir)
|
||
|
|
||
|
var objectStorage storage.ObjectStorage
|
||
|
objectStorage, err = NewStorage(rootDir, 0)
|
||
|
c.Assert(err, IsNil)
|
||
|
|
||
10 years ago
|
err = objectStorage.Put("path1", bytes.NewBuffer([]byte("object1")))
|
||
10 years ago
|
c.Assert(err, IsNil)
|
||
|
|
||
|
// assert object1 was created in correct path
|
||
10 years ago
|
objectResult1, err := objectStorage.Get("path1")
|
||
10 years ago
|
c.Assert(err, IsNil)
|
||
10 years ago
|
object1, _ := ioutil.ReadAll(objectResult1)
|
||
10 years ago
|
c.Assert(string(object1), Equals, "object1")
|
||
|
|
||
10 years ago
|
err = objectStorage.Put("path2", bytes.NewBuffer([]byte("object2")))
|
||
10 years ago
|
c.Assert(err, IsNil)
|
||
|
|
||
|
// assert object1 was created in correct path
|
||
10 years ago
|
objectResult2, err := objectStorage.Get("path2")
|
||
10 years ago
|
c.Assert(err, IsNil)
|
||
10 years ago
|
object2, _ := ioutil.ReadAll(objectResult2)
|
||
10 years ago
|
c.Assert(string(object2), Equals, "object2")
|
||
|
|
||
10 years ago
|
objectResult1, err = objectStorage.Get("path1")
|
||
10 years ago
|
c.Assert(err, IsNil)
|
||
10 years ago
|
object1, _ = ioutil.ReadAll(objectResult1)
|
||
10 years ago
|
c.Assert(string(object1), Equals, "object1")
|
||
|
}
|
||
|
|
||
|
func (s *AppendStorageSuite) TestAppendStoragePutDirPath(c *C) {
|
||
10 years ago
|
rootDir, err := utils.MakeTempTestDir()
|
||
10 years ago
|
c.Assert(err, IsNil)
|
||
|
defer os.RemoveAll(rootDir)
|
||
|
|
||
|
var objectStorage storage.ObjectStorage
|
||
|
objectStorage, err = NewStorage(rootDir, 0)
|
||
|
c.Assert(err, IsNil)
|
||
|
|
||
|
// add object 1
|
||
10 years ago
|
objectStorage.Put("path1/path2/path3", bytes.NewBuffer([]byte("object")))
|
||
10 years ago
|
|
||
|
// assert object1 was created in correct path
|
||
10 years ago
|
objectResult1, err := objectStorage.Get("path1/path2/path3")
|
||
10 years ago
|
c.Assert(err, IsNil)
|
||
10 years ago
|
object1, _ := ioutil.ReadAll(objectResult1)
|
||
10 years ago
|
c.Assert(string(object1), Equals, "object")
|
||
|
|
||
|
// add object 2
|
||
10 years ago
|
objectStorage.Put("path1/path1/path1", bytes.NewBuffer([]byte("object2")))
|
||
10 years ago
|
|
||
|
// assert object1 was created in correct path
|
||
10 years ago
|
objectResult2, err := objectStorage.Get("path1/path1/path1")
|
||
10 years ago
|
c.Assert(err, IsNil)
|
||
10 years ago
|
object2, _ := ioutil.ReadAll(objectResult2)
|
||
10 years ago
|
c.Assert(string(object2), Equals, "object2")
|
||
|
}
|
||
|
|
||
|
func (s *AppendStorageSuite) TestSerialization(c *C) {
|
||
10 years ago
|
rootDir, err := utils.MakeTempTestDir()
|
||
10 years ago
|
c.Assert(err, IsNil)
|
||
|
defer os.RemoveAll(rootDir)
|
||
|
|
||
|
objectStorage, err := NewStorage(rootDir, 0)
|
||
|
c.Assert(err, IsNil)
|
||
|
|
||
10 years ago
|
err = objectStorage.Put("path1", bytes.NewBuffer([]byte("object1")))
|
||
10 years ago
|
c.Assert(err, IsNil)
|
||
10 years ago
|
err = objectStorage.Put("path2", bytes.NewBuffer([]byte("object2")))
|
||
10 years ago
|
c.Assert(err, IsNil)
|
||
10 years ago
|
err = objectStorage.Put("path3/obj3", bytes.NewBuffer([]byte("object3")))
|
||
10 years ago
|
c.Assert(err, IsNil)
|
||
|
|
||
|
es := objectStorage.(*appendStorage)
|
||
|
es.file.Close()
|
||
|
|
||
|
objectStorage2, err := NewStorage(rootDir, 0)
|
||
|
c.Assert(err, IsNil)
|
||
|
|
||
10 years ago
|
objectResult1, err := objectStorage2.Get("path1")
|
||
10 years ago
|
c.Assert(err, IsNil)
|
||
10 years ago
|
object1, _ := ioutil.ReadAll(objectResult1)
|
||
10 years ago
|
c.Assert(string(object1), Equals, "object1")
|
||
|
|
||
10 years ago
|
objectResult2, err := objectStorage2.Get("path2")
|
||
10 years ago
|
c.Assert(err, IsNil)
|
||
10 years ago
|
object2, _ := ioutil.ReadAll(objectResult2)
|
||
10 years ago
|
c.Assert(string(object2), Equals, "object2")
|
||
|
|
||
10 years ago
|
objectResult3, err := objectStorage2.Get("path3/obj3")
|
||
10 years ago
|
c.Assert(err, IsNil)
|
||
10 years ago
|
object3, _ := ioutil.ReadAll(objectResult3)
|
||
10 years ago
|
c.Assert(string(object3), Equals, "object3")
|
||
|
}
|