bulk delete; finish updating common.Result structs
diff --git a/rackspace/objectstorage/v1/bulk/requests.go b/rackspace/objectstorage/v1/bulk/requests.go
index 6585a14..7a08869 100644
--- a/rackspace/objectstorage/v1/bulk/requests.go
+++ b/rackspace/objectstorage/v1/bulk/requests.go
@@ -1,14 +1,7 @@
package bulk
import (
- "archive/tar"
- "compress/gzip"
- "compress/bzip2"
- "errors"
- "io"
"net/url"
- "os"
- "path/filepath"
"strings"
"github.com/racker/perigee"
@@ -43,10 +36,10 @@
return res
}
- reqBody := strings.NewReader(reqString)
+ reqBody := strings.NewReader(reqString)
resp, err := perigee.Request("DELETE", deleteURL(c), perigee.Options{
- ContentType: "text/plain",
+ ContentType: "text/plain",
MoreHeaders: c.Provider.AuthenticatedHeaders(),
OkCodes: []int{200},
ReqBody: reqBody,
@@ -56,52 +49,3 @@
res.Err = err
return res
}
-
-// Extract will extract the files in `file` and create objects in object storage
-// from them.
-func Extract(c *gophercloud.ServiceClient, file string) ExtractResult {
- var res ExtractResult
-
- if file == ""{
- res.Err = errors.New("Missing required field 'f'.")
- return res
- }
-
- var ext string
- var reqBody io.Reader
- f, err := os.Open(file)
- if err != nil {
- res.Err = errors.New("Error opening file.")
- return res
- }
- defer f.Close()
-
- switch filepath.Ext(file) {
- case "tar":
- ext = "tar"
- reqBody = tar.NewReader(f)
- case "gz":
- ext = "tar.gz"
- reqBody, err = gzip.NewReader(f)
- if err != nil {
- res.Err = err
- return res
- }
- case "bz2":
- ext = "tar.bz2"
- reqBody = bzip2.NewReader(f)
- default:
- res.Err = errors.New("Unsupported extension type.")
- return res
- }
-
- resp, err := perigee.Request("PUT", extractURL(c, ext), perigee.Options{
- MoreHeaders: c.Provider.AuthenticatedHeaders(),
- OkCodes: []int{200},
- ReqBody: reqBody,
- Results: &res.Body,
- })
- res.Header = resp.HttpResponse.Header
- res.Err = err
- return res
-}
diff --git a/rackspace/objectstorage/v1/bulk/requests_test.go b/rackspace/objectstorage/v1/bulk/requests_test.go
index 8598f30..8b5578e 100644
--- a/rackspace/objectstorage/v1/bulk/requests_test.go
+++ b/rackspace/objectstorage/v1/bulk/requests_test.go
@@ -15,7 +15,7 @@
th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "DELETE")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
- th.AssertEquals(t, r.URL.RawQuery, "bulk-delete")
+ th.AssertEquals(t, r.URL.RawQuery, "bulk-delete")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, `
@@ -29,7 +29,7 @@
`)
})
- options := &DeleteOpts{"gophercloud-testcontainer1", "gophercloud-testcontainer2"}
+ options := DeleteOpts{"gophercloud-testcontainer1", "gophercloud-testcontainer2"}
actual, err := Delete(fake.ServiceClient(), options).ExtractBody()
th.AssertNoErr(t, err)
th.AssertEquals(t, actual.NumberDeleted, 1)
diff --git a/rackspace/objectstorage/v1/bulk/results.go b/rackspace/objectstorage/v1/bulk/results.go
index 9c7a9a4..fddc125 100644
--- a/rackspace/objectstorage/v1/bulk/results.go
+++ b/rackspace/objectstorage/v1/bulk/results.go
@@ -1,31 +1,28 @@
package bulk
import (
- "github.com/rackspace/gophercloud"
+ "github.com/rackspace/gophercloud"
- "github.com/mitchellh/mapstructure"
+ "github.com/mitchellh/mapstructure"
+)
- )
-
-// DeleteResult represents the result of a delete operation.
+// DeleteResult represents the result of a bulk delete operation.
type DeleteResult struct {
gophercloud.Result
}
-type DeleteBody struct {
- NumberNotFound int `mapstructure:"Number Not Found"`
- ResponseStatus string `mapstructure:"Response Status"`
- Errors []string `mapstructure:"Errors"`
- NumberDeleted int `mapstructure:"Number Deleted"`
- ResponseBody string `mapstructure:"Response Body"`
+// DeleteRespBody is the form of the response body returned by a bulk delete request.
+type DeleteRespBody struct {
+ NumberNotFound int `mapstructure:"Number Not Found"`
+ ResponseStatus string `mapstructure:"Response Status"`
+ Errors []string `mapstructure:"Errors"`
+ NumberDeleted int `mapstructure:"Number Deleted"`
+ ResponseBody string `mapstructure:"Response Body"`
}
-func (dr DeleteResult) ExtractBody() (DeleteBody, error) {
- var resp DeleteBody
- err := mapstructure.Decode(dr.Body, &resp)
- return resp, err
-}
-
-type ExtractResult struct {
- gophercloud.Result
+// ExtractBody will extract the body returned by the bulk extract request.
+func (dr DeleteResult) ExtractBody() (DeleteRespBody, error) {
+ var resp DeleteRespBody
+ err := mapstructure.Decode(dr.Body, &resp)
+ return resp, err
}
diff --git a/rackspace/objectstorage/v1/cdncontainers/delegate_test.go b/rackspace/objectstorage/v1/cdncontainers/delegate_test.go
index a294f7e..02c3c5e 100644
--- a/rackspace/objectstorage/v1/cdncontainers/delegate_test.go
+++ b/rackspace/objectstorage/v1/cdncontainers/delegate_test.go
@@ -44,7 +44,7 @@
os.HandleUpdateContainerSuccessfully(t)
options := &UpdateOpts{TTL: 3600}
- _, err := Update(fake.ServiceClient(), "testContainer", options).ExtractHeaders()
- th.CheckNoErr(t, err)
+ res := Update(fake.ServiceClient(), "testContainer", options)
+ th.CheckNoErr(t, res.Err)
}
diff --git a/rackspace/objectstorage/v1/cdnobjects/delegate_test.go b/rackspace/objectstorage/v1/cdnobjects/delegate_test.go
index 15b716d..b5e04a9 100644
--- a/rackspace/objectstorage/v1/cdnobjects/delegate_test.go
+++ b/rackspace/objectstorage/v1/cdnobjects/delegate_test.go
@@ -13,7 +13,7 @@
defer th.TeardownHTTP()
os.HandleDeleteObjectSuccessfully(t)
- _, err := Delete(fake.ServiceClient(), "testContainer", "testObject", nil).ExtractHeaders()
- th.AssertNoErr(t, err)
+ res := Delete(fake.ServiceClient(), "testContainer", "testObject", nil)
+ th.AssertNoErr(t, res.Err)
}
diff --git a/rackspace/objectstorage/v1/containers/delegate_test.go b/rackspace/objectstorage/v1/containers/delegate_test.go
index 86868ae..7ba4eb2 100644
--- a/rackspace/objectstorage/v1/containers/delegate_test.go
+++ b/rackspace/objectstorage/v1/containers/delegate_test.go
@@ -56,9 +56,9 @@
os.HandleCreateContainerSuccessfully(t)
options := os.CreateOpts{ContentType: "application/json", Metadata: map[string]string{"foo": "bar"}}
- headers, err := Create(fake.ServiceClient(), "testContainer", options).ExtractHeaders()
- th.CheckNoErr(t, err)
- th.CheckEquals(t, "bar", headers["X-Container-Meta-Foo"][0])
+ res := Create(fake.ServiceClient(), "testContainer", options)
+ th.CheckNoErr(t, res.Err)
+ th.CheckEquals(t, "bar", res.Header["X-Container-Meta-Foo"][0])
}
@@ -67,8 +67,8 @@
defer th.TeardownHTTP()
os.HandleDeleteContainerSuccessfully(t)
- _, err := Delete(fake.ServiceClient(), "testContainer").ExtractHeaders()
- th.CheckNoErr(t, err)
+ res := Delete(fake.ServiceClient(), "testContainer")
+ th.CheckNoErr(t, res.Err)
}
func TestUpdateContainers(t *testing.T) {
@@ -77,8 +77,8 @@
os.HandleUpdateContainerSuccessfully(t)
options := &os.UpdateOpts{Metadata: map[string]string{"foo": "bar"}}
- _, err := Update(fake.ServiceClient(), "testContainer", options).ExtractHeaders()
- th.CheckNoErr(t, err)
+ res := Update(fake.ServiceClient(), "testContainer", options)
+ th.CheckNoErr(t, res.Err)
}
func TestGetContainers(t *testing.T) {
diff --git a/rackspace/objectstorage/v1/objects/delegate_test.go b/rackspace/objectstorage/v1/objects/delegate_test.go
index 808f940..08831ec 100644
--- a/rackspace/objectstorage/v1/objects/delegate_test.go
+++ b/rackspace/objectstorage/v1/objects/delegate_test.go
@@ -70,8 +70,8 @@
content := bytes.NewBufferString("Did gyre and gimble in the wabe")
options := &os.CreateOpts{ContentType: "application/json"}
- _, err := Create(fake.ServiceClient(), "testContainer", "testObject", content, options).ExtractHeaders()
- th.AssertNoErr(t, err)
+ res := Create(fake.ServiceClient(), "testContainer", "testObject", content, options)
+ th.AssertNoErr(t, res.Err)
}
func TestCopyObject(t *testing.T) {
@@ -80,8 +80,8 @@
os.HandleCopyObjectSuccessfully(t)
options := &CopyOpts{Destination: "/newTestContainer/newTestObject"}
- _, err := Copy(fake.ServiceClient(), "testContainer", "testObject", options).ExtractHeaders()
- th.AssertNoErr(t, err)
+ res := Copy(fake.ServiceClient(), "testContainer", "testObject", options)
+ th.AssertNoErr(t, res.Err)
}
func TestDeleteObject(t *testing.T) {
@@ -89,8 +89,8 @@
defer th.TeardownHTTP()
os.HandleDeleteObjectSuccessfully(t)
- _, err := Delete(fake.ServiceClient(), "testContainer", "testObject", nil).ExtractHeaders()
- th.AssertNoErr(t, err)
+ res := Delete(fake.ServiceClient(), "testContainer", "testObject", nil)
+ th.AssertNoErr(t, res.Err)
}
func TestUpdateObject(t *testing.T) {
@@ -99,8 +99,8 @@
os.HandleUpdateObjectSuccessfully(t)
options := &os.UpdateOpts{Metadata: map[string]string{"Gophercloud-Test": "objects"}}
- _, err := Update(fake.ServiceClient(), "testContainer", "testObject", options).ExtractHeaders()
- th.AssertNoErr(t, err)
+ res := Update(fake.ServiceClient(), "testContainer", "testObject", options)
+ th.AssertNoErr(t, res.Err)
}
func TestGetObject(t *testing.T) {