Containers update unit tests
diff --git a/openstack/objectstorage/v1/containers/requests.go b/openstack/objectstorage/v1/containers/requests.go
index d772a43..d0d3781 100644
--- a/openstack/objectstorage/v1/containers/requests.go
+++ b/openstack/objectstorage/v1/containers/requests.go
@@ -22,7 +22,7 @@
func List(c *gophercloud.ServiceClient, opts *ListOpts) pagination.Pager {
var headers map[string]string
- url := accountURL(c)
+ url := listURL(c)
if opts != nil {
query, err := gophercloud.BuildQueryString(opts)
if err != nil {
@@ -82,7 +82,7 @@
}
}
- resp, err := perigee.Request("PUT", containerURL(c, containerName), perigee.Options{
+ resp, err := perigee.Request("PUT", createURL(c, containerName), perigee.Options{
MoreHeaders: h,
OkCodes: []int{201, 204},
})
@@ -94,7 +94,7 @@
// Delete is a function that deletes a container.
func Delete(c *gophercloud.ServiceClient, containerName string) DeleteResult {
var res DeleteResult
- resp, err := perigee.Request("DELETE", containerURL(c, containerName), perigee.Options{
+ resp, err := perigee.Request("DELETE", deleteURL(c, containerName), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
OkCodes: []int{204},
})
@@ -138,7 +138,7 @@
}
}
- resp, err := perigee.Request("POST", containerURL(c, containerName), perigee.Options{
+ resp, err := perigee.Request("POST", updateURL(c, containerName), perigee.Options{
MoreHeaders: h,
OkCodes: []int{204},
})
@@ -151,7 +151,7 @@
// metadata, pass the GetResult response to the ExtractMetadata function.
func Get(c *gophercloud.ServiceClient, containerName string) GetResult {
var res GetResult
- resp, err := perigee.Request("HEAD", containerURL(c, containerName), perigee.Options{
+ resp, err := perigee.Request("HEAD", getURL(c, containerName), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
OkCodes: []int{204},
})
diff --git a/openstack/objectstorage/v1/containers/results.go b/openstack/objectstorage/v1/containers/results.go
index be96fca..227a9dc 100644
--- a/openstack/objectstorage/v1/containers/results.go
+++ b/openstack/objectstorage/v1/containers/results.go
@@ -2,11 +2,12 @@
import (
"fmt"
- "net/http"
"strings"
- "github.com/mitchellh/mapstructure"
+ objectstorage "github.com/rackspace/gophercloud/openstack/objectstorage/v1"
"github.com/rackspace/gophercloud/pagination"
+
+ "github.com/mitchellh/mapstructure"
)
// Container represents a container resource.
@@ -97,8 +98,7 @@
// GetResult represents the result of a get operation.
type GetResult struct {
- Resp *http.Response
- Err error
+ objectstorage.CommonResult
}
// ExtractMetadata is a function that takes a GetResult (of type *http.Response)
@@ -117,37 +117,23 @@
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. To extract the
// the headers from the HTTP response, you can invoke the 'ExtractHeaders'
// method on the result struct.
type CreateResult struct {
- commonResult
+ objectstorage.CommonResult
}
// UpdateResult represents the result of an update operation. To extract the
// the headers from the HTTP response, you can invoke the 'ExtractHeaders'
// method on the result struct.
type UpdateResult struct {
- commonResult
+ objectstorage.CommonResult
}
// DeleteResult represents the result of a delete operation. To extract the
// the headers from the HTTP response, you can invoke the 'ExtractHeaders'
// method on the result struct.
type DeleteResult struct {
- commonResult
+ objectstorage.CommonResult
}
diff --git a/openstack/objectstorage/v1/containers/urls.go b/openstack/objectstorage/v1/containers/urls.go
index 2a06f95..f864f84 100644
--- a/openstack/objectstorage/v1/containers/urls.go
+++ b/openstack/objectstorage/v1/containers/urls.go
@@ -2,12 +2,22 @@
import "github.com/rackspace/gophercloud"
-// accountURL returns the URI used to list Containers.
-func accountURL(c *gophercloud.ServiceClient) string {
+func listURL(c *gophercloud.ServiceClient) string {
return c.Endpoint
}
-// containerURL returns the URI for making Container requests.
-func containerURL(c *gophercloud.ServiceClient, container string) string {
+func createURL(c *gophercloud.ServiceClient, container string) string {
return c.ServiceURL(container)
}
+
+func getURL(c *gophercloud.ServiceClient, container string) string {
+ return createURL(c, container)
+}
+
+func deleteURL(c *gophercloud.ServiceClient, container string) string {
+ return createURL(c, container)
+}
+
+func updateURL(c *gophercloud.ServiceClient, container string) string {
+ return createURL(c, container)
+}
diff --git a/openstack/objectstorage/v1/containers/urls_test.go b/openstack/objectstorage/v1/containers/urls_test.go
index da37bf6..d043a2a 100644
--- a/openstack/objectstorage/v1/containers/urls_test.go
+++ b/openstack/objectstorage/v1/containers/urls_test.go
@@ -1,29 +1,43 @@
package containers
import (
- "testing"
"github.com/rackspace/gophercloud"
+ th "github.com/rackspace/gophercloud/testhelper"
+ "testing"
)
-func TestAccountURL(t *testing.T) {
- client := gophercloud.ServiceClient{
- Endpoint: "http://localhost:5000/v1/",
- }
- expected := "http://localhost:5000/v1/"
- actual := accountURL(&client)
- 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 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)
- }
+func TestListURL(t *testing.T) {
+ actual := listURL(endpointClient())
+ expected := endpoint
+ th.CheckEquals(t, expected, actual)
+}
+
+func TestCreateURL(t *testing.T) {
+ actual := createURL(endpointClient(), "foo")
+ expected := endpoint + "foo"
+ th.CheckEquals(t, expected, actual)
+}
+
+func TestGetURL(t *testing.T) {
+ actual := getURL(endpointClient(), "foo")
+ expected := endpoint + "foo"
+ th.CheckEquals(t, expected, actual)
+}
+
+func TestDeleteURL(t *testing.T) {
+ actual := deleteURL(endpointClient(), "foo")
+ expected := endpoint + "foo"
+ th.CheckEquals(t, expected, actual)
+}
+
+func TestUpdateURL(t *testing.T) {
+ actual := updateURL(endpointClient(), "foo")
+ expected := endpoint + "foo"
+ th.CheckEquals(t, expected, actual)
}