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

Commit 42f8dfb

Browse files
committed
Rackspace Auto Scale: Add policies Execute()
1 parent 124df8e commit 42f8dfb

File tree

5 files changed

+48
-0
lines changed

5 files changed

+48
-0
lines changed

rackspace/autoscale/v1/policies/fixtures.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,3 +241,19 @@ func HandlePolicyDeleteSuccessfully(t *testing.T) {
241241
w.WriteHeader(http.StatusNoContent)
242242
})
243243
}
244+
245+
// HandlePolicyExecuteSuccessfully sets up the test server to respond to a policies Execute request.
246+
func HandlePolicyExecuteSuccessfully(t *testing.T) {
247+
groupID := "60b15dad-5ea1-43fa-9a12-a1d737b4da07"
248+
policyID := "2b48d247-0282-4b9d-8775-5c4b67e8e649"
249+
250+
path := fmt.Sprintf("/groups/%s/policies/%s/execute", groupID, policyID)
251+
252+
th.Mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
253+
th.TestMethod(t, r, "POST")
254+
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
255+
256+
w.WriteHeader(http.StatusAccepted)
257+
fmt.Fprintf(w, "{}")
258+
})
259+
}

rackspace/autoscale/v1/policies/requests.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,15 @@ func Delete(client *gophercloud.ServiceClient, groupID, policyID string) DeleteR
216216

217217
return result
218218
}
219+
220+
// Execute requests the given policy be executed immediately.
221+
func Execute(client *gophercloud.ServiceClient, groupID, policyID string) ExecuteResult {
222+
var result ExecuteResult
223+
224+
url := executeURL(client, groupID, policyID)
225+
_, result.Err = client.Post(url, nil, &result.Body, &gophercloud.RequestOpts{
226+
OkCodes: []int{202},
227+
})
228+
229+
return result
230+
}

rackspace/autoscale/v1/policies/requests_test.go

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

141141
th.AssertNoErr(t, err)
142142
}
143+
144+
func TestExecute(t *testing.T) {
145+
th.SetupHTTP()
146+
defer th.TeardownHTTP()
147+
HandlePolicyExecuteSuccessfully(t)
148+
149+
client := client.ServiceClient()
150+
err := Execute(client, groupID, webhookPolicyID).ExtractErr()
151+
152+
th.AssertNoErr(t, err)
153+
}

rackspace/autoscale/v1/policies/results.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ type DeleteResult struct {
5757
gophercloud.ErrResult
5858
}
5959

60+
// ExecuteResult represents the result of an execute operation.
61+
type ExecuteResult struct {
62+
gophercloud.ErrResult
63+
}
64+
6065
// Policy represents a scaling policy.
6166
type Policy struct {
6267
// UUID for the policy.

rackspace/autoscale/v1/policies/urls.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ func updateURL(c *gophercloud.ServiceClient, groupID, policyID string) string {
2121
func deleteURL(c *gophercloud.ServiceClient, groupID, policyID string) string {
2222
return getURL(c, groupID, policyID)
2323
}
24+
25+
func executeURL(c *gophercloud.ServiceClient, groupID, policyID string) string {
26+
return c.ServiceURL("groups", groupID, "policies", policyID, "execute")
27+
}

0 commit comments

Comments
 (0)