Stream object responses with known size bounds
This commit is contained in:
@@ -211,7 +211,7 @@ func TestS3BackendReadReturnsOpenedObjectMetadata(t *testing.T) {
|
||||
if readErr != nil || closeErr != nil {
|
||||
t.Fatalf("read body error=%v close error=%v", readErr, closeErr)
|
||||
}
|
||||
if info.Key != "sessions/control.json" || info.Size != 5 || info.ETag != "generation" || info.LastModified == nil || !info.LastModified.Equal(lastModified) {
|
||||
if info.Key != "sessions/control.json" || info.Size != 5 || !info.SizeKnown || info.ETag != "generation" || info.LastModified == nil || !info.LastModified.Equal(lastModified) {
|
||||
t.Fatalf("Read() info = %#v, want opened object metadata", info)
|
||||
}
|
||||
if string(data) != "state" || client.lastGet == nil || *client.lastGet.Key != "sessions/control.json" {
|
||||
@@ -219,6 +219,31 @@ func TestS3BackendReadReturnsOpenedObjectMetadata(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestS3BackendReadDistinguishesZeroFromMissingSize(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
size *int64
|
||||
known bool
|
||||
}{
|
||||
{name: "zero", size: int64Ptr(0), known: true},
|
||||
{name: "missing"},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
client := &fakeS3API{getSize: tc.size}
|
||||
info, body, err := (&S3Backend{bucket: "bucket", client: client}).Read(context.Background(), "key")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := body.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if info.Size != 0 || info.SizeKnown != tc.known {
|
||||
t.Fatalf("info = %+v", info)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestS3BackendUploadAndExists(t *testing.T) {
|
||||
client := &fakeS3API{putOut: &s3.PutObjectOutput{ETag: strPtr(`"etag123"`)}}
|
||||
backend := &S3Backend{bucket: "bucket-1", client: client}
|
||||
|
||||
Reference in New Issue
Block a user