Objects consistency updates
diff --git a/openstack/objectstorage/v1/objects/requests.go b/openstack/objectstorage/v1/objects/requests.go
index bc21496..15ec5c7 100644
--- a/openstack/objectstorage/v1/objects/requests.go
+++ b/openstack/objectstorage/v1/objects/requests.go
@@ -28,7 +28,7 @@
func List(c *gophercloud.ServiceClient, containerName string, opts *ListOpts) pagination.Pager {
var headers map[string]string
- url := containerURL(c, containerName)
+ url := listURL(c, containerName)
if opts != nil {
query, err := gophercloud.BuildQueryString(opts)
if err != nil {
@@ -73,7 +73,7 @@
func Download(c *gophercloud.ServiceClient, containerName, objectName string, opts *DownloadOpts) DownloadResult {
var res DownloadResult
- url := objectURL(c, containerName, objectName)
+ url := downloadURL(c, containerName, objectName)
h := c.Provider.AuthenticatedHeaders()
if opts != nil {
@@ -129,7 +129,7 @@
var res CreateResult
var reqBody []byte
- url := objectURL(c, containerName, objectName)
+ url := createURL(c, containerName, objectName)
h := c.Provider.AuthenticatedHeaders()
if opts != nil {
@@ -206,7 +206,7 @@
h["X-Object-Meta-"+k] = v
}
- url := objectURL(c, containerName, objectName)
+ url := copyURL(c, containerName, objectName)
resp, err := perigee.Request("COPY", url, perigee.Options{
MoreHeaders: h,
OkCodes: []int{201},
@@ -223,7 +223,7 @@
// Delete is a function that deletes an object.
func Delete(c *gophercloud.ServiceClient, containerName, objectName string, opts *DeleteOpts) DeleteResult {
var res DeleteResult
- url := objectURL(c, containerName, objectName)
+ url := deleteURL(c, containerName, objectName)
if opts != nil {
query, err := gophercloud.BuildQueryString(opts)
@@ -253,7 +253,7 @@
// metadata, pass the GetResult response to the ExtractMetadata function.
func Get(c *gophercloud.ServiceClient, containerName, objectName string, opts *GetOpts) GetResult {
var res GetResult
- url := objectURL(c, containerName, objectName)
+ url := getURL(c, containerName, objectName)
if opts != nil {
query, err := gophercloud.BuildQueryString(opts)
@@ -306,7 +306,7 @@
}
}
- url := objectURL(c, containerName, objectName)
+ url := updateURL(c, containerName, objectName)
resp, err := perigee.Request("POST", url, perigee.Options{
MoreHeaders: h,
OkCodes: []int{202},
diff --git a/openstack/objectstorage/v1/objects/results.go b/openstack/objectstorage/v1/objects/results.go
index f7db3ed..1dda7a3 100644
--- a/openstack/objectstorage/v1/objects/results.go
+++ b/openstack/objectstorage/v1/objects/results.go
@@ -3,11 +3,12 @@
import (
"fmt"
"io/ioutil"
- "net/http"
"strings"
- "github.com/mitchellh/mapstructure"
+ objectstorage "github.com/rackspace/gophercloud/openstack/objectstorage/v1"
"github.com/rackspace/gophercloud/pagination"
+
+ "github.com/mitchellh/mapstructure"
)
// Object is a structure that holds information related to a storage object.
@@ -97,7 +98,7 @@
// DownloadResult is a *http.Response that is returned from a call to the Download function.
type DownloadResult struct {
- commonResult
+ objectstorage.CommonResult
}
// ExtractContent is a function that takes a DownloadResult (of type *http.Response)
@@ -117,7 +118,7 @@
// GetResult is a *http.Response that is returned from a call to the Get function.
type GetResult struct {
- commonResult
+ objectstorage.CommonResult
}
// ExtractMetadata is a function that takes a GetResult (of type *http.Response)
@@ -136,36 +137,22 @@
return metadata, nil
}
-type commonResult struct {
- Resp *http.Response
- Err error
-}
-
-func (cr commonResult) ExtractHeaders() (http.Header, error) {
- var headers http.Header
- if cr.Err != nil {
- return headers, cr.Err
- }
-
- return cr.Resp.Header, nil
-}
-
// CreateResult represents the result of a create operation.
type CreateResult struct {
- commonResult
+ objectstorage.CommonResult
}
// UpdateResult represents the result of an update operation.
type UpdateResult struct {
- commonResult
+ objectstorage.CommonResult
}
// DeleteResult represents the result of a delete operation.
type DeleteResult struct {
- commonResult
+ objectstorage.CommonResult
}
// CopyResult represents the result of a copy operation.
type CopyResult struct {
- commonResult
+ objectstorage.CommonResult
}
diff --git a/openstack/objectstorage/v1/objects/urls.go b/openstack/objectstorage/v1/objects/urls.go
index a377960..d2ec62c 100644
--- a/openstack/objectstorage/v1/objects/urls.go
+++ b/openstack/objectstorage/v1/objects/urls.go
@@ -1,13 +1,33 @@
package objects
-import "github.com/rackspace/gophercloud"
+import (
+ "github.com/rackspace/gophercloud"
+)
-// objectURL returns the URI for making Object requests.
-func objectURL(c *gophercloud.ServiceClient, container, object string) string {
+func listURL(c *gophercloud.ServiceClient, container string) string {
+ return c.ServiceURL(container)
+}
+
+func copyURL(c *gophercloud.ServiceClient, container, object string) string {
return c.ServiceURL(container, object)
}
-// containerURL returns the URI for making Container requests.
-func containerURL(c *gophercloud.ServiceClient, container string) string {
- return c.ServiceURL(container)
+func createURL(c *gophercloud.ServiceClient, container, object string) string {
+ return copyURL(c, container, object)
+}
+
+func getURL(c *gophercloud.ServiceClient, container, object string) string {
+ return copyURL(c, container, object)
+}
+
+func deleteURL(c *gophercloud.ServiceClient, container, object string) string {
+ return copyURL(c, container, object)
+}
+
+func downloadURL(c *gophercloud.ServiceClient, container, object string) string {
+ return copyURL(c, container, object)
+}
+
+func updateURL(c *gophercloud.ServiceClient, container, object string) string {
+ return copyURL(c, container, object)
}
diff --git a/openstack/objectstorage/v1/objects/urls_test.go b/openstack/objectstorage/v1/objects/urls_test.go
index 89d1cb1..1dcfe35 100644
--- a/openstack/objectstorage/v1/objects/urls_test.go
+++ b/openstack/objectstorage/v1/objects/urls_test.go
@@ -2,27 +2,55 @@
import (
"testing"
+
"github.com/rackspace/gophercloud"
+ th "github.com/rackspace/gophercloud/testhelper"
)
-func TestContainerURL(t *testing.T) {
- client := gophercloud.ServiceClient{
- Endpoint: "http://localhost:5000/v1/",
- }
- expected := "http://localhost:5000/v1/testContainer"
- actual := containerURL(&client, "testContainer")
- if actual != expected {
- t.Errorf("Unexpected service URL generated: %s", actual)
- }
+const endpoint = "http://localhost:57909/"
+
+func endpointClient() *gophercloud.ServiceClient {
+ return &gophercloud.ServiceClient{Endpoint: endpoint}
}
-func TestObjectURL(t *testing.T) {
- client := gophercloud.ServiceClient{
- Endpoint: "http://localhost:5000/v1/",
- }
- expected := "http://localhost:5000/v1/testContainer/testObject"
- actual := objectURL(&client, "testContainer", "testObject")
- if actual != expected {
- t.Errorf("Unexpected service URL generated: %s", actual)
- }
+func TestListURL(t *testing.T) {
+ actual := listURL(endpointClient(), "foo")
+ expected := endpoint + "foo"
+ th.CheckEquals(t, expected, actual)
+}
+
+func TestCopyURL(t *testing.T) {
+ actual := copyURL(endpointClient(), "foo", "bar")
+ expected := endpoint + "foo/bar"
+ th.CheckEquals(t, expected, actual)
+}
+
+func TestCreateURL(t *testing.T) {
+ actual := createURL(endpointClient(), "foo", "bar")
+ expected := endpoint + "foo/bar"
+ th.CheckEquals(t, expected, actual)
+}
+
+func TestGetURL(t *testing.T) {
+ actual := getURL(endpointClient(), "foo", "bar")
+ expected := endpoint + "foo/bar"
+ th.CheckEquals(t, expected, actual)
+}
+
+func TestDeleteURL(t *testing.T) {
+ actual := deleteURL(endpointClient(), "foo", "bar")
+ expected := endpoint + "foo/bar"
+ th.CheckEquals(t, expected, actual)
+}
+
+func TestDownloadURL(t *testing.T) {
+ actual := downloadURL(endpointClient(), "foo", "bar")
+ expected := endpoint + "foo/bar"
+ th.CheckEquals(t, expected, actual)
+}
+
+func TestUpdateURL(t *testing.T) {
+ actual := updateURL(endpointClient(), "foo", "bar")
+ expected := endpoint + "foo/bar"
+ th.CheckEquals(t, expected, actual)
}