Feature/filestorage securityservices delete (#133)
* sfs: Add support for security services Delete
* sfs: Add acceptance tests for security service Delete
diff --git a/acceptance/openstack/sharedfilesystems/v2/securityservices.go b/acceptance/openstack/sharedfilesystems/v2/securityservices.go
index e9b5549..265323d 100644
--- a/acceptance/openstack/sharedfilesystems/v2/securityservices.go
+++ b/acceptance/openstack/sharedfilesystems/v2/securityservices.go
@@ -31,6 +31,17 @@
return securityService, nil
}
+// DeleteSecurityService will delete a security service. An error will occur if
+// the security service was unable to be deleted.
+func DeleteSecurityService(t *testing.T, client *gophercloud.ServiceClient, securityService *securityservices.SecurityService) {
+ err := securityservices.Delete(client, securityService.ID).ExtractErr()
+ if err != nil {
+ t.Fatalf("Failed to delete security service %s: %v", securityService.ID, err)
+ }
+
+ t.Logf("Deleted security service: %s", securityService.ID)
+}
+
// PrintSecurityService will print a security service and all of its attributes.
func PrintSecurityService(t *testing.T, securityService *securityservices.SecurityService) {
t.Logf("ID: %s", securityService.ID)
diff --git a/acceptance/openstack/sharedfilesystems/v2/securityservices_test.go b/acceptance/openstack/sharedfilesystems/v2/securityservices_test.go
index 8ef917c..0249733 100644
--- a/acceptance/openstack/sharedfilesystems/v2/securityservices_test.go
+++ b/acceptance/openstack/sharedfilesystems/v2/securityservices_test.go
@@ -6,7 +6,7 @@
"github.com/gophercloud/gophercloud/acceptance/clients"
)
-func TestSecurityServiceCreate(t *testing.T) {
+func TestSecurityServiceCreateDelete(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 security service: %v", err)
}
- // TODO: Delete the security service once Delete is supported
-
PrintSecurityService(t, securityService)
+
+ defer DeleteSecurityService(t, client, securityService)
}
diff --git a/openstack/sharedfilesystems/v2/securityservices/requests.go b/openstack/sharedfilesystems/v2/securityservices/requests.go
index eca9fe5..1253d33 100644
--- a/openstack/sharedfilesystems/v2/securityservices/requests.go
+++ b/openstack/sharedfilesystems/v2/securityservices/requests.go
@@ -59,3 +59,9 @@
})
return
}
+
+// Delete will delete the existing SecurityService 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/securityservices/results.go b/openstack/sharedfilesystems/v2/securityservices/results.go
index e34692d..746b2b3 100644
--- a/openstack/sharedfilesystems/v2/securityservices/results.go
+++ b/openstack/sharedfilesystems/v2/securityservices/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/securityservices/testing/fixtures.go b/openstack/sharedfilesystems/v2/securityservices/testing/fixtures.go
index 78adc48..e6b101a 100644
--- a/openstack/sharedfilesystems/v2/securityservices/testing/fixtures.go
+++ b/openstack/sharedfilesystems/v2/securityservices/testing/fixtures.go
@@ -50,3 +50,11 @@
}`)
})
}
+
+func MockDeleteResponse(t *testing.T) {
+ th.Mux.HandleFunc("/security-services/securityServiceID", 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/securityservices/testing/requests_test.go b/openstack/sharedfilesystems/v2/securityservices/testing/requests_test.go
index 2b3325e..8ef88ee 100644
--- a/openstack/sharedfilesystems/v2/securityservices/testing/requests_test.go
+++ b/openstack/sharedfilesystems/v2/securityservices/testing/requests_test.go
@@ -51,3 +51,14 @@
t.Fatal("ErrMissingInput was expected to occur")
}
}
+
+// Verifies that security service deletion works
+func TestDelete(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ MockDeleteResponse(t)
+
+ res := securityservices.Delete(client.ServiceClient(), "securityServiceID")
+ th.AssertNoErr(t, res.Err)
+}
diff --git a/openstack/sharedfilesystems/v2/securityservices/urls.go b/openstack/sharedfilesystems/v2/securityservices/urls.go
index ba0ae6d..5cbdd17 100644
--- a/openstack/sharedfilesystems/v2/securityservices/urls.go
+++ b/openstack/sharedfilesystems/v2/securityservices/urls.go
@@ -5,3 +5,7 @@
func createURL(c *gophercloud.ServiceClient) string {
return c.ServiceURL("security-services")
}
+
+func deleteURL(c *gophercloud.ServiceClient, id string) string {
+ return c.ServiceURL("security-services", id)
+}