@@ -1964,6 +1964,101 @@ func testObjectTaggingWithVersioning() {
19641964 logSuccess (testName , function , args , startTime )
19651965}
19661966
1967+ func testPutObjectWithAutoChecksums () {
1968+ // initialize logging params
1969+ startTime := time .Now ()
1970+ testName := getFuncName ()
1971+ function := "PutObject(bucketName, objectName, reader, size, opts)"
1972+ args := map [string ]interface {}{
1973+ "bucketName" : "" ,
1974+ "objectName" : "" ,
1975+ "opts" : "minio.PutObjectOptions{UserMetadata: metadata, Progress: progress}" ,
1976+ }
1977+
1978+ if ! isFullMode () {
1979+ logIgnored (testName , function , args , startTime , "Skipping functional tests for short/quick runs" )
1980+ return
1981+ }
1982+
1983+ c , err := NewClient (ClientConfig {TrailingHeaders : true })
1984+ if err != nil {
1985+ logError (testName , function , args , startTime , "" , "MinIO client object creation failed" , err )
1986+ return
1987+ }
1988+
1989+ // Generate a new random bucket name.
1990+ bucketName := randString (60 , rand .NewSource (time .Now ().UnixNano ()), "minio-go-test-" )
1991+ args ["bucketName" ] = bucketName
1992+
1993+ // Make a new bucket.
1994+ err = c .MakeBucket (context .Background (), bucketName , minio.MakeBucketOptions {Region : "us-east-1" })
1995+ if err != nil {
1996+ logError (testName , function , args , startTime , "" , "Make bucket failed" , err )
1997+ return
1998+ }
1999+
2000+ defer cleanupBucket (bucketName , c )
2001+ const testfile = "datafile-1.03-MB"
2002+ bufSize := dataFileMap [testfile ]
2003+
2004+ // Save the data
2005+ objectName := randString (60 , rand .NewSource (time .Now ().UnixNano ()), "" )
2006+ args ["objectName" ] = objectName
2007+ c .TraceOn (os .Stdout )
2008+
2009+ cmpChecksum := func (got , want string ) {
2010+ if want != got {
2011+ logError (testName , function , args , startTime , "" , "checksum mismatch" , fmt .Errorf ("want %s, got %s" , want , got ))
2012+ return
2013+ }
2014+ }
2015+
2016+ meta := map [string ]string {}
2017+ reader := getDataReader (testfile )
2018+ b , err := io .ReadAll (reader )
2019+ if err != nil {
2020+ logError (testName , function , args , startTime , "" , "Read failed" , err )
2021+ return
2022+ }
2023+ h := minio .ChecksumCRC64NVME .Hasher ()
2024+ h .Reset ()
2025+ h .Write (b )
2026+ // Upload the data without explicit checksum.
2027+ resp , err := c .PutObject (context .Background (), bucketName , objectName , bytes .NewReader (b ), int64 (bufSize ), minio.PutObjectOptions {
2028+ DisableMultipart : true ,
2029+ DisableContentSha256 : false ,
2030+ UserMetadata : meta ,
2031+ AutoChecksum : minio .ChecksumNone ,
2032+ Checksum : minio .ChecksumNone ,
2033+ })
2034+ _ = resp
2035+ if err != nil {
2036+ logError (testName , function , args , startTime , "" , "PutObject failed" , err )
2037+ return
2038+ }
2039+
2040+ // Read the metadata back
2041+ gopts := minio.GetObjectOptions {Checksum : true }
2042+ st , err := c .StatObject (context .Background (), bucketName , objectName , gopts )
2043+ if err != nil {
2044+ logError (testName , function , args , startTime , "" , "GetObject failed" , err )
2045+ return
2046+ }
2047+ if st .ChecksumCRC64NVME != "" {
2048+ meta [minio .ChecksumCRC64NVME .Key ()] = base64 .StdEncoding .EncodeToString (h .Sum (nil ))
2049+ cmpChecksum (st .ChecksumCRC64NVME , meta ["x-amz-checksum-crc64nvme" ])
2050+ if st .ChecksumMode != minio .ChecksumFullObjectMode .String () {
2051+ logError (testName , function , args , startTime , "" , "Checksum mode is not full object" , fmt .Errorf ("got %s, want %s" , st .ChecksumMode , minio .ChecksumFullObjectMode .String ()))
2052+ }
2053+ }
2054+ if st .Size != int64 (bufSize ) {
2055+ logError (testName , function , args , startTime , "" , "Number of bytes returned by PutObject does not match GetObject, expected " + string (bufSize )+ " got " + string (st .Size ), err )
2056+ return
2057+ }
2058+
2059+ logSuccess (testName , function , args , startTime )
2060+ }
2061+
19672062// Test PutObject with custom checksums.
19682063func testPutObjectWithChecksums () {
19692064 // initialize logging params
@@ -14685,6 +14780,7 @@ func main() {
1468514780 testPutObjectMetadataNonUSASCIIV2 ()
1468614781 testPutObjectNoLengthV2 ()
1468714782 testPutObjectsUnknownV2 ()
14783+ testPutObjectWithAutoChecksums ()
1468814784 testGetObjectContextV2 ()
1468914785 testFPutObjectContextV2 ()
1469014786 testFGetObjectContextV2 ()
0 commit comments