Rackspace Auto Scale: Add webhooks Delete()
diff --git a/rackspace/autoscale/v1/webhooks/fixtures.go b/rackspace/autoscale/v1/webhooks/fixtures.go
index 8847f46..daa4c6c 100644
--- a/rackspace/autoscale/v1/webhooks/fixtures.go
+++ b/rackspace/autoscale/v1/webhooks/fixtures.go
@@ -205,7 +205,22 @@
th.TestJSONRequest(t, r, WebhookUpdateRequest)
- w.Header().Add("Content-Type", "application/json")
+ w.WriteHeader(http.StatusNoContent)
+ })
+}
+
+// HandleWebhookDeleteSuccessfully sets up the test server to respond to a webhooks Delete request.
+func HandleWebhookDeleteSuccessfully(t *testing.T) {
+ groupID := "10eb3219-1b12-4b34-b1e4-e10ee4f24c65"
+ policyID := "2b48d247-0282-4b9d-8775-5c4b67e8e649"
+ webhookID := "2bd1822c-58c5-49fd-8b3d-ed44781a58d1"
+
+ path := fmt.Sprintf("/groups/%s/policies/%s/webhooks/%s", groupID, policyID, webhookID)
+
+ th.Mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "DELETE")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+
w.WriteHeader(http.StatusNoContent)
})
}
diff --git a/rackspace/autoscale/v1/webhooks/requests.go b/rackspace/autoscale/v1/webhooks/requests.go
index 893ad57..2a07357 100644
--- a/rackspace/autoscale/v1/webhooks/requests.go
+++ b/rackspace/autoscale/v1/webhooks/requests.go
@@ -153,3 +153,15 @@
return result
}
+
+// Delete requests the given webhook be permanently deleted.
+func Delete(client *gophercloud.ServiceClient, groupID, policyID, webhookID string) DeleteResult {
+ var result DeleteResult
+
+ url := deleteURL(client, groupID, policyID, webhookID)
+ _, result.Err = client.Delete(url, &gophercloud.RequestOpts{
+ OkCodes: []int{204},
+ })
+
+ return result
+}
diff --git a/rackspace/autoscale/v1/webhooks/requests_test.go b/rackspace/autoscale/v1/webhooks/requests_test.go
index e06080a..0eed1c2 100644
--- a/rackspace/autoscale/v1/webhooks/requests_test.go
+++ b/rackspace/autoscale/v1/webhooks/requests_test.go
@@ -104,3 +104,14 @@
th.AssertNoErr(t, err)
}
+
+func TestDelete(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleWebhookDeleteSuccessfully(t)
+
+ client := client.ServiceClient()
+ err := Delete(client, groupID, policyID, firstID).ExtractErr()
+
+ th.AssertNoErr(t, err)
+}
diff --git a/rackspace/autoscale/v1/webhooks/results.go b/rackspace/autoscale/v1/webhooks/results.go
index 9628724..2774dd3 100644
--- a/rackspace/autoscale/v1/webhooks/results.go
+++ b/rackspace/autoscale/v1/webhooks/results.go
@@ -53,6 +53,11 @@
gophercloud.ErrResult
}
+// DeleteResult represents the result of a delete operation.
+type DeleteResult struct {
+ gophercloud.ErrResult
+}
+
// Webhook represents a webhook associted with a scaling policy.
type Webhook struct {
// UUID for the webhook.
diff --git a/rackspace/autoscale/v1/webhooks/urls.go b/rackspace/autoscale/v1/webhooks/urls.go
index 0efb90f..f5432e1 100644
--- a/rackspace/autoscale/v1/webhooks/urls.go
+++ b/rackspace/autoscale/v1/webhooks/urls.go
@@ -17,3 +17,7 @@
func updateURL(c *gophercloud.ServiceClient, groupID, policyID, webhookID string) string {
return getURL(c, groupID, policyID, webhookID)
}
+
+func deleteURL(c *gophercloud.ServiceClient, groupID, policyID, webhookID string) string {
+ return getURL(c, groupID, policyID, webhookID)
+}