Skip to content

Commit

Permalink
test: add object reader test
Browse files Browse the repository at this point in the history
  • Loading branch information
jobstoit committed Apr 27, 2024
1 parent 55e38bb commit 22606c2
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions feature/s3/manager/reader_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package manager_test

import (
"context"
"io"
"reflect"
"testing"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/feature/s3/manager"
"github.com/aws/aws-sdk-go-v2/service/s3"
)

func TestObjectReader(t *testing.T) {
c, invocations, ranges := newDownloadRangeClient(buf12MB)

d := manager.NewDownloader(c, func(d *manager.Downloader) {
d.Concurrency = 1
})

rd := d.NewReader(context.Background(), &s3.GetObjectInput{
Bucket: aws.String("bucket"),
Key: aws.String("key"),
})

n, err := io.Copy(io.Discard, rd)
if err != nil {
t.Fatalf("expected no error, got %v", err)
}

if e, a := int64(len(buf12MB)), n; e != a {
t.Errorf("expected %d buffer length, got %d", e, a)
}

if e, a := 4, *invocations; e != a {
t.Errorf("expect %v API calls, got %v", e, a)
}

expectRngs := []string{"bytes=0-0", "bytes=0-5242880", "bytes=5242881-10485761", "bytes=10485762-12582912"}
if e, a := expectRngs, *ranges; !reflect.DeepEqual(e, a) {
t.Errorf("expect %v ranges, got %v", e, a)
}
}

0 comments on commit 22606c2

Please sign in to comment.