From 097d9d43958df8e154a5a29be7f4d05ef5461798 Mon Sep 17 00:00:00 2001 From: Alice Sawatzky Date: Mon, 10 Aug 2020 14:58:47 -0500 Subject: [PATCH] [alibaba_test] improve folder tests --- alibaba_test.go | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/alibaba_test.go b/alibaba_test.go index f59744f6..6b1ece1b 100644 --- a/alibaba_test.go +++ b/alibaba_test.go @@ -17,6 +17,7 @@ limitations under the License. package storage import ( + "fmt" "os" "testing" @@ -49,25 +50,39 @@ func (suite *AlibabaTestSuite) SetupSuite() { path := "deleteme.txt" for i := 0; i < testCount; i++ { - newPath := strconv.Itoa(i) + path - err := suite.NoPrefixAlibabaOSSBackend.PutObject(newPath, data) + testFilePath := fmt.Sprintf("%i%s", i, path) + testDirFilePath := fmt.Sprintf("testdir%i/%s", i, path) + err := suite.NoPrefixAlibabaOSSBackend.PutObject(testFilePath, data) suite.Nil(err, "no error putting deleteme.txt using Alibaba Cloud OSS backend") - err = suite.SSEAlibabaOSSBackend.PutObject(newPath, data) + err = suite.NoPrefixAlibabaOSSBackend.PutObject(testDirFilePath, data) + suite.Nil(err, "no error putting testdir/deleteme.txt using Alibaba Cloud OSS backend") + + err = suite.SSEAlibabaOSSBackend.PutObject(testFilePath, data) suite.Nil(err, "no error putting deleteme.txt using Alibaba Cloud OSS backend (SSE)") + + err = suite.SSEAlibabaOSSBackend.PutObject(testDirFilePath, data) + suite.Nil(err, "no error putting testdir/deleteme.txt using Alibaba Cloud OSS backend (SSE)") } } func (suite *AlibabaTestSuite) TearDownSuite() { path := "deleteme.txt" for i := 0; i < testCount; i++ { - newPath := strconv.Itoa(i) + path + testFilePath := fmt.Sprintf("%i%s", i, path) + testDirFilePath := fmt.Sprintf("testdir%i/%s", i, path) - err := suite.NoPrefixAlibabaOSSBackend.DeleteObject(newPath) + err := suite.NoPrefixAlibabaOSSBackend.DeleteObject(testFilePath) suite.Nil(err, "no error deleting deleteme.txt using AlibabaOSS backend") - err = suite.SSEAlibabaOSSBackend.DeleteObject(newPath) + err := suite.NoPrefixAlibabaOSSBackend.DeleteObject(testDirFilePath) + suite.Nil(err, "no error deleting testdir/deleteme.txt using AlibabaOSS backend") + + err = suite.SSEAlibabaOSSBackend.DeleteObject(testFilePath) suite.Nil(err, "no error deleting deleteme.txt using AlibabaOSS backend") + + err = suite.SSEAlibabaOSSBackend.DeleteObject(testDirFilePath) + suite.Nil(err, "no error deleting testdir/deleteme.txt using AlibabaOSS backend") } } @@ -88,11 +103,13 @@ func (suite *AlibabaTestSuite) TestListFolders() { _, err := suite.BrokenAlibabaOSSBackend.ListFolders("") suite.NotNil(err, "cannot list folders with bad bucket") - _, err = suite.NoPrefixAlibabaOSSBackend.ListFolders("") + folders, err := suite.NoPrefixAlibabaOSSBackend.ListFolders("") suite.Nil(err, "can list folders with good bucket, no prefix") + suite.Equal(len(folders), testCount, "able to list folders") - _, err = suite.SSEAlibabaOSSBackend.ListFolders("") + folders, err = suite.SSEAlibabaOSSBackend.ListFolders("") suite.Nil(err, "can list objects with good bucket, SSE") + suite.Equal(len(folders), testCount, "able to list folders") } func (suite *AlibabaTestSuite) TestGetObject() {