Feature/filestorage sharenetworks delete (#122)
* sfs: Add delete for share networks
* sfs: Make name and descr required for creating share network
* sfs: Add acceptance test for share network Delete
* sfs: Remove required parameters
After taking a close look at the code it appeared that 'name'
and 'description' are not required parameters
diff --git a/acceptance/openstack/sharedfilesystems/v2/sharenetworks.go b/acceptance/openstack/sharedfilesystems/v2/sharenetworks.go
index a964515..1f75e90 100644
--- a/acceptance/openstack/sharedfilesystems/v2/sharenetworks.go
+++ b/acceptance/openstack/sharedfilesystems/v2/sharenetworks.go
@@ -31,6 +31,17 @@
return shareNetwork, nil
}
+// DeleteShareNetwork will delete a share network. An error will occur if
+// the share network was unable to be deleted.
+func DeleteShareNetwork(t *testing.T, client *gophercloud.ServiceClient, shareNetwork *sharenetworks.ShareNetwork) {
+ err := sharenetworks.Delete(client, shareNetwork.ID).ExtractErr()
+ if err != nil {
+ t.Fatalf("Failed to delete share network %s: %v", shareNetwork.ID, err)
+ }
+
+ t.Logf("Deleted share network: %s", shareNetwork.ID)
+}
+
// PrintShareNetwork will print a share network and all of its attributes.
func PrintShareNetwork(t *testing.T, sharenetwork *sharenetworks.ShareNetwork) {
t.Logf("ID: %s", sharenetwork.ID)
diff --git a/acceptance/openstack/sharedfilesystems/v2/sharenetworks_test.go b/acceptance/openstack/sharedfilesystems/v2/sharenetworks_test.go
index 6b74007..e654251 100644
--- a/acceptance/openstack/sharedfilesystems/v2/sharenetworks_test.go
+++ b/acceptance/openstack/sharedfilesystems/v2/sharenetworks_test.go
@@ -6,7 +6,7 @@
"github.com/gophercloud/gophercloud/acceptance/clients"
)
-func TestShareNetworkCreate(t *testing.T) {
+func TestShareNetworkCreateDestroy(t *testing.T) {
client, err := clients.NewSharedFileSystemV2Client()
if err != nil {
t.Fatalf("Unable to create shared file system client: %v", err)
@@ -17,7 +17,7 @@
t.Fatalf("Unable to create share network: %v", err)
}
- // TODO: delete the share network when the delete is implemented
-
PrintShareNetwork(t, shareNetwork)
+
+ defer DeleteShareNetwork(t, client, shareNetwork)
}
diff --git a/openstack/sharedfilesystems/v2/sharenetworks/requests.go b/openstack/sharedfilesystems/v2/sharenetworks/requests.go
index f551861..ad29404 100644
--- a/openstack/sharedfilesystems/v2/sharenetworks/requests.go
+++ b/openstack/sharedfilesystems/v2/sharenetworks/requests.go
@@ -44,3 +44,9 @@
})
return
}
+
+// Delete will delete the existing ShareNetwork with the provided ID.
+func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult) {
+ _, r.Err = client.Delete(deleteURL(client, id), nil)
+ return
+}
diff --git a/openstack/sharedfilesystems/v2/sharenetworks/results.go b/openstack/sharedfilesystems/v2/sharenetworks/results.go
index 9a2891a..946ddd8 100644
--- a/openstack/sharedfilesystems/v2/sharenetworks/results.go
+++ b/openstack/sharedfilesystems/v2/sharenetworks/results.go
@@ -50,3 +50,8 @@
type CreateResult struct {
commonResult
}
+
+// DeleteResult contains the response body and error from a Delete request.
+type DeleteResult struct {
+ gophercloud.ErrResult
+}
diff --git a/openstack/sharedfilesystems/v2/sharenetworks/testing/fixtures.go b/openstack/sharedfilesystems/v2/sharenetworks/testing/fixtures.go
index bc61084..a014e5e 100644
--- a/openstack/sharedfilesystems/v2/sharenetworks/testing/fixtures.go
+++ b/openstack/sharedfilesystems/v2/sharenetworks/testing/fixtures.go
@@ -61,3 +61,11 @@
"53482b62-2c84-4a53-b6ab-30d9d9800d06"))
})
}
+
+func MockDeleteResponse(t *testing.T) {
+ th.Mux.HandleFunc("/share-networks/fa158a3d-6d9f-4187-9ca5-abbb82646eb2", 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/sharenetworks/testing/requests_test.go b/openstack/sharedfilesystems/v2/sharenetworks/testing/requests_test.go
index 9a00885..15baf0d 100644
--- a/openstack/sharedfilesystems/v2/sharenetworks/testing/requests_test.go
+++ b/openstack/sharedfilesystems/v2/sharenetworks/testing/requests_test.go
@@ -30,3 +30,14 @@
th.AssertEquals(t, n.NeutronNetID, "998b42ee-2cee-4d36-8b95-67b5ca1f2109")
th.AssertEquals(t, n.NeutronSubnetID, "53482b62-2c84-4a53-b6ab-30d9d9800d06")
}
+
+// Verifies that share network deletion works
+func TestDelete(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ MockDeleteResponse(t)
+
+ res := sharenetworks.Delete(client.ServiceClient(), "fa158a3d-6d9f-4187-9ca5-abbb82646eb2")
+ th.AssertNoErr(t, res.Err)
+}
diff --git a/openstack/sharedfilesystems/v2/sharenetworks/urls.go b/openstack/sharedfilesystems/v2/sharenetworks/urls.go
index 637ea98..7cd6c73 100644
--- a/openstack/sharedfilesystems/v2/sharenetworks/urls.go
+++ b/openstack/sharedfilesystems/v2/sharenetworks/urls.go
@@ -5,3 +5,7 @@
func createURL(c *gophercloud.ServiceClient) string {
return c.ServiceURL("share-networks")
}
+
+func deleteURL(c *gophercloud.ServiceClient, id string) string {
+ return c.ServiceURL("share-networks", id)
+}