Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit b5d5548

Browse files
committed
Rackspace Auto Scale: Add webhooks Delete()
1 parent d9ebfb9 commit b5d5548

File tree

5 files changed

+48
-1
lines changed

5 files changed

+48
-1
lines changed

rackspace/autoscale/v1/webhooks/fixtures.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,22 @@ func HandleWebhookUpdateSuccessfully(t *testing.T) {
205205

206206
th.TestJSONRequest(t, r, WebhookUpdateRequest)
207207

208-
w.Header().Add("Content-Type", "application/json")
208+
w.WriteHeader(http.StatusNoContent)
209+
})
210+
}
211+
212+
// HandleWebhookDeleteSuccessfully sets up the test server to respond to a webhooks Delete request.
213+
func HandleWebhookDeleteSuccessfully(t *testing.T) {
214+
groupID := "10eb3219-1b12-4b34-b1e4-e10ee4f24c65"
215+
policyID := "2b48d247-0282-4b9d-8775-5c4b67e8e649"
216+
webhookID := "2bd1822c-58c5-49fd-8b3d-ed44781a58d1"
217+
218+
path := fmt.Sprintf("/groups/%s/policies/%s/webhooks/%s", groupID, policyID, webhookID)
219+
220+
th.Mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
221+
th.TestMethod(t, r, "DELETE")
222+
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
223+
209224
w.WriteHeader(http.StatusNoContent)
210225
})
211226
}

rackspace/autoscale/v1/webhooks/requests.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,15 @@ func Update(client *gophercloud.ServiceClient, groupID, policyID, webhookID stri
153153

154154
return result
155155
}
156+
157+
// Delete requests the given webhook be permanently deleted.
158+
func Delete(client *gophercloud.ServiceClient, groupID, policyID, webhookID string) DeleteResult {
159+
var result DeleteResult
160+
161+
url := deleteURL(client, groupID, policyID, webhookID)
162+
_, result.Err = client.Delete(url, &gophercloud.RequestOpts{
163+
OkCodes: []int{204},
164+
})
165+
166+
return result
167+
}

rackspace/autoscale/v1/webhooks/requests_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,14 @@ func TestUpdate(t *testing.T) {
104104

105105
th.AssertNoErr(t, err)
106106
}
107+
108+
func TestDelete(t *testing.T) {
109+
th.SetupHTTP()
110+
defer th.TeardownHTTP()
111+
HandleWebhookDeleteSuccessfully(t)
112+
113+
client := client.ServiceClient()
114+
err := Delete(client, groupID, policyID, firstID).ExtractErr()
115+
116+
th.AssertNoErr(t, err)
117+
}

rackspace/autoscale/v1/webhooks/results.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ type UpdateResult struct {
5353
gophercloud.ErrResult
5454
}
5555

56+
// DeleteResult represents the result of a delete operation.
57+
type DeleteResult struct {
58+
gophercloud.ErrResult
59+
}
60+
5661
// Webhook represents a webhook associted with a scaling policy.
5762
type Webhook struct {
5863
// UUID for the webhook.

rackspace/autoscale/v1/webhooks/urls.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ func getURL(c *gophercloud.ServiceClient, groupID, policyID, webhookID string) s
1717
func updateURL(c *gophercloud.ServiceClient, groupID, policyID, webhookID string) string {
1818
return getURL(c, groupID, policyID, webhookID)
1919
}
20+
21+
func deleteURL(c *gophercloud.ServiceClient, groupID, policyID, webhookID string) string {
22+
return getURL(c, groupID, policyID, webhookID)
23+
}

0 commit comments

Comments
 (0)