Merge pull request #226 from jamiehannaford/new-readme
Updated README
diff --git a/openstack/blockstorage/v1/apiversions/requests.go b/openstack/blockstorage/v1/apiversions/requests.go
index b3a39f7..79a939c 100644
--- a/openstack/blockstorage/v1/apiversions/requests.go
+++ b/openstack/blockstorage/v1/apiversions/requests.go
@@ -7,7 +7,7 @@
"github.com/racker/perigee"
)
-// ListVersions lists all the Cinder API versions available to end-users.
+// List lists all the Cinder API versions available to end-users.
func List(c *gophercloud.ServiceClient) pagination.Pager {
return pagination.NewPager(c, listURL(c), func(r pagination.LastHTTPResponse) pagination.Page {
return APIVersionPage{pagination.SinglePageBase(r)}
diff --git a/openstack/blockstorage/v1/apiversions/results.go b/openstack/blockstorage/v1/apiversions/results.go
index eeff132..c4ac157 100644
--- a/openstack/blockstorage/v1/apiversions/results.go
+++ b/openstack/blockstorage/v1/apiversions/results.go
@@ -44,10 +44,12 @@
return resp.Versions, nil
}
+// GetResult represents the result of a get operation.
type GetResult struct {
gophercloud.CommonResult
}
+// Extract is a function that accepts a result and extracts an API version resource.
func (r GetResult) Extract() (*APIVersion, error) {
var resp struct {
Version *APIVersion `mapstructure:"version"`
diff --git a/openstack/blockstorage/v1/snapshots/requests.go b/openstack/blockstorage/v1/snapshots/requests.go
index 40b44d8..f3180d7 100644
--- a/openstack/blockstorage/v1/snapshots/requests.go
+++ b/openstack/blockstorage/v1/snapshots/requests.go
@@ -100,15 +100,16 @@
return pagination.NewPager(client, url, createPage)
}
-// UpdateOpts contain options for updating an existing Snapshot. This object is
-// passed to the snapshots.Update function. For more information about the
-// parameters, see the Snapshot object.
+// UpdateMetadataOpts contain options for updating an existing Snapshot. This
+// object is passed to the snapshots.Update function. For more information
+// about the parameters, see the Snapshot object.
type UpdateMetadataOpts struct {
Metadata map[string]interface{}
}
-// Update will update the Snapshot with provided information. To extract the updated
-// Snapshot from the response, call the ExtractMetadata method on the UpdateResult.
+// UpdateMetadata will update the Snapshot with provided information. To
+// extract the updated Snapshot from the response, call the ExtractMetadata
+// method on the UpdateMetadataResult.
func UpdateMetadata(client *gophercloud.ServiceClient, id string, opts *UpdateMetadataOpts) UpdateMetadataResult {
type request struct {
Metadata map[string]interface{} `json:"metadata,omitempty"`
diff --git a/openstack/blockstorage/v1/snapshots/util.go b/openstack/blockstorage/v1/snapshots/util.go
index b882875..64cdc60 100644
--- a/openstack/blockstorage/v1/snapshots/util.go
+++ b/openstack/blockstorage/v1/snapshots/util.go
@@ -4,6 +4,8 @@
"github.com/rackspace/gophercloud"
)
+// WaitForStatus will continually poll the resource, checking for a particular
+// status. It will do this for the amount of seconds defined.
func WaitForStatus(c *gophercloud.ServiceClient, id, status string, secs int) error {
return gophercloud.WaitFor(secs, func() (bool, error) {
current, err := Get(c, id).Extract()
diff --git a/openstack/blockstorage/v1/volumes/util.go b/openstack/blockstorage/v1/volumes/util.go
index 0e2f16e..1dda695 100644
--- a/openstack/blockstorage/v1/volumes/util.go
+++ b/openstack/blockstorage/v1/volumes/util.go
@@ -4,6 +4,8 @@
"github.com/rackspace/gophercloud"
)
+// WaitForStatus will continually poll the resource, checking for a particular
+// status. It will do this for the amount of seconds defined.
func WaitForStatus(c *gophercloud.ServiceClient, id, status string, secs int) error {
return gophercloud.WaitFor(secs, func() (bool, error) {
current, err := Get(c, id).Extract()
diff --git a/openstack/common/extensions/results.go b/openstack/common/extensions/results.go
index 2b8d8b7..9319018 100755
--- a/openstack/common/extensions/results.go
+++ b/openstack/common/extensions/results.go
@@ -8,7 +8,7 @@
"github.com/rackspace/gophercloud/pagination"
)
-// GetResult temporarility stores the result of a Get call.
+// GetResult temporarily stores the result of a Get call.
// Use its Extract() method to interpret it as an Extension.
type GetResult struct {
gophercloud.CommonResult
diff --git a/openstack/compute/v2/servers/doc.go b/openstack/compute/v2/servers/doc.go
index 77a7514..0a1791d 100644
--- a/openstack/compute/v2/servers/doc.go
+++ b/openstack/compute/v2/servers/doc.go
@@ -1,2 +1,3 @@
-// The servers package provides convenient access to standard, OpenStack-defined compute services.
+// Package servers provides convenient access to standard, OpenStack-defined
+// compute services.
package servers
diff --git a/openstack/networking/v2/extensions/external/requests.go b/openstack/networking/v2/extensions/external/requests.go
index f195cfa..afdd428 100644
--- a/openstack/networking/v2/extensions/external/requests.go
+++ b/openstack/networking/v2/extensions/external/requests.go
@@ -2,6 +2,8 @@
import "github.com/rackspace/gophercloud/openstack/networking/v2/networks"
+// AdminState gives users a solid type to work with for create and update
+// operations. It is recommended that users use the `Up` and `Down` enums.
type AdminState *bool
// Convenience vars for AdminStateUp values.
@@ -9,16 +11,19 @@
iTrue = true
iFalse = false
- Nothing AdminState = nil
- Up AdminState = &iTrue
- Down AdminState = &iFalse
+ Up AdminState = &iTrue
+ Down AdminState = &iFalse
)
+// CreateOpts is the structure used when creating new external network
+// resources. It embeds networks.CreateOpts and so inherits all of its required
+// and optional fields, with the addition of the External field.
type CreateOpts struct {
Parent networks.CreateOpts
External bool
}
+// ToNetworkCreateMap casts a CreateOpts struct to a map.
func (o CreateOpts) ToNetworkCreateMap() map[string]map[string]interface{} {
outer := o.Parent.ToNetworkCreateMap()
@@ -27,11 +32,15 @@
return outer
}
+// UpdateOpts is the structure used when updating existing external network
+// resources. It embeds networks.UpdateOpts and so inherits all of its required
+// and optional fields, with the addition of the External field.
type UpdateOpts struct {
Parent networks.UpdateOpts
External bool
}
+// ToNetworkUpdateMap casts an UpdateOpts struct to a map.
func (o UpdateOpts) ToNetworkUpdateMap() map[string]map[string]interface{} {
outer := o.Parent.ToNetworkUpdateMap()
diff --git a/openstack/networking/v2/extensions/lbaas/monitors/requests.go b/openstack/networking/v2/extensions/lbaas/monitors/requests.go
index 9f63fc5..fca7199 100644
--- a/openstack/networking/v2/extensions/lbaas/monitors/requests.go
+++ b/openstack/networking/v2/extensions/lbaas/monitors/requests.go
@@ -20,8 +20,8 @@
Delay int `q:"delay"`
Timeout int `q:"timeout"`
MaxRetries int `q:"max_retries"`
- HttpMethod string `q:"http_method"`
- UrlPath string `q:"url_path"`
+ HTTPMethod string `q:"http_method"`
+ URLPath string `q:"url_path"`
ExpectedCodes string `q:"expected_codes"`
AdminStateUp *bool `q:"admin_state_up"`
Status string `q:"status"`
@@ -49,6 +49,7 @@
})
}
+// Constants that represent approved monitoring types.
const (
TypePING = "PING"
TypeTCP = "TCP"
diff --git a/openstack/networking/v2/extensions/lbaas/vips/requests.go b/openstack/networking/v2/extensions/lbaas/vips/requests.go
index 8fadebf..ce4d9e4 100644
--- a/openstack/networking/v2/extensions/lbaas/vips/requests.go
+++ b/openstack/networking/v2/extensions/lbaas/vips/requests.go
@@ -8,6 +8,8 @@
"github.com/rackspace/gophercloud/pagination"
)
+// AdminState gives users a solid type to work with for create and update
+// operations. It is recommended that users use the `Up` and `Down` enums.
type AdminState *bool
// Convenience vars for AdminStateUp values.
@@ -15,9 +17,8 @@
iTrue = true
iFalse = false
- Nothing AdminState
- Up AdminState = &iTrue
- Down AdminState = &iFalse
+ Up AdminState = &iTrue
+ Down AdminState = &iFalse
)
// ListOpts allows the filtering and sorting of paginated collections through
diff --git a/openstack/networking/v2/extensions/provider/doc.go b/openstack/networking/v2/extensions/provider/doc.go
index 612d26e..373da44 100755
--- a/openstack/networking/v2/extensions/provider/doc.go
+++ b/openstack/networking/v2/extensions/provider/doc.go
@@ -1,4 +1,4 @@
-// Package networkattrs gives access to the provider Neutron plugin, allowing
+// Package provider gives access to the provider Neutron plugin, allowing
// network extended attributes. The provider extended attributes for networks
// enable administrative users to specify how network objects map to the
// underlying networking infrastructure. These extended attributes also appear
diff --git a/openstack/networking/v2/extensions/provider/results.go b/openstack/networking/v2/extensions/provider/results.go
index 96caac1..a20b259 100755
--- a/openstack/networking/v2/extensions/provider/results.go
+++ b/openstack/networking/v2/extensions/provider/results.go
@@ -8,6 +8,8 @@
"github.com/rackspace/gophercloud/pagination"
)
+// AdminState gives users a solid type to work with for create and update
+// operations. It is recommended that users use the `Up` and `Down` enums.
type AdminState *bool
// Convenience vars for AdminStateUp values.
@@ -15,9 +17,8 @@
iTrue = true
iFalse = false
- Nothing AdminState = nil
- Up AdminState = &iTrue
- Down AdminState = &iFalse
+ Up AdminState = &iTrue
+ Down AdminState = &iFalse
)
// NetworkExtAttrs represents an extended form of a Network with additional fields.
@@ -79,7 +80,7 @@
return res.Network, nil
}
-// ExtractGet decorates a CreateResult struct returned from a networks.Create()
+// ExtractCreate decorates a CreateResult struct returned from a networks.Create()
// function with extended attributes.
func ExtractCreate(r networks.CreateResult) (*NetworkExtAttrs, error) {
if r.Err != nil {
diff --git a/openstack/networking/v2/networks/requests.go b/openstack/networking/v2/networks/requests.go
index 6088b36..81b1545 100644
--- a/openstack/networking/v2/networks/requests.go
+++ b/openstack/networking/v2/networks/requests.go
@@ -57,12 +57,19 @@
return res
}
+// CreateOptsBuilder is the interface options structs have to satisfy in order
+// to be used in the main Create operation in this package. Since many
+// extensions decorate or modify the common logic, it is useful for them to
+// satisfy a basic interface in order for them to be used.
type CreateOptsBuilder interface {
ToNetworkCreateMap() map[string]map[string]interface{}
}
+// CreateOpts is the common options struct used in this package's Create
+// operation.
type CreateOpts networkOpts
+// ToNetworkCreateMap casts a CreateOpts struct to a map.
func (o CreateOpts) ToNetworkCreateMap() map[string]map[string]interface{} {
inner := make(map[string]interface{})
@@ -107,12 +114,19 @@
return res
}
+// UpdateOptsBuilder is the interface options structs have to satisfy in order
+// to be used in the main Update operation in this package. Since many
+// extensions decorate or modify the common logic, it is useful for them to
+// satisfy a basic interface in order for them to be used.
type UpdateOptsBuilder interface {
ToNetworkUpdateMap() map[string]map[string]interface{}
}
+// UpdateOpts is the common options struct used in this package's Update
+// operation.
type UpdateOpts networkOpts
+// ToNetworkUpdateMap casts a UpdateOpts struct to a map.
func (o UpdateOpts) ToNetworkUpdateMap() map[string]map[string]interface{} {
inner := make(map[string]interface{})
diff --git a/openstack/networking/v2/ports/urls_tests.go b/openstack/networking/v2/ports/urls_test.go
similarity index 100%
rename from openstack/networking/v2/ports/urls_tests.go
rename to openstack/networking/v2/ports/urls_test.go
diff --git a/openstack/networking/v2/subnets/urls_tests.go b/openstack/networking/v2/subnets/urls_test.go
similarity index 100%
rename from openstack/networking/v2/subnets/urls_tests.go
rename to openstack/networking/v2/subnets/urls_test.go
diff --git a/openstack/objectstorage/v1/accounts/doc.go b/openstack/objectstorage/v1/accounts/doc.go
index 5c94e1a..f5f894a 100644
--- a/openstack/objectstorage/v1/accounts/doc.go
+++ b/openstack/objectstorage/v1/accounts/doc.go
@@ -1,5 +1,8 @@
-/* The accounts package defines operations performed on an object-storage account.
-
-Reference: http://developer.openstack.org/api-ref-objectstorage-v1.html#storage_account_services
-*/
+// Package accounts contains functionality for working with Object Storage
+// account resources. An account is the top-level resource the object storage
+// hierarchy: containers belong to accounts, objects belong to containers.
+//
+// Another way of thinking of an account is like a namespace for all your
+// resources. It is synonymous with a project or tenant in other OpenStack
+// services.
package accounts
diff --git a/openstack/objectstorage/v1/accounts/requests_test.go b/openstack/objectstorage/v1/accounts/requests_test.go
index e1450d4..348f93e 100644
--- a/openstack/objectstorage/v1/accounts/requests_test.go
+++ b/openstack/objectstorage/v1/accounts/requests_test.go
@@ -4,34 +4,24 @@
"net/http"
"testing"
- "github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/testhelper"
+ fake "github.com/rackspace/gophercloud/testhelper/client"
)
-const tokenId = "abcabcabcabc"
-
var metadata = map[string]string{"gophercloud-test": "accounts"}
-func serviceClient() *gophercloud.ServiceClient {
- return &gophercloud.ServiceClient{
- Provider: &gophercloud.ProviderClient{TokenID: tokenId},
- Endpoint: testhelper.Endpoint(),
- }
-}
-
func TestUpdateAccount(t *testing.T) {
testhelper.SetupHTTP()
defer testhelper.TeardownHTTP()
testhelper.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
testhelper.TestMethod(t, r, "POST")
- testhelper.TestHeader(t, r, "X-Auth-Token", tokenId)
+ testhelper.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
testhelper.TestHeader(t, r, "X-Account-Meta-Gophercloud-Test", "accounts")
w.WriteHeader(http.StatusNoContent)
})
- client := serviceClient()
- err := Update(client, UpdateOpts{Metadata: metadata})
+ err := Update(fake.ServiceClient(), UpdateOpts{Metadata: metadata})
if err != nil {
t.Fatalf("Unable to update account: %v", err)
}
@@ -43,12 +33,11 @@
testhelper.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
testhelper.TestMethod(t, r, "HEAD")
- testhelper.TestHeader(t, r, "X-Auth-Token", tokenId)
+ testhelper.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
w.WriteHeader(http.StatusNoContent)
})
- client := serviceClient()
- _, err := Get(client, GetOpts{})
+ _, err := Get(fake.ServiceClient(), GetOpts{})
if err != nil {
t.Fatalf("Unable to get account metadata: %v", err)
}
diff --git a/openstack/objectstorage/v1/containers/doc.go b/openstack/objectstorage/v1/containers/doc.go
index 9b6ac17..5fed553 100644
--- a/openstack/objectstorage/v1/containers/doc.go
+++ b/openstack/objectstorage/v1/containers/doc.go
@@ -1,5 +1,8 @@
-/* The containers package defines operations performed on an object-storage container.
-
-Reference: http://developer.openstack.org/api-ref-objectstorage-v1.html#storage_container_services
-*/
+// Package containers contains functionality for working with Object Storage
+// container resources. A container serves as a logical namespace for objects
+// that are placed inside it - an object with the same name in two different
+// containers represents two different objects.
+//
+// In addition to containing objects, you can also use the container to control
+// access to objects by using an access control list (ACL).
package containers
diff --git a/openstack/objectstorage/v1/containers/requests_test.go b/openstack/objectstorage/v1/containers/requests_test.go
index 1ab09a9..09930d0 100644
--- a/openstack/objectstorage/v1/containers/requests_test.go
+++ b/openstack/objectstorage/v1/containers/requests_test.go
@@ -5,31 +5,20 @@
"net/http"
"testing"
- "github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/pagination"
"github.com/rackspace/gophercloud/testhelper"
-)
-
-const (
- tokenId = "abcabcabcabc"
+ fake "github.com/rackspace/gophercloud/testhelper/client"
)
var metadata = map[string]string{"gophercloud-test": "containers"}
-func serviceClient() *gophercloud.ServiceClient {
- return &gophercloud.ServiceClient{
- Provider: &gophercloud.ProviderClient{TokenID: tokenId},
- Endpoint: testhelper.Endpoint(),
- }
-}
-
func TestListContainerInfo(t *testing.T) {
testhelper.SetupHTTP()
defer testhelper.TeardownHTTP()
testhelper.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
testhelper.TestMethod(t, r, "GET")
- testhelper.TestHeader(t, r, "X-Auth-Token", tokenId)
+ testhelper.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
testhelper.TestHeader(t, r, "Accept", "application/json")
w.Header().Set("Content-Type", "application/json")
@@ -56,9 +45,9 @@
}
})
- client := serviceClient()
count := 0
- List(client, &ListOpts{Full: true}).EachPage(func(page pagination.Page) (bool, error) {
+
+ List(fake.ServiceClient(), &ListOpts{Full: true}).EachPage(func(page pagination.Page) (bool, error) {
count++
actual, err := ExtractInfo(page)
if err != nil {
@@ -95,7 +84,7 @@
testhelper.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
testhelper.TestMethod(t, r, "GET")
- testhelper.TestHeader(t, r, "X-Auth-Token", tokenId)
+ testhelper.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
testhelper.TestHeader(t, r, "Accept", "text/plain")
w.Header().Set("Content-Type", "text/plain")
@@ -111,9 +100,9 @@
}
})
- client := serviceClient()
count := 0
- List(client, &ListOpts{Full: false}).EachPage(func(page pagination.Page) (bool, error) {
+
+ List(fake.ServiceClient(), &ListOpts{Full: false}).EachPage(func(page pagination.Page) (bool, error) {
count++
actual, err := ExtractNames(page)
if err != nil {
@@ -139,13 +128,12 @@
testhelper.Mux.HandleFunc("/testContainer", func(w http.ResponseWriter, r *http.Request) {
testhelper.TestMethod(t, r, "PUT")
- testhelper.TestHeader(t, r, "X-Auth-Token", tokenId)
+ testhelper.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
testhelper.TestHeader(t, r, "Accept", "application/json")
w.WriteHeader(http.StatusNoContent)
})
- client := serviceClient()
- _, err := Create(client, "testContainer", nil).ExtractHeaders()
+ _, err := Create(fake.ServiceClient(), "testContainer", nil).ExtractHeaders()
if err != nil {
t.Fatalf("Unexpected error creating container: %v", err)
}
@@ -157,13 +145,12 @@
testhelper.Mux.HandleFunc("/testContainer", func(w http.ResponseWriter, r *http.Request) {
testhelper.TestMethod(t, r, "DELETE")
- testhelper.TestHeader(t, r, "X-Auth-Token", tokenId)
+ testhelper.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
testhelper.TestHeader(t, r, "Accept", "application/json")
w.WriteHeader(http.StatusNoContent)
})
- client := serviceClient()
- _, err := Delete(client, "testContainer").ExtractHeaders()
+ _, err := Delete(fake.ServiceClient(), "testContainer").ExtractHeaders()
if err != nil {
t.Fatalf("Unexpected error deleting container: %v", err)
}
@@ -175,13 +162,12 @@
testhelper.Mux.HandleFunc("/testContainer", func(w http.ResponseWriter, r *http.Request) {
testhelper.TestMethod(t, r, "POST")
- testhelper.TestHeader(t, r, "X-Auth-Token", tokenId)
+ testhelper.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
testhelper.TestHeader(t, r, "Accept", "application/json")
w.WriteHeader(http.StatusNoContent)
})
- client := serviceClient()
- _, err := Update(client, "testContainer", nil).ExtractHeaders()
+ _, err := Update(fake.ServiceClient(), "testContainer", nil).ExtractHeaders()
if err != nil {
t.Fatalf("Unexpected error updating container metadata: %v", err)
}
@@ -193,13 +179,12 @@
testhelper.Mux.HandleFunc("/testContainer", func(w http.ResponseWriter, r *http.Request) {
testhelper.TestMethod(t, r, "HEAD")
- testhelper.TestHeader(t, r, "X-Auth-Token", tokenId)
+ testhelper.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
testhelper.TestHeader(t, r, "Accept", "application/json")
w.WriteHeader(http.StatusNoContent)
})
- client := serviceClient()
- _, err := Get(client, "testContainer").ExtractMetadata()
+ _, err := Get(fake.ServiceClient(), "testContainer").ExtractMetadata()
if err != nil {
t.Fatalf("Unexpected error getting container metadata: %v", err)
}
diff --git a/openstack/objectstorage/v1/containers/results.go b/openstack/objectstorage/v1/containers/results.go
index 80425bd..be96fca 100644
--- a/openstack/objectstorage/v1/containers/results.go
+++ b/openstack/objectstorage/v1/containers/results.go
@@ -9,13 +9,20 @@
"github.com/rackspace/gophercloud/pagination"
)
+// Container represents a container resource.
type Container struct {
- Bytes int `json:"bytes" mapstructure:"bytes"`
- Count int `json:"count" mapstructure:"count"`
- Name string `json:"name" mapstructure:"name"`
+ // The total number of bytes stored in the container.
+ Bytes int `json:"bytes" mapstructure:"bytes"`
+
+ // The total number of objects stored in the container.
+ Count int `json:"count" mapstructure:"count"`
+
+ // The name of the container.
+ Name string `json:"name" mapstructure:"name"`
}
-// ListResult is a *http.Response that is returned from a call to the List function.
+// ContainerPage is the page returned by a pager when traversing over a
+// collection of containers.
type ContainerPage struct {
pagination.MarkerPageBase
}
@@ -124,14 +131,23 @@
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
}
+// 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
}
+// 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
}
diff --git a/openstack/objectstorage/v1/objects/doc.go b/openstack/objectstorage/v1/objects/doc.go
index 2a7461b..30a9add 100644
--- a/openstack/objectstorage/v1/objects/doc.go
+++ b/openstack/objectstorage/v1/objects/doc.go
@@ -1,5 +1,5 @@
-/* The objects package defines operations performed on an object-storage object.
-
-Reference: http://developer.openstack.org/api-ref-objectstorage-v1.html#storage_object_services
-*/
+// Package objects contains functionality for working with Object Storage
+// object resources. An object is a resource that represents and contains data
+// - such as documents, images, and so on. You can also store custom metadata
+// with an object.
package objects
diff --git a/openstack/objectstorage/v1/objects/requests_test.go b/openstack/objectstorage/v1/objects/requests_test.go
index 15956cd..089081f 100644
--- a/openstack/objectstorage/v1/objects/requests_test.go
+++ b/openstack/objectstorage/v1/objects/requests_test.go
@@ -6,38 +6,26 @@
"net/http"
"testing"
- "github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/pagination"
"github.com/rackspace/gophercloud/testhelper"
-)
-
-const (
- tokenId = "abcabcabcabc"
+ fake "github.com/rackspace/gophercloud/testhelper/client"
)
var metadata = map[string]string{"Gophercloud-Test": "objects"}
-func serviceClient() *gophercloud.ServiceClient {
- return &gophercloud.ServiceClient{
- Provider: &gophercloud.ProviderClient{TokenID: tokenId},
- Endpoint: testhelper.Endpoint(),
- }
-}
-
func TestDownloadObject(t *testing.T) {
testhelper.SetupHTTP()
defer testhelper.TeardownHTTP()
testhelper.Mux.HandleFunc("/testContainer/testObject", func(w http.ResponseWriter, r *http.Request) {
testhelper.TestMethod(t, r, "GET")
- testhelper.TestHeader(t, r, "X-Auth-Token", tokenId)
+ testhelper.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
testhelper.TestHeader(t, r, "Accept", "application/json")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "Successful download with Gophercloud")
})
- client := serviceClient()
- content, err := Download(client, "testContainer", "testObject", nil).ExtractContent()
+ content, err := Download(fake.ServiceClient(), "testContainer", "testObject", nil).ExtractContent()
if err != nil {
t.Fatalf("Unexpected error downloading object: %v", err)
}
@@ -52,7 +40,7 @@
testhelper.Mux.HandleFunc("/testContainer", func(w http.ResponseWriter, r *http.Request) {
testhelper.TestMethod(t, r, "GET")
- testhelper.TestHeader(t, r, "X-Auth-Token", tokenId)
+ testhelper.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
testhelper.TestHeader(t, r, "Accept", "application/json")
w.Header().Set("Content-Type", "application/json")
@@ -83,9 +71,9 @@
}
})
- client := serviceClient()
count := 0
- err := List(client, "testContainer", &ListOpts{Full: true}).EachPage(func(page pagination.Page) (bool, error) {
+
+ err := List(fake.ServiceClient(), "testContainer", &ListOpts{Full: true}).EachPage(func(page pagination.Page) (bool, error) {
count++
actual, err := ExtractInfo(page)
if err != nil {
@@ -129,7 +117,7 @@
testhelper.Mux.HandleFunc("/testContainer", func(w http.ResponseWriter, r *http.Request) {
testhelper.TestMethod(t, r, "GET")
- testhelper.TestHeader(t, r, "X-Auth-Token", tokenId)
+ testhelper.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
testhelper.TestHeader(t, r, "Accept", "text/plain")
w.Header().Set("Content-Type", "text/plain")
@@ -145,9 +133,8 @@
}
})
- client := serviceClient()
count := 0
- List(client, "testContainer", &ListOpts{Full: false}).EachPage(func(page pagination.Page) (bool, error) {
+ List(fake.ServiceClient(), "testContainer", &ListOpts{Full: false}).EachPage(func(page pagination.Page) (bool, error) {
count++
actual, err := ExtractNames(page)
if err != nil {
@@ -173,14 +160,13 @@
testhelper.Mux.HandleFunc("/testContainer/testObject", func(w http.ResponseWriter, r *http.Request) {
testhelper.TestMethod(t, r, "PUT")
- testhelper.TestHeader(t, r, "X-Auth-Token", tokenId)
+ testhelper.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
testhelper.TestHeader(t, r, "Accept", "application/json")
w.WriteHeader(http.StatusCreated)
})
- client := serviceClient()
content := bytes.NewBufferString("Did gyre and gimble in the wabe")
- _, err := Create(client, "testContainer", "testObject", content, nil).ExtractHeaders()
+ _, err := Create(fake.ServiceClient(), "testContainer", "testObject", content, nil).ExtractHeaders()
if err != nil {
t.Fatalf("Unexpected error creating object: %v", err)
}
@@ -192,14 +178,13 @@
testhelper.Mux.HandleFunc("/testContainer/testObject", func(w http.ResponseWriter, r *http.Request) {
testhelper.TestMethod(t, r, "COPY")
- testhelper.TestHeader(t, r, "X-Auth-Token", tokenId)
+ testhelper.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
testhelper.TestHeader(t, r, "Accept", "application/json")
testhelper.TestHeader(t, r, "Destination", "/newTestContainer/newTestObject")
w.WriteHeader(http.StatusCreated)
})
- client := serviceClient()
- _, err := Copy(client, "testContainer", "testObject", &CopyOpts{Destination: "/newTestContainer/newTestObject"}).ExtractHeaders()
+ _, err := Copy(fake.ServiceClient(), "testContainer", "testObject", &CopyOpts{Destination: "/newTestContainer/newTestObject"}).ExtractHeaders()
if err != nil {
t.Fatalf("Unexpected error copying object: %v", err)
}
@@ -211,13 +196,12 @@
testhelper.Mux.HandleFunc("/testContainer/testObject", func(w http.ResponseWriter, r *http.Request) {
testhelper.TestMethod(t, r, "DELETE")
- testhelper.TestHeader(t, r, "X-Auth-Token", tokenId)
+ testhelper.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
testhelper.TestHeader(t, r, "Accept", "application/json")
w.WriteHeader(http.StatusNoContent)
})
- client := serviceClient()
- _, err := Delete(client, "testContainer", "testObject", nil).ExtractHeaders()
+ _, err := Delete(fake.ServiceClient(), "testContainer", "testObject", nil).ExtractHeaders()
if err != nil {
t.Fatalf("Unexpected error deleting object: %v", err)
}
@@ -229,14 +213,13 @@
testhelper.Mux.HandleFunc("/testContainer/testObject", func(w http.ResponseWriter, r *http.Request) {
testhelper.TestMethod(t, r, "POST")
- testhelper.TestHeader(t, r, "X-Auth-Token", tokenId)
+ testhelper.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
testhelper.TestHeader(t, r, "Accept", "application/json")
testhelper.TestHeader(t, r, "X-Object-Meta-Gophercloud-Test", "objects")
w.WriteHeader(http.StatusAccepted)
})
- client := serviceClient()
- _, err := Update(client, "testContainer", "testObject", &UpdateOpts{Metadata: metadata}).ExtractHeaders()
+ _, err := Update(fake.ServiceClient(), "testContainer", "testObject", &UpdateOpts{Metadata: metadata}).ExtractHeaders()
if err != nil {
t.Fatalf("Unexpected error updating object metadata: %v", err)
}
@@ -248,15 +231,14 @@
testhelper.Mux.HandleFunc("/testContainer/testObject", func(w http.ResponseWriter, r *http.Request) {
testhelper.TestMethod(t, r, "HEAD")
- testhelper.TestHeader(t, r, "X-Auth-Token", tokenId)
+ testhelper.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
testhelper.TestHeader(t, r, "Accept", "application/json")
w.Header().Add("X-Object-Meta-Gophercloud-Test", "objects")
w.WriteHeader(http.StatusNoContent)
})
- client := serviceClient()
expected := metadata
- actual, err := Get(client, "testContainer", "testObject", nil).ExtractMetadata()
+ actual, err := Get(fake.ServiceClient(), "testContainer", "testObject", nil).ExtractMetadata()
if err != nil {
t.Fatalf("Unexpected error getting object metadata: %v", err)
}
diff --git a/openstack/objectstorage/v1/objects/results.go b/openstack/objectstorage/v1/objects/results.go
index aaeb040..f7db3ed 100644
--- a/openstack/objectstorage/v1/objects/results.go
+++ b/openstack/objectstorage/v1/objects/results.go
@@ -19,7 +19,8 @@
Name string `json:"name" mapstructure:"name"`
}
-// ListResult is a single page of objects that is returned from a call to the List function.
+// ObjectPage is a single page of objects that is returned from a call to the
+// List function.
type ObjectPage struct {
pagination.MarkerPageBase
}
@@ -149,18 +150,22 @@
return cr.Resp.Header, nil
}
+// CreateResult represents the result of a create operation.
type CreateResult struct {
commonResult
}
+// UpdateResult represents the result of an update operation.
type UpdateResult struct {
commonResult
}
+// DeleteResult represents the result of a delete operation.
type DeleteResult struct {
commonResult
}
+// CopyResult represents the result of a copy operation.
type CopyResult struct {
commonResult
}
diff --git a/package.go b/package.go
index 396e523..fb6f24a 100644
--- a/package.go
+++ b/package.go
@@ -1,7 +1,4 @@
-// Gophercloud provides a multi-vendor interface to OpenStack-compatible clouds which attempts to follow
-// established Go community coding standards and social norms.
-//
-// Unless you intend on contributing code to the SDK, you will almost certainly never have to use any
-// Context structures or any of its methods. Contextual methods exist for easier unit testing only.
-// Stick with the global functions unless you know exactly what you're doing, and why.
+// Package gophercloud provides a multi-vendor interface to OpenStack-compatible
+// clouds. The package attempts to follow established community standards and
+// golang idioms. Contributions are welcome!
package gophercloud
diff --git a/params.go b/params.go
index 10aefea..26c48c0 100644
--- a/params.go
+++ b/params.go
@@ -21,6 +21,8 @@
return nil
}
+// MaybeInt takes an int that might be a zero-value, and either returns a
+// pointer to its address or a nil value (i.e. empty pointer).
func MaybeInt(original int) *int {
if original != 0 {
return &original
@@ -58,6 +60,19 @@
return v.Interface() == z.Interface()
}
+// BuildQueryString accepts a generic structure and parses it URL struct. It
+// converts field names into query names based on tags. So for example, this
+// type:
+//
+// struct {
+// Bar string `q:"x_bar"`
+// Baz int `q:"lorem_ipsum"`
+// }{
+// Bar: "XXX",
+// Baz: "YYY",
+// }
+//
+// will be converted into ?x_bar=XXX&lorem_ipsum=YYYY
func BuildQueryString(opts interface{}) (*url.URL, error) {
optsValue := reflect.ValueOf(opts)
if optsValue.Kind() == reflect.Ptr {
@@ -69,7 +84,7 @@
optsType = optsType.Elem()
}
- optsSlice := make([]string, 0)
+ var optsSlice []string
if optsValue.Kind() == reflect.Struct {
for i := 0; i < optsValue.NumField(); i++ {
v := optsValue.Field(i)
@@ -115,10 +130,9 @@
return nil, fmt.Errorf("Options type is not a struct.")
}
-func BuildRequestBody(opts interface{}) (map[string]interface{}, error) {
- return nil, nil
-}
-
+// BuildHeaders accepts a generic structure and parses it string map. It
+// converts field names into header names based on "h" tags, and field values
+// into header values by a simple one-to-one mapping.
func BuildHeaders(opts interface{}) (map[string]string, error) {
optsValue := reflect.ValueOf(opts)
if optsValue.Kind() == reflect.Ptr {