containers acceptance tests docs (and fix)
diff --git a/acceptance/openstack/storage/v1/containers_test.go b/acceptance/openstack/storage/v1/containers_test.go
index cf5e3cd..29f6312 100644
--- a/acceptance/openstack/storage/v1/containers_test.go
+++ b/acceptance/openstack/storage/v1/containers_test.go
@@ -10,20 +10,24 @@
"github.com/rackspace/gophercloud/openstack/storage/v1/containers"
)
+// numContainers is the number of containers to create for testing.
var numContainers = 2
func TestContainers(t *testing.T) {
+ // Create a new client to execute the HTTP requests. See common.go for newClient body.
client, err := newClient()
if err != nil {
t.Error(err)
return
}
+ // Create a slice of random container names.
cNames := make([]string, numContainers)
for i := 0; i < numContainers; i++ {
cNames[i] = tools.RandomString("gophercloud-test-container-", 8)
}
+ // Create numContainers containers.
for i := 0; i < len(cNames); i++ {
_, err := containers.Create(client, containers.CreateOpts{
Name: cNames[i],
@@ -33,6 +37,7 @@
return
}
}
+ // Delete the numContainers containers after function completion.
defer func() {
for i := 0; i < len(cNames); i++ {
err = containers.Delete(client, containers.DeleteOpts{
@@ -45,6 +50,8 @@
}
}()
+ // List the numContainer names that were just created. To just list those,
+ // the 'prefix' parameter is used.
lr, err := containers.List(client, containers.ListOpts{
Full: false,
Params: map[string]string{
@@ -55,6 +62,7 @@
t.Error(err)
return
}
+ // Extract the names from the 'List' response.
cns, err := containers.ExtractNames(lr)
if err != nil {
t.Error(err)
@@ -65,13 +73,18 @@
return
}
+ // List the info for the numContainer containers that were created.
lr, err = containers.List(client, containers.ListOpts{
Full: true,
+ Params: map[string]string{
+ "prefix": "gophercloud-test-container-",
+ },
})
if err != nil {
t.Error(err)
return
}
+ // Extract the info from the 'List' response.
cis, err := containers.ExtractInfo(lr)
if err != nil {
t.Error(err)
@@ -81,6 +94,8 @@
t.Errorf("Expected %d containers and got %d", len(cNames), len(cis))
return
}
+
+ // Update one of the numContainer container metadata.
err = containers.Update(client, containers.UpdateOpts{
Name: cNames[0],
Metadata: metadata,
@@ -89,6 +104,7 @@
t.Error(err)
return
}
+ // After the tests are done, delete the metadata that was set.
defer func() {
tempMap := make(map[string]string)
for k := range metadata {
@@ -104,11 +120,15 @@
}
}()
- gr, err := containers.Get(client, containers.GetOpts{})
+ // Retrieve a container's metadata.
+ gr, err := containers.Get(client, containers.GetOpts{
+ Name: cNames[0],
+ })
if err != nil {
t.Error(err)
return
}
+ // Extract the metadata from the 'Get' response.
cm := containers.ExtractMetadata(gr)
for k := range metadata {
if cm[k] != metadata[strings.Title(k)] {