From 91c408551ec84adaa162c373d79070ff73e2df21 Mon Sep 17 00:00:00 2001 From: "Frederick F. Kautz IV" Date: Sat, 18 Apr 2015 18:31:39 -0700 Subject: [PATCH] Adding test for ls cmd --- cmd-ls.go | 1 + cmd_test.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/cmd-ls.go b/cmd-ls.go index f1e6202b..fbc2cc4f 100644 --- a/cmd-ls.go +++ b/cmd-ls.go @@ -111,6 +111,7 @@ func runListCmd(ctx *cli.Context) { doListCmd(mcClientManager{}, u, globalDebugFlag) } } + func doListCmd(manager clientManager, u string, debug bool) { clnt, err := manager.getNewClient(u, debug) if err != nil { diff --git a/cmd_test.go b/cmd_test.go index 58e583ca..cfcbeef9 100644 --- a/cmd_test.go +++ b/cmd_test.go @@ -141,3 +141,35 @@ func (s *CmdTestSuite) TestCopyRecursive(c *C) { cl2.AssertExpectations(c) cl3.AssertExpectations(c) } + +func (s *CmdTestSuite) TestLsCmdWithBucket(c *C) { + // c.Skip("Incomplete") + sourceURL, err := parseURL("http://example.com/bucket1/", nil) + c.Assert(err, IsNil) + + manager := &MockclientManager{} + cl1 := &clientMocks.Client{} + + data1 := "hello1" + binarySum1 := md5.Sum([]byte(data1)) + etag1 := base64.StdEncoding.EncodeToString(binarySum1[:]) + dataLen1 := int64(len(data1)) + + data2 := "hello world 2" + binarySum2 := md5.Sum([]byte(data2)) + etag2 := base64.StdEncoding.EncodeToString(binarySum2[:]) + dataLen2 := int64(len(data2)) + + items := []*client.Item{ + {Key: "hello1", LastModified: time.Now(), ETag: etag1, Size: dataLen1}, + {Key: "hello2", LastModified: time.Now(), ETag: etag2, Size: dataLen2}, + } + + manager.On("getNewClient", sourceURL, false).Return(cl1, nil).Once() + cl1.On("ListObjects", "bucket1", "").Return(items, nil).Once() + doListCmd(manager, sourceURL, false) + // TODO work out how to test printing + + manager.AssertExpectations(c) + cl1.AssertExpectations(c) +}