@@ -528,9 +528,10 @@ func TestIntegration_MRDCallbackReturnsDataLength(t *testing.T) {
528528func TestIntegration_MRDWithReadHandle (t * testing.T ) {
529529 multiTransportTest (skipAllButZonal (context .Background (), "Bidi Read API test" ), t , func (t * testing.T , ctx context.Context , bucket string , _ string , client * Client ) {
530530 const (
531- dataSize = 1000
532- offset = 0
533- limit = 100
531+ dataSize = 1000
532+ offset = 0
533+ limit = 100
534+ negativeOffset = - 200
534535 )
535536
536537 // Generate random content for testing.
@@ -562,7 +563,7 @@ func TestIntegration_MRDWithReadHandle(t *testing.T) {
562563 }
563564
564565 // Perform the read operation.
565- var res1 , res2 multiRangeDownloaderOutput
566+ var res1 , res2 , res3 , res4 multiRangeDownloaderOutput
566567 mrd .Add (& res1 .buf , offset , limit , func (x , y int64 , err error ) {
567568 res1 .offset = x
568569 res1 .limit = y
@@ -573,14 +574,28 @@ func TestIntegration_MRDWithReadHandle(t *testing.T) {
573574 res2 .limit = y
574575 res2 .err = err
575576 })
577+ mrd2 .Add (& res3 .buf , negativeOffset , limit , func (x , y int64 , err error ) {
578+ res3 .offset = x
579+ res3 .limit = y
580+ res3 .err = err
581+ })
582+ mrd2 .Add (& res4 .buf , negativeOffset , 0 , func (x , y int64 , err error ) {
583+ res4 .offset = x
584+ res4 .limit = y
585+ res4 .err = err
586+ })
576587
577588 mrd .Wait ()
578589 mrd2 .Wait ()
590+
579591 if res1 .err != nil {
580592 t .Fatalf ("mrd.Add callback returned error: %v" , res1 .err )
581593 }
582594 if res2 .err != nil {
583- t .Fatalf ("mrd2.Add callback returned error: %v" , res2 .err )
595+ t .Fatalf ("mrd2.Add callback returned error for res2: %v" , res2 .err )
596+ }
597+ if res3 .err != nil {
598+ t .Fatalf ("mrd2.Add callback returned error for res3: %v" , res3 .err )
584599 }
585600
586601 // Validate results for mrd with read handle.
@@ -593,6 +608,16 @@ func TestIntegration_MRDWithReadHandle(t *testing.T) {
593608 t .Errorf ("mrd2 downloaded content mismatch. got %d bytes, want %d bytes" , len (got ), len (want ))
594609 }
595610
611+ want = content [max (0 , dataSize + negativeOffset ):min (dataSize , max (0 , dataSize + negativeOffset )+ limit )]
612+ if got := res3 .buf .Bytes (); ! bytes .Equal (got , want ) {
613+ t .Errorf ("mrd2 downloaded content mismatch. got %v bytes, want %v bytes. %v" , got , want , content )
614+ }
615+
616+ want = content [max (0 , dataSize + negativeOffset ):]
617+ if got := res4 .buf .Bytes (); ! bytes .Equal (got , want ) {
618+ t .Errorf ("mrd2 downloaded content mismatch. got %v bytes, want %v bytes. %v" , got , want , content )
619+ }
620+
596621 if err := mrd .Close (); err != nil {
597622 t .Fatalf ("Error while closing reader: %v" , err )
598623 }
0 commit comments