blob: 18f6b635bfc40ad36c5726257e4b70767d5610ca [file] [log] [blame]
Brad Ison366a7a02016-03-27 17:06:21 -04001// +build fixtures
2
3package webhooks
4
5import (
6 "fmt"
7 "net/http"
8 "testing"
9
10 "github.com/rackspace/gophercloud"
11 th "github.com/rackspace/gophercloud/testhelper"
12 "github.com/rackspace/gophercloud/testhelper/client"
13)
14
15// WebhookListBody contains the canned body of a webhooks.List response.
16const WebhookListBody = `
17{
18 "webhooks": [
19 {
20 "id": "2bd1822c-58c5-49fd-8b3d-ed44781a58d1",
21 "name": "first hook",
22 "links": [
23 {
24 "href": "https://dfw.autoscale.api.rackspacecloud.com/v1.0/123456/groups/60b15dad-5ea1-43fa-9a12-a1d737b4da07/policies/2b48d247-0282-4b9d-8775-5c4b67e8e649/webhooks/2bd1822c-58c5-49fd-8b3d-ed44781a58d1/",
25 "rel": "self"
26 },
27 {
28 "href": "https://dfw.autoscale.api.rackspacecloud.com/v1.0/execute/1/714c1c17c5e6ea5ef1e710d5ccc62e492575bab5216184d4c27dc0164db1bc06/",
29 "rel": "capability"
30 }
31 ],
32 "metadata": {}
33 },
34 {
35 "id": "76711c36-dfbe-4f5e-bea6-cded99690515",
36 "name": "second hook",
37 "links": [
38 {
39 "href": "https://dfw.autoscale.api.rackspacecloud.com/v1.0/123456/groups/60b15dad-5ea1-43fa-9a12-a1d737b4da07/policies/2b48d247-0282-4b9d-8775-5c4b67e8e649/webhooks/76711c36-dfbe-4f5e-bea6-cded99690515/",
40 "rel": "self"
41 },
42 {
43 "href": "https://dfw.autoscale.api.rackspacecloud.com/v1.0/execute/1/982e24858723f9e8bc2afea42a73a3c357c8f518857735400a7f7d8b3f14ccdb/",
44 "rel": "capability"
45 }
46 ],
47 "metadata": {
48 "notes": "a note about this webhook"
49 }
50 }
51 ],
52 "webhooks_links": []
53}
54`
55
56var (
57 // FirstWebhook is a Webhook corresponding to the first result in WebhookListBody.
58 FirstWebhook = Webhook{
59 ID: "2bd1822c-58c5-49fd-8b3d-ed44781a58d1",
60 Name: "first hook",
61 Links: []gophercloud.Link{
62 {
63 Href: "https://dfw.autoscale.api.rackspacecloud.com/v1.0/123456/groups/60b15dad-5ea1-43fa-9a12-a1d737b4da07/policies/2b48d247-0282-4b9d-8775-5c4b67e8e649/webhooks/2bd1822c-58c5-49fd-8b3d-ed44781a58d1/",
64 Rel: "self",
65 },
66 {
67 Href: "https://dfw.autoscale.api.rackspacecloud.com/v1.0/execute/1/714c1c17c5e6ea5ef1e710d5ccc62e492575bab5216184d4c27dc0164db1bc06/",
68 Rel: "capability",
69 },
70 },
71 Metadata: map[string]string{},
72 }
73
74 // SecondWebhook is a Webhook corresponding to the second result in WebhookListBody.
75 SecondWebhook = Webhook{
76 ID: "76711c36-dfbe-4f5e-bea6-cded99690515",
77 Name: "second hook",
78 Links: []gophercloud.Link{
79 {
80 Href: "https://dfw.autoscale.api.rackspacecloud.com/v1.0/123456/groups/60b15dad-5ea1-43fa-9a12-a1d737b4da07/policies/2b48d247-0282-4b9d-8775-5c4b67e8e649/webhooks/76711c36-dfbe-4f5e-bea6-cded99690515/",
81 Rel: "self",
82 },
83 {
84 Href: "https://dfw.autoscale.api.rackspacecloud.com/v1.0/execute/1/982e24858723f9e8bc2afea42a73a3c357c8f518857735400a7f7d8b3f14ccdb/",
85 Rel: "capability",
86 },
87 },
88 Metadata: map[string]string{
89 "notes": "a note about this webhook",
90 },
91 }
92)
93
94// HandleWebhookListSuccessfully sets up the test server to respond to a webhooks List request.
95func HandleWebhookListSuccessfully(t *testing.T) {
96 path := "/groups/10eb3219-1b12-4b34-b1e4-e10ee4f24c65/policies/2b48d247-0282-4b9d-8775-5c4b67e8e649/webhooks"
97
98 th.Mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
99 th.TestMethod(t, r, "GET")
100 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
101
102 w.Header().Add("Content-Type", "application/json")
103
104 fmt.Fprintf(w, WebhookListBody)
105 })
106}