@@ -2,9 +2,11 @@ package integration_test
22
33import (
44 "bytes"
5+ "fmt"
56
67 "os"
78
9+ "github.com/aliyun/aliyun-oss-go-sdk/oss"
810 "github.com/cloudfoundry/storage-cli/alioss/config"
911 "github.com/cloudfoundry/storage-cli/alioss/integration"
1012
@@ -209,13 +211,16 @@ var _ = Describe("General testing for all Ali regions", func() {
209211 destBlob := blobName + "-dest"
210212
211213 defer func () {
212- cliSession , err := integration .RunCli (cliPath , configPath , "delete" , srcBlob )
213- Expect (err ).ToNot (HaveOccurred ())
214- Expect (cliSession .ExitCode ()).To (BeZero ())
215-
216- cliSession , err = integration .RunCli (cliPath , configPath , "delete" , destBlob )
217- Expect (err ).ToNot (HaveOccurred ())
218- Expect (cliSession .ExitCode ()).To (BeZero ())
214+ for _ , b := range []string {srcBlob , destBlob } {
215+ cliSession , err := integration .RunCli (cliPath , configPath , "delete" , b )
216+ if err != nil {
217+ GinkgoWriter .Printf ("cleanup: error deleting %s: %v\n " , b , err )
218+ continue
219+ }
220+ if cliSession .ExitCode () != 0 && cliSession .ExitCode () != 3 {
221+ GinkgoWriter .Printf ("cleanup: delete %s exited with code %d\n " , b , cliSession .ExitCode ())
222+ }
223+ }
219224 }()
220225
221226 contentFile = integration .MakeContentFile ("copied content" )
@@ -346,9 +351,81 @@ var _ = Describe("General testing for all Ali regions", func() {
346351 Expect (output ).To (ContainSubstring (blob2 ))
347352 Expect (output ).NotTo (ContainSubstring (otherBlob ))
348353 })
354+
355+ It ("lists all blobs across multiple pages" , func () {
356+ prefix := integration .GenerateRandomString ()
357+ const totalObjects = 120
358+
359+ var blobNames []string
360+ var contentFiles []string
361+
362+ for i := 0 ; i < totalObjects ; i ++ {
363+ blobName := fmt .Sprintf ("%s/%03d" , prefix , i )
364+ blobNames = append (blobNames , blobName )
365+
366+ contentFile := integration .MakeContentFile (fmt .Sprintf ("content-%d" , i ))
367+ contentFiles = append (contentFiles , contentFile )
368+
369+ cliSession , err := integration .RunCli (cliPath , configPath , "put" , contentFile , blobName )
370+ Expect (err ).ToNot (HaveOccurred ())
371+ Expect (cliSession .ExitCode ()).To (BeZero ())
372+ }
373+
374+ defer func () {
375+ for _ , f := range contentFiles {
376+ _ = os .Remove (f ) //nolint:errcheck
377+ }
378+
379+ for _ , b := range blobNames {
380+ cliSession , err := integration .RunCli (cliPath , configPath , "delete" , b )
381+ if err == nil && (cliSession .ExitCode () == 0 || cliSession .ExitCode () == 3 ) {
382+ continue
383+ }
384+ }
385+ }()
386+
387+ cliSession , err := integration .RunCli (cliPath , configPath , "list" , prefix )
388+ Expect (err ).ToNot (HaveOccurred ())
389+ Expect (cliSession .ExitCode ()).To (BeZero ())
390+
391+ output := bytes .NewBuffer (cliSession .Out .Contents ()).String ()
392+
393+ for _ , b := range blobNames {
394+ Expect (output ).To (ContainSubstring (b ))
395+ }
396+ })
349397 })
350398
351399 Describe ("Invoking `ensure-bucket-exists`" , func () {
400+ It ("creates a bucket that can be observed via the OSS API" , func () {
401+ newBucketName := bucketName + "-bommel"
402+
403+ cfg := defaultConfig
404+ cfg .BucketName = newBucketName
405+
406+ configPath = integration .MakeConfigFile (& cfg )
407+ defer func () { _ = os .Remove (configPath ) }() //nolint:errcheck
408+
409+ ossClient , err := oss .New (cfg .Endpoint , cfg .AccessKeyID , cfg .AccessKeySecret )
410+ Expect (err ).ToNot (HaveOccurred ())
411+
412+ defer func () {
413+ if err := ossClient .DeleteBucket (newBucketName ); err != nil {
414+ if _ , ferr := fmt .Fprintf (GinkgoWriter , "cleanup: failed to delete bucket %s: %v\n " , newBucketName , err ); ferr != nil {
415+ GinkgoWriter .Printf ("cleanup: failed to write cleanup message: %v\n " , ferr )
416+ }
417+ }
418+ }()
419+
420+ s1 , err := integration .RunCli (cliPath , configPath , "ensure-bucket-exists" )
421+ Expect (err ).ToNot (HaveOccurred ())
422+ Expect (s1 .ExitCode ()).To (BeZero ())
423+
424+ exists , err := ossClient .IsBucketExist (newBucketName )
425+ Expect (err ).ToNot (HaveOccurred ())
426+ Expect (exists ).To (BeTrue ())
427+ })
428+
352429 It ("is idempotent" , func () {
353430 s1 , err := integration .RunCli (cliPath , configPath , "ensure-bucket-exists" )
354431 Expect (err ).ToNot (HaveOccurred ())
0 commit comments