From 31e24bfb299a98f63cfc38e1900738e2487998e4 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 20 May 2015 11:45:20 -0700 Subject: [PATCH] Complete fs tests for objectRange and List recursive --- cmd_test.go | 13 ++++++- pkg/client/fs/fs_test.go | 80 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 89 insertions(+), 4 deletions(-) diff --git a/cmd_test.go b/cmd_test.go index e61e26c6..d848c191 100644 --- a/cmd_test.go +++ b/cmd_test.go @@ -71,7 +71,7 @@ func (s *CmdTestSuite) TestNewConfigV1(c *C) { url string } - want := []aliases{ + wantAliases := []aliases{ { "s3", "https://s3.amazonaws.com", @@ -85,12 +85,21 @@ func (s *CmdTestSuite) TestNewConfigV1(c *C) { "http://localhost:9000", }, } - for _, alias := range want { + for _, alias := range wantAliases { url, ok := data.Aliases[alias.name] c.Assert(ok, Equals, true) c.Assert(url, Equals, alias.url) } + wantHosts := []string{ + "play.minio.io:9000", + "dl.minio.io:9000", + "s3*.amazonaws.com", + } + for _, host := range wantHosts { + _, ok := data.Hosts[host] + c.Assert(ok, Equals, true) + } } func (s *CmdTestSuite) TestValidACL(c *C) { diff --git a/pkg/client/fs/fs_test.go b/pkg/client/fs/fs_test.go index edcf7bd0..ff7af794 100644 --- a/pkg/client/fs/fs_test.go +++ b/pkg/client/fs/fs_test.go @@ -60,11 +60,64 @@ func (s *MySuite) TestList(c *C) { c.Assert(err, IsNil) var contents []*client.Content - for contentCh := range fsc.List(true) { + for contentCh := range fsc.List(false) { + contents = append(contents, contentCh.Content) + } + c.Assert(err, IsNil) + c.Assert(len(contents), Equals, 2) + + for _, content := range contents { + c.Assert(content.Type.IsRegular(), Equals, true) + } + + objectPath = filepath.Join(root, "test1/newObject1") + fsc, err = New(objectPath) + c.Assert(err, IsNil) + + err = fsc.PutObject(uint64(dataLen), bytes.NewReader([]byte(data))) + c.Assert(err, IsNil) + + fsc, err = New(root) + c.Assert(err, IsNil) + + contents = nil + for contentCh := range fsc.List(false) { contents = append(contents, contentCh.Content) } c.Assert(err, IsNil) c.Assert(len(contents), Equals, 3) + + for _, content := range contents { + // skip previous regular files + if content.Type.IsRegular() { + continue + } + c.Assert(content.Type.IsDir(), Equals, true) + } + + fsc, err = New(root) + c.Assert(err, IsNil) + + contents = nil + for contentCh := range fsc.List(true) { + contents = append(contents, contentCh.Content) + } + + c.Assert(err, IsNil) + c.Assert(len(contents), Equals, 5) + + var regularFiles int + var directories int + for _, content := range contents { + if content.Type.IsRegular() { + regularFiles++ + } + if content.Type.IsDir() { + directories++ + } + } + c.Assert(regularFiles, Equals, 3) + c.Assert(directories, Equals, 2) } func (s *MySuite) TestPutBucket(c *C) { @@ -149,7 +202,30 @@ func (s *MySuite) TestGetObject(c *C) { } -func (s *MySuite) TestStat(c *C) { +func (s *MySuite) TestGetObjectRange(c *C) { + root, err := ioutil.TempDir(os.TempDir(), "fs-") + c.Assert(err, IsNil) + defer os.RemoveAll(root) + + objectPath := filepath.Join(root, "object") + fsc, err := New(objectPath) + c.Assert(err, IsNil) + + data := "hello world" + dataLen := len(data) + + err = fsc.PutObject(uint64(dataLen), bytes.NewReader([]byte(data))) + c.Assert(err, IsNil) + + reader, size, err := fsc.GetObject(0, 5) + c.Assert(err, IsNil) + var results bytes.Buffer + _, err = io.CopyN(&results, reader, int64(size)) + c.Assert(err, IsNil) + c.Assert([]byte("hello"), DeepEquals, results.Bytes()) +} + +func (s *MySuite) TestStatObject(c *C) { root, err := ioutil.TempDir(os.TempDir(), "fs-") c.Assert(err, IsNil) defer os.RemoveAll(root)