rax objects unit test; fix for creating object content
diff --git a/acceptance/rackspace/objectstorage/v1/common.go b/acceptance/rackspace/objectstorage/v1/common.go
index 0b4d170..6422203 100644
--- a/acceptance/rackspace/objectstorage/v1/common.go
+++ b/acceptance/rackspace/objectstorage/v1/common.go
@@ -1,4 +1,4 @@
-// +build acceptance rackspace
+// +build acceptance rackspace objectstorage v1
package v1
diff --git a/acceptance/rackspace/objectstorage/v1/containers_test.go b/acceptance/rackspace/objectstorage/v1/containers_test.go
index 1e8ee36..d22057b 100644
--- a/acceptance/rackspace/objectstorage/v1/containers_test.go
+++ b/acceptance/rackspace/objectstorage/v1/containers_test.go
@@ -1,4 +1,4 @@
-// +build acceptance rackspace
+// +build acceptance rackspace objectstorage v1
package v1
diff --git a/acceptance/rackspace/objectstorage/v1/objects_test.go b/acceptance/rackspace/objectstorage/v1/objects_test.go
index b7b1f99..749f6d3 100644
--- a/acceptance/rackspace/objectstorage/v1/objects_test.go
+++ b/acceptance/rackspace/objectstorage/v1/objects_test.go
@@ -1 +1,113 @@
+// +build acceptance rackspace objectstorage v1
+
package v1
+
+import (
+ "bytes"
+ "testing"
+
+ osObjects "github.com/rackspace/gophercloud/openstack/objectstorage/v1/objects"
+ "github.com/rackspace/gophercloud/pagination"
+ raxContainers "github.com/rackspace/gophercloud/rackspace/objectstorage/v1/containers"
+ raxObjects "github.com/rackspace/gophercloud/rackspace/objectstorage/v1/objects"
+ th "github.com/rackspace/gophercloud/testhelper"
+)
+
+func TestObjects(t *testing.T) {
+ c, err := createClient(t, false)
+ th.AssertNoErr(t, err)
+
+ _, err = raxContainers.Create(c, "gophercloud-test", nil).ExtractHeaders()
+ th.AssertNoErr(t, err)
+
+ defer func() {
+ _, err := raxContainers.Delete(c, "gophercloud-test").ExtractHeaders()
+ th.AssertNoErr(t, err)
+ }()
+
+ content := bytes.NewBufferString("Lewis Carroll")
+ options := &osObjects.CreateOpts{ContentType: "text/plain"}
+ _, err = raxObjects.Create(c, "gophercloud-test", "o1", content, options).ExtractHeaders()
+ th.AssertNoErr(t, err)
+ defer func() {
+ _, err := raxObjects.Delete(c, "gophercloud-test", "o1", nil).ExtractHeaders()
+ th.AssertNoErr(t, err)
+ }()
+
+ t.Logf("Objects Info available to the currently issued token:")
+ count := 0
+ err = raxObjects.List(c, "gophercloud-test", &osObjects.ListOpts{Full: true}).EachPage(func(page pagination.Page) (bool, error) {
+ t.Logf("--- Page %02d ---", count)
+
+ objects, err := raxObjects.ExtractInfo(page)
+ th.AssertNoErr(t, err)
+
+ for i, object := range objects {
+ t.Logf("[%02d] name=[%s]", i, object.Name)
+ t.Logf(" content-type=[%s]", object.ContentType)
+ t.Logf(" bytes=[%d]", object.Bytes)
+ t.Logf(" last-modified=[%s]", object.LastModified)
+ t.Logf(" hash=[%s]", object.Hash)
+ }
+
+ count++
+ return true, nil
+ })
+ th.AssertNoErr(t, err)
+ if count == 0 {
+ t.Errorf("No objects listed for your current token.")
+ }
+ t.Logf("Container Names available to the currently issued token:")
+ count = 0
+ err = raxObjects.List(c, "gophercloud-test", &osObjects.ListOpts{Full: false}).EachPage(func(page pagination.Page) (bool, error) {
+ t.Logf("--- Page %02d ---", count)
+
+ names, err := raxObjects.ExtractNames(page)
+ th.AssertNoErr(t, err)
+
+ for i, name := range names {
+ t.Logf("[%02d] %s", i, name)
+ }
+
+ count++
+ return true, nil
+ })
+ th.AssertNoErr(t, err)
+ if count == 0 {
+ t.Errorf("No objects listed for your current token.")
+ }
+
+ _, err = raxObjects.Copy(c, "gophercloud-test", "o1", &raxObjects.CopyOpts{Destination: "gophercloud-test/o2"}).ExtractHeaders()
+ th.AssertNoErr(t, err)
+ defer func() {
+ _, err := raxObjects.Delete(c, "gophercloud-test", "o2", nil).ExtractHeaders()
+ th.AssertNoErr(t, err)
+ }()
+
+ o1Content, err := raxObjects.Download(c, "gophercloud-test", "o1", nil).ExtractContent()
+ th.AssertNoErr(t, err)
+ o2Content, err := raxObjects.Download(c, "gophercloud-test", "o2", nil).ExtractContent()
+ th.AssertNoErr(t, err)
+ th.AssertEquals(t, string(o2Content), string(o1Content))
+
+ headers, err := raxObjects.Update(c, "gophercloud-test", "o2", osObjects.UpdateOpts{Metadata: map[string]string{"white": "mountains"}}).ExtractHeaders()
+ th.AssertNoErr(t, err)
+ t.Logf("Headers from Update Account request: %+v\n", headers)
+ defer func() {
+ _, err := raxObjects.Update(c, "gophercloud-test", "o2", osObjects.UpdateOpts{Metadata: map[string]string{"white": ""}}).ExtractHeaders()
+ th.AssertNoErr(t, err)
+ metadata, err := raxObjects.Get(c, "gophercloud-test", "o2", nil).ExtractMetadata()
+ th.AssertNoErr(t, err)
+ t.Logf("Metadata from Get Account request (after update reverted): %+v\n", metadata)
+ th.CheckEquals(t, metadata["White"], "")
+ }()
+
+ getResult := raxObjects.Get(c, "gophercloud-test", "o2", nil)
+ headers, err = getResult.ExtractHeaders()
+ th.AssertNoErr(t, err)
+ t.Logf("Headers from Get Account request (after update): %+v\n", headers)
+ metadata, err := getResult.ExtractMetadata()
+ th.AssertNoErr(t, err)
+ t.Logf("Metadata from Get Account request (after update): %+v\n", metadata)
+ th.CheckEquals(t, metadata["White"], "mountains")
+}