sfs/share: Delete share (#120)
diff --git a/openstack/sharedfilesystems/v2/shares/requests.go b/openstack/sharedfilesystems/v2/shares/requests.go
index f168178..292ea95 100644
--- a/openstack/sharedfilesystems/v2/shares/requests.go
+++ b/openstack/sharedfilesystems/v2/shares/requests.go
@@ -67,3 +67,9 @@
})
return
}
+
+// Delete will delete an existing Share with the given UUID.
+func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult) {
+ _, r.Err = client.Delete(deleteURL(client, id), nil)
+ return
+}
diff --git a/openstack/sharedfilesystems/v2/shares/results.go b/openstack/sharedfilesystems/v2/shares/results.go
index f303201..10d8129 100644
--- a/openstack/sharedfilesystems/v2/shares/results.go
+++ b/openstack/sharedfilesystems/v2/shares/results.go
@@ -80,3 +80,8 @@
type CreateResult struct {
commonResult
}
+
+// DeleteResult contains the delete results
+type DeleteResult struct {
+ gophercloud.ErrResult
+}
diff --git a/openstack/sharedfilesystems/v2/shares/testing/fixtures.go b/openstack/sharedfilesystems/v2/shares/testing/fixtures.go
index 3f90946..00bdfe0 100644
--- a/openstack/sharedfilesystems/v2/shares/testing/fixtures.go
+++ b/openstack/sharedfilesystems/v2/shares/testing/fixtures.go
@@ -10,6 +10,7 @@
const (
shareEndpoint = "/shares"
+ shareID = "011d21e2-fbc3-4e4a-9993-9ea223f73264"
)
var createRequest = `{
@@ -78,3 +79,12 @@
fmt.Fprintf(w, createResponse)
})
}
+
+// MockDeleteResponse creates a mock delete response
+func MockDeleteResponse(t *testing.T) {
+ th.Mux.HandleFunc(shareEndpoint+"/"+shareID, func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "DELETE")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+ w.WriteHeader(http.StatusAccepted)
+ })
+}
diff --git a/openstack/sharedfilesystems/v2/shares/testing/request_test.go b/openstack/sharedfilesystems/v2/shares/testing/request_test.go
index 6d69201..c4e811c 100644
--- a/openstack/sharedfilesystems/v2/shares/testing/request_test.go
+++ b/openstack/sharedfilesystems/v2/shares/testing/request_test.go
@@ -21,3 +21,13 @@
th.AssertEquals(t, n.Size, 1)
th.AssertEquals(t, n.ShareProto, "NFS")
}
+
+func TestDelete(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ MockDeleteResponse(t)
+
+ result := shares.Delete(client.ServiceClient(), shareID)
+ th.AssertNoErr(t, result.Err)
+}
diff --git a/openstack/sharedfilesystems/v2/shares/urls.go b/openstack/sharedfilesystems/v2/shares/urls.go
index 4fba746..7cb1c81 100644
--- a/openstack/sharedfilesystems/v2/shares/urls.go
+++ b/openstack/sharedfilesystems/v2/shares/urls.go
@@ -5,3 +5,7 @@
func createURL(c *gophercloud.ServiceClient) string {
return c.ServiceURL("shares")
}
+
+func deleteURL(c *gophercloud.ServiceClient, id string) string {
+ return c.ServiceURL("shares", id)
+}