Mint - Add AWS SDK Go tests (#12097)

* Add aws-sdk-go tests: extend testListObjectVersionsSimple with error cases

* Add aws-sdk-go tests: extend testListMultipartUploads with error cases

Co-authored-by: Andre Bruch <ab@andrebruch.com>
Signed-off-by: Harshavardhana <harsha@minio.io>
This commit is contained in:
iternity-dotcom 2021-04-20 18:40:03 +02:00 committed by Harshavardhana
parent 445d080826
commit 046e8fd17e
2 changed files with 64 additions and 0 deletions

View File

@ -27,6 +27,8 @@ import (
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
)
@ -177,6 +179,45 @@ func testListObjectVersionsSimple() {
return
}
// Error cases
// bucket-listobjects-handlers.go > ListObjectVersionsHandler > listObjectVersions
lovInput := &s3.ListObjectVersionsInput{
Bucket: aws.String(bucket),
VersionIdMarker: aws.String("test"),
}
result, err = s3Client.ListObjectVersions(lovInput)
if err == nil {
failureLog(function, args, startTime, "", fmt.Sprintf("ListObjectVersions expected to fail but got %v", err), err).Fatal()
return
}
// bucket-listobjects-handlers.go > ListObjectVersionsHandler > validateListObjectsArgs
lovInput.EncodingType = aws.String("test")
result, err = s3Client.ListObjectVersions(lovInput)
if err == nil {
failureLog(function, args, startTime, "", fmt.Sprintf("ListObjectVersions expected to fail but got %v", err), err).Fatal()
return
}
// Second client
creds := credentials.NewStaticCredentials("test", "test", "")
newSession, err := session.NewSession()
if err != nil {
failureLog(function, args, startTime, "", fmt.Sprintf("NewSession expected to succeed but got %v", err), err).Fatal()
return
}
s3Config := s3Client.Config
s3Config.Credentials = creds
s3ClientTest := s3.New(newSession, &s3Config)
// Check with a second client: bucket-listobjects-handlers.go > ListObjectVersionsHandler > checkRequestAuthType
result, err = s3ClientTest.ListObjectVersions(lovInput)
if err == nil {
failureLog(function, args, startTime, "", fmt.Sprintf("ListObjectVersions expected to fail but got %v", err), err).Fatal()
return
}
successLogger(function, args, startTime).Info()
}

View File

@ -951,6 +951,29 @@ func testListMultipartUploads(s3Client *s3.S3) {
return
}
// Error cases
// MaxParts < 0
lpInput := &s3.ListPartsInput{
Bucket: aws.String(bucket),
Key: aws.String(object),
UploadId: multipartUpload.UploadId,
MaxParts: aws.Int64(-1),
}
listParts, err = s3Client.ListParts(lpInput)
if err == nil {
failureLog(function, args, startTime, "", "AWS SDK Go ListPartsInput API (MaxParts < 0) failed for", err).Fatal()
return
}
// PartNumberMarker < 0
lpInput.PartNumberMarker = aws.Int64(-1)
listParts, err = s3Client.ListParts(lpInput)
if err == nil {
failureLog(function, args, startTime, "", "AWS SDK Go ListPartsInput API (PartNumberMarker < 0) failed for", err).Fatal()
return
}
successLogger(function, args, startTime).Info()
}