Skip to content

Commit

Permalink
udpate testcase.
Browse files Browse the repository at this point in the history
  • Loading branch information
huiguangjun committed Aug 19, 2022
1 parent 5d06353 commit 3413376
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 49 deletions.
4 changes: 3 additions & 1 deletion oss/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ var (

// for cloud box ID
cloudBoxID = os.Getenv("OSS_TEST_CLOUDBOX_ID")

kmsID = os.Getenv("OSS_TEST_KMS_ID")
)

var (
Expand Down Expand Up @@ -3428,7 +3430,7 @@ func (s *OssClientSuite) TestSetBucketInventory(c *C) {
// encryption config
var invSseOss InvSseOss
invSseKms := InvSseKms{
KmsId: "keyId",
KmsId: kmsID,
}
var invEncryption InvEncryption

Expand Down
1 change: 1 addition & 0 deletions oss/download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var _ = Suite(&OssDownloadSuite{})

// SetUpSuite runs once when the suite starts running
func (s *OssDownloadSuite) SetUpSuite(c *C) {
bucketName := bucketNamePrefix + RandLowStr(6)
if cloudboxControlEndpoint == "" {
client, err := New(endpoint, accessID, accessKey)
c.Assert(err, IsNil)
Expand Down
5 changes: 3 additions & 2 deletions oss/livechannel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var _ = Suite(&OssBucketLiveChannelSuite{})

// SetUpSuite Run once when the suite starts running
func (s *OssBucketLiveChannelSuite) SetUpSuite(c *C) {
bucketName := bucketNamePrefix + RandLowStr(6)
if cloudboxControlEndpoint == "" {
client, err := New(endpoint, accessID, accessKey)
c.Assert(err, IsNil)
Expand Down Expand Up @@ -108,8 +109,8 @@ func (s *OssBucketLiveChannelSuite) TestCreateLiveChannel(c *C) {
result, err := s.bucket.CreateLiveChannel(channelName, config)
c.Assert(err, IsNil)

playURL := getPlayURL(bucketName, channelName, playlistName)
publishURL := getPublishURL(bucketName, channelName)
playURL := getPlayURL(s.bucket.BucketName, channelName, playlistName)
publishURL := getPublishURL(s.bucket.BucketName, channelName)
c.Assert(result.PlayUrls[0], Equals, playURL)
c.Assert(result.PublishUrls[0], Equals, publishURL)

Expand Down
67 changes: 34 additions & 33 deletions oss/multicopy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var _ = Suite(&OssCopySuite{})

// SetUpSuite runs once when the suite starts running
func (s *OssCopySuite) SetUpSuite(c *C) {
bucketName := bucketNamePrefix + RandLowStr(6)
if cloudboxControlEndpoint == "" {
client, err := New(endpoint, accessID, accessKey)
c.Assert(err, IsNil)
Expand Down Expand Up @@ -121,7 +122,7 @@ func (s *OssCopySuite) TestCopyRoutineWithoutRecovery(c *C) {
os.Remove(newFile)

// Does not specify parameter 'routines', by default it's single routine
err = s.bucket.CopyFile(bucketName, srcObjectName, destObjectName, 100*1024)
err = s.bucket.CopyFile(s.bucket.BucketName, srcObjectName, destObjectName, 100*1024)
c.Assert(err, IsNil)

err = s.bucket.GetObjectToFile(destObjectName, newFile)
Expand All @@ -136,7 +137,7 @@ func (s *OssCopySuite) TestCopyRoutineWithoutRecovery(c *C) {
os.Remove(newFile)

// Specify one routine.
err = s.bucket.CopyFile(bucketName, srcObjectName, destObjectName, 100*1024, Routines(1))
err = s.bucket.CopyFile(s.bucket.BucketName, srcObjectName, destObjectName, 100*1024, Routines(1))
c.Assert(err, IsNil)

err = s.bucket.GetObjectToFile(destObjectName, newFile)
Expand All @@ -151,7 +152,7 @@ func (s *OssCopySuite) TestCopyRoutineWithoutRecovery(c *C) {
os.Remove(newFile)

// Specify three routines, which is less than parts count 5
err = s.bucket.CopyFile(bucketName, srcObjectName, destObjectName, 100*1024, Routines(3))
err = s.bucket.CopyFile(s.bucket.BucketName, srcObjectName, destObjectName, 100*1024, Routines(3))
c.Assert(err, IsNil)

err = s.bucket.GetObjectToFile(destObjectName, newFile)
Expand All @@ -166,7 +167,7 @@ func (s *OssCopySuite) TestCopyRoutineWithoutRecovery(c *C) {
os.Remove(newFile)

// Specify 5 routines which is the same as parts count
err = s.bucket.CopyFile(bucketName, srcObjectName, destObjectName, 100*1024, Routines(5))
err = s.bucket.CopyFile(s.bucket.BucketName, srcObjectName, destObjectName, 100*1024, Routines(5))
c.Assert(err, IsNil)

err = s.bucket.GetObjectToFile(destObjectName, newFile)
Expand All @@ -181,7 +182,7 @@ func (s *OssCopySuite) TestCopyRoutineWithoutRecovery(c *C) {
os.Remove(newFile)

// Specify routine count 10, which is more than parts count
err = s.bucket.CopyFile(bucketName, srcObjectName, destObjectName, 100*1024, Routines(10))
err = s.bucket.CopyFile(s.bucket.BucketName, srcObjectName, destObjectName, 100*1024, Routines(10))
c.Assert(err, IsNil)

err = s.bucket.GetObjectToFile(destObjectName, newFile)
Expand All @@ -196,7 +197,7 @@ func (s *OssCopySuite) TestCopyRoutineWithoutRecovery(c *C) {
os.Remove(newFile)

// Invalid routine count, will use single routine
err = s.bucket.CopyFile(bucketName, srcObjectName, destObjectName, 100*1024, Routines(-1))
err = s.bucket.CopyFile(s.bucket.BucketName, srcObjectName, destObjectName, 100*1024, Routines(-1))
c.Assert(err, IsNil)

err = s.bucket.GetObjectToFile(destObjectName, newFile)
Expand All @@ -211,7 +212,7 @@ func (s *OssCopySuite) TestCopyRoutineWithoutRecovery(c *C) {
os.Remove(newFile)

// Option
err = s.bucket.CopyFile(bucketName, srcObjectName, destObjectName, 100*1024, Routines(3), Meta("myprop", "mypropval"))
err = s.bucket.CopyFile(s.bucket.BucketName, srcObjectName, destObjectName, 100*1024, Routines(3), Meta("myprop", "mypropval"))

meta, err := s.bucket.GetObjectDetailedMeta(destObjectName)
c.Assert(err, IsNil)
Expand Down Expand Up @@ -253,7 +254,7 @@ func (s *OssCopySuite) TestCopyRoutineWithoutRecoveryNegative(c *C) {

copyPartHooker = CopyErrorHooker
// Worker routine errors
err = s.bucket.CopyFile(bucketName, srcObjectName, destObjectName, 100*1024, Routines(2))
err = s.bucket.CopyFile(s.bucket.BucketName, srcObjectName, destObjectName, 100*1024, Routines(2))

c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "ErrorHooker")
Expand All @@ -264,13 +265,13 @@ func (s *OssCopySuite) TestCopyRoutineWithoutRecoveryNegative(c *C) {
c.Assert(err, NotNil)

// Target object does not exist
err = s.bucket.CopyFile(bucketName, "notexist", destObjectName, 100*1024, Routines(2))
err = s.bucket.CopyFile(s.bucket.BucketName, "notexist", destObjectName, 100*1024, Routines(2))

// The part size is invalid
err = s.bucket.CopyFile(bucketName, srcObjectName, destObjectName, 1024, Routines(2))
err = s.bucket.CopyFile(s.bucket.BucketName, srcObjectName, destObjectName, 1024, Routines(2))
c.Assert(err, NotNil)

err = s.bucket.CopyFile(bucketName, srcObjectName, destObjectName, 1024*1024*1024*100, Routines(2))
err = s.bucket.CopyFile(s.bucket.BucketName, srcObjectName, destObjectName, 1024*1024*1024*100, Routines(2))
c.Assert(err, NotNil)

// Delete the source file
Expand All @@ -294,7 +295,7 @@ func (s *OssCopySuite) TestCopyRoutineWithRecovery(c *C) {
// Copy object with checkpoint enabled, single runtine.
// Copy 4 parts---the CopyErrorHooker makes sure the copy of part 5 will fail.
copyPartHooker = CopyErrorHooker
err = s.bucket.CopyFile(bucketName, srcObjectName, destObjectName, 1024*100, Checkpoint(true, destObjectName+".cp"))
err = s.bucket.CopyFile(s.bucket.BucketName, srcObjectName, destObjectName, 1024*100, Checkpoint(true, destObjectName+".cp"))
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "ErrorHooker")
copyPartHooker = defaultCopyPartHook
Expand All @@ -305,9 +306,9 @@ func (s *OssCopySuite) TestCopyRoutineWithRecovery(c *C) {
c.Assert(err, IsNil)
c.Assert(ccp.Magic, Equals, copyCpMagic)
c.Assert(len(ccp.MD5), Equals, len("LC34jZU5xK4hlxi3Qn3XGQ=="))
c.Assert(ccp.SrcBucketName, Equals, bucketName)
c.Assert(ccp.SrcBucketName, Equals, s.bucket.BucketName)
c.Assert(ccp.SrcObjectKey, Equals, srcObjectName)
c.Assert(ccp.DestBucketName, Equals, bucketName)
c.Assert(ccp.DestBucketName, Equals, s.bucket.BucketName)
c.Assert(ccp.DestObjectKey, Equals, destObjectName)
c.Assert(len(ccp.CopyID), Equals, len("3F79722737D1469980DACEDCA325BB52"))
c.Assert(ccp.ObjStat.Size, Equals, int64(482048))
Expand All @@ -318,7 +319,7 @@ func (s *OssCopySuite) TestCopyRoutineWithRecovery(c *C) {
c.Assert(ccp.PartStat[4], Equals, false)

// Second copy, finish the last part
err = s.bucket.CopyFile(bucketName, srcObjectName, destObjectName, 1024*100, Checkpoint(true, destObjectName+".cp"))
err = s.bucket.CopyFile(s.bucket.BucketName, srcObjectName, destObjectName, 1024*100, Checkpoint(true, destObjectName+".cp"))
c.Assert(err, IsNil)

err = s.bucket.GetObjectToFile(destObjectName, newFile)
Expand All @@ -337,7 +338,7 @@ func (s *OssCopySuite) TestCopyRoutineWithRecovery(c *C) {

//multicopy with empty checkpoint path
copyPartHooker = CopyErrorHooker
err = s.bucket.CopyFile(bucketName, srcObjectName, destObjectName, 1024*100, Checkpoint(true, ""))
err = s.bucket.CopyFile(s.bucket.BucketName, srcObjectName, destObjectName, 1024*100, Checkpoint(true, ""))
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "ErrorHooker")
copyPartHooker = defaultCopyPartHook
Expand All @@ -347,22 +348,22 @@ func (s *OssCopySuite) TestCopyRoutineWithRecovery(c *C) {

//multi copy with checkpoint dir
copyPartHooker = CopyErrorHooker
err = s.bucket.CopyFile(bucketName, srcObjectName, destObjectName, 1024*100, Routines(2), CheckpointDir(true, "./"))
err = s.bucket.CopyFile(s.bucket.BucketName, srcObjectName, destObjectName, 1024*100, Routines(2), CheckpointDir(true, "./"))
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "ErrorHooker")
copyPartHooker = defaultCopyPartHook

// Check CP
ccp = copyCheckpoint{}
cpConf := cpConfig{IsEnable: true, DirPath: "./"}
cpFilePath := getCopyCpFilePath(&cpConf, bucketName, srcObjectName, s.bucket.BucketName, destObjectName, "")
cpFilePath := getCopyCpFilePath(&cpConf, s.bucket.BucketName, srcObjectName, s.bucket.BucketName, destObjectName, "")
err = ccp.load(cpFilePath)
c.Assert(err, IsNil)
c.Assert(ccp.Magic, Equals, copyCpMagic)
c.Assert(len(ccp.MD5), Equals, len("LC34jZU5xK4hlxi3Qn3XGQ=="))
c.Assert(ccp.SrcBucketName, Equals, bucketName)
c.Assert(ccp.SrcBucketName, Equals, s.bucket.BucketName)
c.Assert(ccp.SrcObjectKey, Equals, srcObjectName)
c.Assert(ccp.DestBucketName, Equals, bucketName)
c.Assert(ccp.DestBucketName, Equals, s.bucket.BucketName)
c.Assert(ccp.DestObjectKey, Equals, destObjectName)
c.Assert(len(ccp.CopyID), Equals, len("3F79722737D1469980DACEDCA325BB52"))
c.Assert(ccp.ObjStat.Size, Equals, int64(482048))
Expand All @@ -373,7 +374,7 @@ func (s *OssCopySuite) TestCopyRoutineWithRecovery(c *C) {
c.Assert(ccp.PartStat[4], Equals, false)

// Second copy, finish the last part.
err = s.bucket.CopyFile(bucketName, srcObjectName, destObjectName, 1024*100, Routines(2), CheckpointDir(true, "./"))
err = s.bucket.CopyFile(s.bucket.BucketName, srcObjectName, destObjectName, 1024*100, Routines(2), CheckpointDir(true, "./"))
c.Assert(err, IsNil)

err = s.bucket.GetObjectToFile(destObjectName, newFile)
Expand All @@ -391,7 +392,7 @@ func (s *OssCopySuite) TestCopyRoutineWithRecovery(c *C) {
c.Assert(err, NotNil)

// First copy without error.
err = s.bucket.CopyFile(bucketName, srcObjectName, destObjectName, 1024*100, Routines(3), Checkpoint(true, destObjectName+".cp"))
err = s.bucket.CopyFile(s.bucket.BucketName, srcObjectName, destObjectName, 1024*100, Routines(3), Checkpoint(true, destObjectName+".cp"))
c.Assert(err, IsNil)

err = s.bucket.GetObjectToFile(destObjectName, newFile)
Expand All @@ -406,7 +407,7 @@ func (s *OssCopySuite) TestCopyRoutineWithRecovery(c *C) {
os.Remove(newFile)

// Copy with multiple coroutines, no errors.
err = s.bucket.CopyFile(bucketName, srcObjectName, destObjectName, 1024*100, Routines(10), Checkpoint(true, destObjectName+".cp"))
err = s.bucket.CopyFile(s.bucket.BucketName, srcObjectName, destObjectName, 1024*100, Routines(10), Checkpoint(true, destObjectName+".cp"))
c.Assert(err, IsNil)

err = s.bucket.GetObjectToFile(destObjectName, newFile)
Expand All @@ -421,7 +422,7 @@ func (s *OssCopySuite) TestCopyRoutineWithRecovery(c *C) {
os.Remove(newFile)

// Option
err = s.bucket.CopyFile(bucketName, srcObjectName, destObjectName, 1024*100, Routines(5), Checkpoint(true, destObjectName+".cp"), Meta("myprop", "mypropval"))
err = s.bucket.CopyFile(s.bucket.BucketName, srcObjectName, destObjectName, 1024*100, Routines(5), Checkpoint(true, destObjectName+".cp"), Meta("myprop", "mypropval"))
c.Assert(err, IsNil)

meta, err := s.bucket.GetObjectDetailedMeta(destObjectName)
Expand Down Expand Up @@ -455,20 +456,20 @@ func (s *OssCopySuite) TestCopyRoutineWithRecoveryNegative(c *C) {
c.Assert(err, NotNil)

// Source object does not exist
err = s.bucket.CopyFile(bucketName, "notexist", destObjectName, 100*1024, Routines(2), Checkpoint(true, destObjectName+".cp"))
err = s.bucket.CopyFile(s.bucket.BucketName, "notexist", destObjectName, 100*1024, Routines(2), Checkpoint(true, destObjectName+".cp"))
c.Assert(err, NotNil)

// Specify part size is invalid.
err = s.bucket.CopyFile(bucketName, srcObjectName, destObjectName, 1024, Checkpoint(true, destObjectName+".cp"))
err = s.bucket.CopyFile(s.bucket.BucketName, srcObjectName, destObjectName, 1024, Checkpoint(true, destObjectName+".cp"))
c.Assert(err, NotNil)

err = s.bucket.CopyFile(bucketName, srcObjectName, destObjectName, 1024*1024*1024*100, Routines(2), Checkpoint(true, destObjectName+".cp"))
err = s.bucket.CopyFile(s.bucket.BucketName, srcObjectName, destObjectName, 1024*1024*1024*100, Routines(2), Checkpoint(true, destObjectName+".cp"))
c.Assert(err, NotNil)
}

// TestCopyFileCrossBucket is a cross bucket's direct copy.
func (s *OssCopySuite) TestCopyFileCrossBucket(c *C) {
destBucketName := bucketName + "-desc"
destBucketName := s.bucket.BucketName + "-cross-b"
srcObjectName := objectNamePrefix + RandStr(8)
destObjectName := srcObjectName + "-dest"
fileName := "../sample/BingWallpaper-2015-11-07.jpg"
Expand All @@ -486,7 +487,7 @@ func (s *OssCopySuite) TestCopyFileCrossBucket(c *C) {
os.Remove(newFile)

// Copy files
err = destBucket.CopyFile(bucketName, srcObjectName, destObjectName, 1024*100, Routines(5), Checkpoint(true, destObjectName+".cp"))
err = destBucket.CopyFile(s.bucket.BucketName, srcObjectName, destObjectName, 1024*100, Routines(5), Checkpoint(true, destObjectName+".cp"))
c.Assert(err, IsNil)

err = destBucket.GetObjectToFile(destObjectName, newFile)
Expand All @@ -501,7 +502,7 @@ func (s *OssCopySuite) TestCopyFileCrossBucket(c *C) {
os.Remove(newFile)

// Copy file with options
err = destBucket.CopyFile(bucketName, srcObjectName, destObjectName, 1024*100, Routines(10), Checkpoint(true, "copy.cp"), Meta("myprop", "mypropval"))
err = destBucket.CopyFile(s.bucket.BucketName, srcObjectName, destObjectName, 1024*100, Routines(10), Checkpoint(true, "copy.cp"), Meta("myprop", "mypropval"))
c.Assert(err, IsNil)

err = destBucket.GetObjectToFile(destObjectName, newFile)
Expand Down Expand Up @@ -611,7 +612,7 @@ func (s *OssCopySuite) TestVersioningCopyFileCrossBucket(c *C) {

// TestCopyFileChoiceOptions
func (s *OssCopySuite) TestCopyFileChoiceOptions(c *C) {
destBucketName := bucketName + "-desc"
destBucketName := s.bucket.BucketName + "-desc"
srcObjectName := objectNamePrefix + RandStr(8)
destObjectName := srcObjectName + "-dest"
fileName := "../sample/BingWallpaper-2015-11-07.jpg"
Expand Down Expand Up @@ -639,7 +640,7 @@ func (s *OssCopySuite) TestCopyFileChoiceOptions(c *C) {
}

// Copy files
err = destBucket.CopyFile(bucketName, srcObjectName, destObjectName, 1024*100, options...)
err = destBucket.CopyFile(s.bucket.BucketName, srcObjectName, destObjectName, 1024*100, options...)
c.Assert(err, IsNil)

// check object
Expand Down Expand Up @@ -667,7 +668,7 @@ func (s *OssCopySuite) TestCopyFileChoiceOptions(c *C) {
Checkpoint(true, "copy.cp"), // with checkpoint
}

err = destBucket.CopyFile(bucketName, srcObjectName, destObjectName, 1024*100, options...)
err = destBucket.CopyFile(s.bucket.BucketName, srcObjectName, destObjectName, 1024*100, options...)
c.Assert(err, IsNil)

// check object
Expand Down
Loading

0 comments on commit 3413376

Please sign in to comment.