objects acceptance test docs
diff --git a/acceptance/openstack/storage/v1/objects_test.go b/acceptance/openstack/storage/v1/objects_test.go
index 7952870..066a223 100644
--- a/acceptance/openstack/storage/v1/objects_test.go
+++ b/acceptance/openstack/storage/v1/objects_test.go
@@ -13,20 +13,25 @@
"github.com/rackspace/gophercloud/pagination"
)
+// numObjects is the number of objects to create for testing.
var numObjects = 2
func TestObjects(t *testing.T) {
+ // Create a provider client for executing the HTTP request.
+ // See common.go for more information.
client, err := newClient()
if err != nil {
t.Error(err)
return
}
+ // Make a slice of length numObjects to hold the random object names.
oNames := make([]string, numObjects)
for i := 0; i < len(oNames); i++ {
oNames[i] = tools.RandomString("test-object-", 8)
}
+ // Create a container to hold the test objects.
cName := tools.RandomString("test-container-", 8)
_, err = containers.Create(client, containers.CreateOpts{
Name: cName,
@@ -35,6 +40,7 @@
t.Error(err)
return
}
+ // Defer deletion of the container until after testing.
defer func() {
err = containers.Delete(client, containers.DeleteOpts{
Name: cName,
@@ -45,6 +51,7 @@
}
}()
+ // Create a slice of buffers to hold the test object content.
oContents := make([]*bytes.Buffer, numObjects)
for i := 0; i < numObjects; i++ {
oContents[i] = bytes.NewBuffer([]byte(tools.RandomString("", 10)))
@@ -58,6 +65,7 @@
return
}
}
+ // Delete the objects after testing.
defer func() {
for i := 0; i < numObjects; i++ {
err = objects.Delete(client, objects.DeleteOpts{
@@ -108,6 +116,7 @@
return
}
+ // Copy the contents of one object to another.
err = objects.Copy(client, objects.CopyOpts{
Container: cName,
Name: oNames[0],
@@ -119,6 +128,7 @@
return
}
+ // Download one of the objects that was created above.
dr, err := objects.Download(client, objects.DownloadOpts{
Container: cName,
Name: oNames[1],
@@ -127,10 +137,12 @@
t.Error(err)
return
}
+ // Extract the content from the 'Download' response of object.
o2Content, err := objects.ExtractContent(dr)
if err != nil {
t.Error(err)
}
+ // Download the another object that was create above.
dr, err = objects.Download(client, objects.DownloadOpts{
Container: cName,
Name: oNames[0],
@@ -139,16 +151,19 @@
t.Error(err)
return
}
+ // Extract the content from the 'Download' response of other object.
o1Content, err := objects.ExtractContent(dr)
if err != nil {
t.Error(err)
return
}
+ // Compare the two object's contents to test that the copy worked.
if string(o2Content) != string(o1Content) {
t.Errorf("Copy failed. Expected\n%s\nand got\n%s", string(o1Content), string(o2Content))
return
}
+ // Update an object's metadata.
err = objects.Update(client, objects.UpdateOpts{
Container: cName,
Name: oNames[0],
@@ -158,6 +173,7 @@
t.Error(err)
return
}
+ // Delete the object's metadata after testing.
defer func() {
tempMap := make(map[string]string)
for k := range metadata {
@@ -174,11 +190,13 @@
}
}()
+ // Retrieve an object's metadata.
gr, err := objects.Get(client, objects.GetOpts{})
if err != nil {
t.Error(err)
return
}
+ // Extract the custom metadata from the 'Get' response.
om := objects.ExtractMetadata(gr)
for k := range metadata {
if om[k] != metadata[strings.Title(k)] {