@@ -1876,24 +1876,24 @@ func TestIntegration_WriterCRC32CValidation(t *testing.T) {
18761876 },
18771877 {
18781878 name : "resumable with user-sent CRC32C" ,
1879- content : bytes .Repeat ([]byte ("a" ), 1024 * 1024 ),
1879+ content : bytes .Repeat ([]byte ("a" ), 1 * MiB ),
18801880 chunkSize : 256 * 1024 ,
18811881 sendCrc32c : true ,
18821882 },
18831883 {
18841884 name : "resumable with default CRC32" ,
1885- content : bytes .Repeat ([]byte ("a" ), 1024 * 1024 ),
1885+ content : bytes .Repeat ([]byte ("a" ), 1 * MiB ),
18861886 chunkSize : 256 * 1024 ,
18871887 },
18881888 {
18891889 name : "resumable with disabled auto checksum" ,
1890- content : bytes .Repeat ([]byte ("a" ), 1024 * 1024 ),
1890+ content : bytes .Repeat ([]byte ("a" ), 1 * MiB ),
18911891 chunkSize : 256 * 1024 ,
18921892 disableAutoChecksum : true ,
18931893 },
18941894 {
18951895 name : "resumable with incorrect checksum" ,
1896- content : bytes .Repeat ([]byte ("a" ), 1024 * 1024 ),
1896+ content : bytes .Repeat ([]byte ("a" ), 1 * MiB ),
18971897 chunkSize : 256 * 1024 ,
18981898 sendCrc32c : true ,
18991899 incorrectChecksum : true ,
@@ -3388,6 +3388,7 @@ func TestIntegration_WriterAppend(t *testing.T) {
33883388 flushOffset int64
33893389 sendCRC bool
33903390 disableAutoChecksum bool
3391+ incorrectChecksum bool
33913392 }{
33923393 {
33933394 name : "finalized_object" ,
@@ -3412,6 +3413,13 @@ func TestIntegration_WriterAppend(t *testing.T) {
34123413 disableAutoChecksum : true ,
34133414 flushOffset : - 1 , // no flush
34143415 },
3416+ {
3417+ name : "finalized_object with incorrect checksum" ,
3418+ finalize : true ,
3419+ content : randomBytes9MiB ,
3420+ chunkSize : 4 * MiB ,
3421+ incorrectChecksum : true ,
3422+ },
34153423 {
34163424 name : "unfinalized_object" ,
34173425 finalize : false ,
@@ -3462,6 +3470,20 @@ func TestIntegration_WriterAppend(t *testing.T) {
34623470 w .CRC32C = crc32 .Checksum (tc .content , crc32cTable )
34633471 content := tc .content
34643472
3473+ // If incorrectChecksum is true, write data and close writer
3474+ // immediately to validate if writer returns error
3475+ if tc .incorrectChecksum {
3476+ w .CRC32C ++ // simulate incorrect checksum
3477+ w .SendCRC32C = true
3478+ if _ , err := w .Write (content ); err != nil {
3479+ t .Fatalf ("writer.Write: %v" , err )
3480+ }
3481+ if err := w .Close (); ! incorrectChecksumError (err ) {
3482+ t .Fatalf ("expected an InvalidArgument error for incorrect checksum, but got %v" , err )
3483+ }
3484+ return
3485+ }
3486+
34653487 // If flushOffset is 0, just do a flush and check the attributes.
34663488 if tc .flushOffset == 0 {
34673489 if _ , err := w .Flush (); err != nil {
0 commit comments