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

Commit 124df8e

Browse files
committed
Rackspace Auto Scale: Add policies Delete()
1 parent ac037d5 commit 124df8e

File tree

5 files changed

+47
-0
lines changed

5 files changed

+47
-0
lines changed

rackspace/autoscale/v1/policies/fixtures.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,18 @@ func HandlePolicyUpdateSuccessfully(t *testing.T) {
226226
w.WriteHeader(http.StatusNoContent)
227227
})
228228
}
229+
230+
// HandlePolicyDeleteSuccessfully sets up the test server to respond to a policies Delete request.
231+
func HandlePolicyDeleteSuccessfully(t *testing.T) {
232+
groupID := "60b15dad-5ea1-43fa-9a12-a1d737b4da07"
233+
policyID := "2b48d247-0282-4b9d-8775-5c4b67e8e649"
234+
235+
path := fmt.Sprintf("/groups/%s/policies/%s", groupID, policyID)
236+
237+
th.Mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
238+
th.TestMethod(t, r, "DELETE")
239+
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
240+
241+
w.WriteHeader(http.StatusNoContent)
242+
})
243+
}

rackspace/autoscale/v1/policies/requests.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,15 @@ func Update(client *gophercloud.ServiceClient, groupID, policyID string, opts Up
204204

205205
return result
206206
}
207+
208+
// Delete requests the given policy be permanently deleted.
209+
func Delete(client *gophercloud.ServiceClient, groupID, policyID string) DeleteResult {
210+
var result DeleteResult
211+
212+
url := deleteURL(client, groupID, policyID)
213+
_, result.Err = client.Delete(url, &gophercloud.RequestOpts{
214+
OkCodes: []int{204},
215+
})
216+
217+
return result
218+
}

rackspace/autoscale/v1/policies/requests_test.go

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

130130
th.AssertNoErr(t, err)
131131
}
132+
133+
func TestDelete(t *testing.T) {
134+
th.SetupHTTP()
135+
defer th.TeardownHTTP()
136+
HandlePolicyDeleteSuccessfully(t)
137+
138+
client := client.ServiceClient()
139+
err := Delete(client, groupID, webhookPolicyID).ExtractErr()
140+
141+
th.AssertNoErr(t, err)
142+
}

rackspace/autoscale/v1/policies/results.go

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

55+
// DeleteResult represents the result of a delete operation.
56+
type DeleteResult struct {
57+
gophercloud.ErrResult
58+
}
59+
5560
// Policy represents a scaling policy.
5661
type Policy struct {
5762
// UUID for the policy.

rackspace/autoscale/v1/policies/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 string) string {
1717
func updateURL(c *gophercloud.ServiceClient, groupID, policyID string) string {
1818
return getURL(c, groupID, policyID)
1919
}
20+
21+
func deleteURL(c *gophercloud.ServiceClient, groupID, policyID string) string {
22+
return getURL(c, groupID, policyID)
23+
}

0 commit comments

Comments
 (0)