Brad Ison | 53e997c | 2016-03-26 18:02:05 -0400 | [diff] [blame^] | 1 | // +build fixtures |
| 2 | |
| 3 | package policies |
| 4 | |
| 5 | import ( |
| 6 | "fmt" |
| 7 | "net/http" |
| 8 | "testing" |
| 9 | |
| 10 | th "github.com/rackspace/gophercloud/testhelper" |
| 11 | "github.com/rackspace/gophercloud/testhelper/client" |
| 12 | ) |
| 13 | |
| 14 | // PolicyListBody contains the canned body of a policies.List response. |
| 15 | const PolicyListBody = ` |
| 16 | { |
| 17 | "policies_links": [], |
| 18 | "policies": [ |
| 19 | { |
| 20 | "name": "webhook policy", |
| 21 | "links": [ |
| 22 | { |
| 23 | "href": "https://dfw.autoscale.api.rackspacecloud.com/v1.0/123456/groups/60b15dad-5ea1-43fa-9a12-a1d737b4da07/policies/2b48d247-0282-4b9d-8775-5c4b67e8e649/", |
| 24 | "rel": "self" |
| 25 | } |
| 26 | ], |
| 27 | "changePercent": 3, |
| 28 | "cooldown": 300, |
| 29 | "type": "webhook", |
| 30 | "id": "2b48d247-0282-4b9d-8775-5c4b67e8e649" |
| 31 | }, |
| 32 | { |
| 33 | "cooldown": 0, |
| 34 | "name": "one time", |
| 35 | "links": [ |
| 36 | { |
| 37 | "href": "https://dfw.autoscale.api.rackspacecloud.com/v1.0/123456/groups/60b15dad-5ea1-43fa-9a12-a1d737b4da07/policies/c175c31e-65f9-41de-8b15-918420d3253e/", |
| 38 | "rel": "self" |
| 39 | } |
| 40 | ], |
| 41 | "args": { |
| 42 | "at": "2020-04-01T23:00:00.000Z" |
| 43 | }, |
| 44 | "type": "schedule", |
| 45 | "id": "c175c31e-65f9-41de-8b15-918420d3253e", |
| 46 | "change": -1 |
| 47 | }, |
| 48 | { |
| 49 | "cooldown": 0, |
| 50 | "name": "sunday afternoon", |
| 51 | "links": [ |
| 52 | { |
| 53 | "href": "https://dfw.autoscale.api.rackspacecloud.com/v1.0/123456/groups/60b15dad-5ea1-43fa-9a12-a1d737b4da07/policies/e785e3e7-af9e-4f3c-99ae-b80a532e1663/", |
| 54 | "rel": "self" |
| 55 | } |
| 56 | ], |
| 57 | "args": { |
| 58 | "cron": "59 15 * * 0" |
| 59 | }, |
| 60 | "type": "schedule", |
| 61 | "id": "e785e3e7-af9e-4f3c-99ae-b80a532e1663", |
| 62 | "change": 2 |
| 63 | } |
| 64 | ] |
| 65 | } |
| 66 | ` |
| 67 | |
| 68 | var ( |
| 69 | // WebhookPolicy is a Policy corresponding to the first result in PolicyListBody. |
| 70 | WebhookPolicy = Policy{ |
| 71 | ID: "2b48d247-0282-4b9d-8775-5c4b67e8e649", |
| 72 | Name: "webhook policy", |
| 73 | Type: Webhook, |
| 74 | Cooldown: 300, |
| 75 | ChangePercent: 3, |
| 76 | } |
| 77 | |
| 78 | // OneTimePolicy is a Policy corresponding to the second result in PolicyListBody. |
| 79 | OneTimePolicy = Policy{ |
| 80 | ID: "c175c31e-65f9-41de-8b15-918420d3253e", |
| 81 | Name: "one time", |
| 82 | Type: Schedule, |
| 83 | Change: -1, |
| 84 | Args: map[string]interface{}{ |
| 85 | "at": "2020-04-01T23:00:00.000Z", |
| 86 | }, |
| 87 | } |
| 88 | |
| 89 | // SundayAfternoonPolicy is a Policy corresponding to the third result in PolicyListBody. |
| 90 | SundayAfternoonPolicy = Policy{ |
| 91 | ID: "e785e3e7-af9e-4f3c-99ae-b80a532e1663", |
| 92 | Name: "sunday afternoon", |
| 93 | Type: Schedule, |
| 94 | Change: 2, |
| 95 | Args: map[string]interface{}{ |
| 96 | "cron": "59 15 * * 0", |
| 97 | }, |
| 98 | } |
| 99 | ) |
| 100 | |
| 101 | // HandlePolicyListSuccessfully sets up the test server to respond to a policies List request. |
| 102 | func HandlePolicyListSuccessfully(t *testing.T) { |
| 103 | path := "/groups/10eb3219-1b12-4b34-b1e4-e10ee4f24c65/policies" |
| 104 | |
| 105 | th.Mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) { |
| 106 | th.TestMethod(t, r, "GET") |
| 107 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 108 | |
| 109 | w.Header().Add("Content-Type", "application/json") |
| 110 | |
| 111 | fmt.Fprintf(w, PolicyListBody) |
| 112 | }) |
| 113 | } |