Updating download function to use reader rather than casting everything into bytes
diff --git a/openstack/objectstorage/v1/objects/requests_test.go b/openstack/objectstorage/v1/objects/requests_test.go
index 7ab40f2..3935e1b 100644
--- a/openstack/objectstorage/v1/objects/requests_test.go
+++ b/openstack/objectstorage/v1/objects/requests_test.go
@@ -2,6 +2,7 @@
import (
"bytes"
+ "io"
"testing"
"github.com/rackspace/gophercloud/pagination"
@@ -9,14 +10,30 @@
fake "github.com/rackspace/gophercloud/testhelper/client"
)
-func TestDownloadObject(t *testing.T) {
+func TestDownloadReader(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleDownloadObjectSuccessfully(t)
- content, err := Download(fake.ServiceClient(), "testContainer", "testObject", nil).ExtractContent()
+ response := Download(fake.ServiceClient(), "testContainer", "testObject", nil)
+
+ // Check reader
+ buf := bytes.NewBuffer(make([]byte, 0))
+ io.CopyN(buf, response.Body, 10)
+ th.CheckEquals(t, "Successful", string(buf.Bytes()))
+}
+
+func TestDownloadExtraction(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleDownloadObjectSuccessfully(t)
+
+ response := Download(fake.ServiceClient(), "testContainer", "testObject", nil)
+
+ // Check []byte extraction
+ bytes, err := response.ExtractContent()
th.AssertNoErr(t, err)
- th.CheckEquals(t, string(content), "Successful download with Gophercloud")
+ th.CheckEquals(t, "Successful download with Gophercloud", string(bytes))
}
func TestListObjectInfo(t *testing.T) {