From f9749638e3393f471d7e28362795689bf37cc023 Mon Sep 17 00:00:00 2001 From: Stefan Majewsky Date: Mon, 30 Apr 2018 14:14:56 +0200 Subject: revamp the LargeObject API I thought about this some more, and I believe the Writer-based approach in the previous version of the LargeObject API does not scale: It makes it very hard to write code that uploads segments without resorting to a buffer the same size as the segments. I don't want gigabyte-scale buffers filling up my RAM, so this commit switches to a different API based on Readers. LargeObject.Append() now behaves very similar to Object.Upload(), which I find quite nice. --- tests/object_test.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'tests/object_test.go') diff --git a/tests/object_test.go b/tests/object_test.go index 6291527..251db9f 100644 --- a/tests/object_test.go +++ b/tests/object_test.go @@ -51,7 +51,7 @@ func TestObjectLifecycle(t *testing.T) { err = o.Delete(nil, nil) expectError(t, err, "expected 204 response, got 404 instead:

Not Found

The resource could not be found.

") - err = o.Upload(bytes.NewReader([]byte("test")), nil) + err = o.Upload(bytes.NewReader([]byte("test")), nil, nil) expectSuccess(t, err) expectObjectExistence(t, o, true) @@ -66,31 +66,31 @@ func TestObjectUpload(t *testing.T) { //test upload with bytes.Reader obj := c.Object("upload1") - err := obj.Upload(bytes.NewReader(objectExampleContent), nil) + err := obj.Upload(bytes.NewReader(objectExampleContent), nil, nil) expectSuccess(t, err) expectObjectContent(t, obj, objectExampleContent) //test upload with bytes.Buffer obj = c.Object("upload2") - err = obj.Upload(bytes.NewBuffer(objectExampleContent), nil) + err = obj.Upload(bytes.NewBuffer(objectExampleContent), nil, nil) expectSuccess(t, err) expectObjectContent(t, obj, objectExampleContent) //test upload with strings.Reader obj = c.Object("upload3") - err = obj.Upload(strings.NewReader(string(objectExampleContent)), nil) + err = obj.Upload(strings.NewReader(string(objectExampleContent)), nil, nil) expectSuccess(t, err) expectObjectContent(t, obj, objectExampleContent) //test upload with opaque io.Reader obj = c.Object("upload4") - err = obj.Upload(opaqueReader{bytes.NewReader(objectExampleContent)}, nil) + err = obj.Upload(opaqueReader{bytes.NewReader(objectExampleContent)}, nil, nil) expectSuccess(t, err) expectObjectContent(t, obj, objectExampleContent) //test upload with io.Writer obj = c.Object("upload5") - err = obj.UploadWithWriter(nil, func(w io.Writer) error { + err = obj.UploadWithWriter(nil, nil, func(w io.Writer) error { _, err := w.Write(objectExampleContent) return err }) @@ -99,13 +99,13 @@ func TestObjectUpload(t *testing.T) { //test upload with empty reader (should create zero-byte-sized object) obj = c.Object("upload6") - err = obj.Upload(eofReader{}, nil) + err = obj.Upload(eofReader{}, nil, nil) expectSuccess(t, err) expectObjectContent(t, obj, nil) //test upload without reader (should create zero-byte-sized object) obj = c.Object("upload7") - err = obj.Upload(nil, nil) + err = obj.Upload(nil, nil, nil) expectSuccess(t, err) expectObjectContent(t, obj, nil) }) @@ -129,7 +129,7 @@ func TestObjectDownload(t *testing.T) { testWithContainer(t, func(c *schwift.Container) { //upload example object obj := c.Object("example") - err := obj.Upload(bytes.NewReader(objectExampleContent), nil) + err := obj.Upload(bytes.NewReader(objectExampleContent), nil, nil) expectSuccess(t, err) //test download as string @@ -170,7 +170,7 @@ func TestObjectUpdate(t *testing.T) { expectError(t, err, "expected 202 response, got 404 instead:

Not Found

The resource could not be found.

") //create object - err = obj.Upload(nil, nil) + err = obj.Upload(nil, nil, nil) expectSuccess(t, err) hdr, err := obj.Headers() @@ -190,7 +190,7 @@ func TestObjectUpdate(t *testing.T) { func TestObjectCopyMove(t *testing.T) { testWithContainer(t, func(c *schwift.Container) { obj1 := c.Object("location1") - err := obj1.Upload(bytes.NewReader(objectExampleContent), nil) + err := obj1.Upload(bytes.NewReader(objectExampleContent), nil, nil) expectSuccess(t, err) expectObjectExistence(t, obj1, true) -- cgit v1.2.3