Skip to content

Commit 47d560b

Browse files
[alibaba_test] improve folder tests
1 parent bd898ee commit 47d560b

1 file changed

Lines changed: 25 additions & 9 deletions

File tree

alibaba_test.go

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ limitations under the License.
1717
package storage
1818

1919
import (
20+
"fmt"
2021
"os"
2122
"testing"
2223

2324
"github.com/stretchr/testify/suite"
24-
"strconv"
2525
)
2626

2727
type AlibabaTestSuite struct {
@@ -49,25 +49,39 @@ func (suite *AlibabaTestSuite) SetupSuite() {
4949
path := "deleteme.txt"
5050

5151
for i := 0; i < testCount; i++ {
52-
newPath := strconv.Itoa(i) + path
53-
err := suite.NoPrefixAlibabaOSSBackend.PutObject(newPath, data)
52+
testFilePath := fmt.Sprintf("%d%s", i, path)
53+
testDirFilePath := fmt.Sprintf("testdir%d/%s", i, path)
54+
err := suite.NoPrefixAlibabaOSSBackend.PutObject(testFilePath, data)
5455
suite.Nil(err, "no error putting deleteme.txt using Alibaba Cloud OSS backend")
5556

56-
err = suite.SSEAlibabaOSSBackend.PutObject(newPath, data)
57+
err = suite.NoPrefixAlibabaOSSBackend.PutObject(testDirFilePath, data)
58+
suite.Nil(err, "no error putting testdir/deleteme.txt using Alibaba Cloud OSS backend")
59+
60+
err = suite.SSEAlibabaOSSBackend.PutObject(testFilePath, data)
5761
suite.Nil(err, "no error putting deleteme.txt using Alibaba Cloud OSS backend (SSE)")
62+
63+
err = suite.SSEAlibabaOSSBackend.PutObject(testDirFilePath, data)
64+
suite.Nil(err, "no error putting testdir/deleteme.txt using Alibaba Cloud OSS backend (SSE)")
5865
}
5966
}
6067

6168
func (suite *AlibabaTestSuite) TearDownSuite() {
6269
path := "deleteme.txt"
6370
for i := 0; i < testCount; i++ {
64-
newPath := strconv.Itoa(i) + path
71+
testFilePath := fmt.Sprintf("%d%s", i, path)
72+
testDirFilePath := fmt.Sprintf("testdir%d/%s", i, path)
6573

66-
err := suite.NoPrefixAlibabaOSSBackend.DeleteObject(newPath)
74+
err := suite.NoPrefixAlibabaOSSBackend.DeleteObject(testFilePath)
6775
suite.Nil(err, "no error deleting deleteme.txt using AlibabaOSS backend")
6876

69-
err = suite.SSEAlibabaOSSBackend.DeleteObject(newPath)
77+
err = suite.NoPrefixAlibabaOSSBackend.DeleteObject(testDirFilePath)
78+
suite.Nil(err, "no error deleting testdir/deleteme.txt using AlibabaOSS backend")
79+
80+
err = suite.SSEAlibabaOSSBackend.DeleteObject(testFilePath)
7081
suite.Nil(err, "no error deleting deleteme.txt using AlibabaOSS backend")
82+
83+
err = suite.SSEAlibabaOSSBackend.DeleteObject(testDirFilePath)
84+
suite.Nil(err, "no error deleting testdir/deleteme.txt using AlibabaOSS backend")
7185
}
7286
}
7387

@@ -88,11 +102,13 @@ func (suite *AlibabaTestSuite) TestListFolders() {
88102
_, err := suite.BrokenAlibabaOSSBackend.ListFolders("")
89103
suite.NotNil(err, "cannot list folders with bad bucket")
90104

91-
_, err = suite.NoPrefixAlibabaOSSBackend.ListFolders("")
105+
folders, err := suite.NoPrefixAlibabaOSSBackend.ListFolders("")
92106
suite.Nil(err, "can list folders with good bucket, no prefix")
107+
suite.Equal(len(folders), testCount, "able to list folders")
93108

94-
_, err = suite.SSEAlibabaOSSBackend.ListFolders("")
109+
folders, err = suite.SSEAlibabaOSSBackend.ListFolders("")
95110
suite.Nil(err, "can list objects with good bucket, SSE")
111+
suite.Equal(len(folders), testCount, "able to list folders")
96112
}
97113

98114
func (suite *AlibabaTestSuite) TestGetObject() {

0 commit comments

Comments
 (0)