File: fixtures.go

package info (click to toggle)
golang-github-rackspace-gophercloud 1.0.0%2Bgit20161013.1012.e00690e8-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 5,148 kB
  • ctags: 6,414
  • sloc: sh: 16; makefile: 6
file content (226 lines) | stat: -rw-r--r-- 7,356 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
// +build fixtures

package webhooks

import (
	"fmt"
	"net/http"
	"testing"

	"github.com/rackspace/gophercloud"
	th "github.com/rackspace/gophercloud/testhelper"
	"github.com/rackspace/gophercloud/testhelper/client"
)

// WebhookListBody contains the canned body of a webhooks.List response.
const WebhookListBody = `
{
  "webhooks": [
    {
      "id": "2bd1822c-58c5-49fd-8b3d-ed44781a58d1",
      "name": "first hook",
      "links": [
        {
          "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/",
          "rel": "self"
        },
        {
          "href": "https://dfw.autoscale.api.rackspacecloud.com/v1.0/execute/1/714c1c17c5e6ea5ef1e710d5ccc62e492575bab5216184d4c27dc0164db1bc06/",
          "rel": "capability"
        }
      ],
      "metadata": {}
    },
    {
      "id": "76711c36-dfbe-4f5e-bea6-cded99690515",
      "name": "second hook",
      "links": [
        {
          "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/",
          "rel": "self"
        },
        {
          "href": "https://dfw.autoscale.api.rackspacecloud.com/v1.0/execute/1/982e24858723f9e8bc2afea42a73a3c357c8f518857735400a7f7d8b3f14ccdb/",
          "rel": "capability"
        }
      ],
      "metadata": {
        "notes": "a note about this webhook"
      }
    }
  ],
  "webhooks_links": []
}
`

// WebhookCreateBody contains the canned body of a webhooks.Create response.
const WebhookCreateBody = WebhookListBody

// WebhookCreateRequest contains the canned body of a webhooks.Create request.
const WebhookCreateRequest = `
[
  {
    "name": "first hook"
  },
  {
    "name": "second hook",
    "metadata": {
      "notes": "a note about this webhook"
    }
  }
]
`

// WebhookGetBody contains the canned body of a webhooks.Get response.
const WebhookGetBody = `
{
  "webhook": {
    "id": "2bd1822c-58c5-49fd-8b3d-ed44781a58d1",
    "name": "first hook",
    "links": [
      {
        "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/",
        "rel": "self"
      },
      {
        "href": "https://dfw.autoscale.api.rackspacecloud.com/v1.0/execute/1/714c1c17c5e6ea5ef1e710d5ccc62e492575bab5216184d4c27dc0164db1bc06/",
        "rel": "capability"
      }
    ],
    "metadata": {}
  }
}
`

// WebhookUpdateRequest contains the canned body of a webhooks.Update request.
const WebhookUpdateRequest = `
{
  "name": "updated hook",
  "metadata": {
    "new-key": "some data"
  }
}
`

var (
	// FirstWebhook is a Webhook corresponding to the first result in WebhookListBody.
	FirstWebhook = Webhook{
		ID:   "2bd1822c-58c5-49fd-8b3d-ed44781a58d1",
		Name: "first hook",
		Links: []gophercloud.Link{
			{
				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/",
				Rel:  "self",
			},
			{
				Href: "https://dfw.autoscale.api.rackspacecloud.com/v1.0/execute/1/714c1c17c5e6ea5ef1e710d5ccc62e492575bab5216184d4c27dc0164db1bc06/",
				Rel:  "capability",
			},
		},
		Metadata: map[string]string{},
	}

	// SecondWebhook is a Webhook corresponding to the second result in WebhookListBody.
	SecondWebhook = Webhook{
		ID:   "76711c36-dfbe-4f5e-bea6-cded99690515",
		Name: "second hook",
		Links: []gophercloud.Link{
			{
				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/",
				Rel:  "self",
			},
			{
				Href: "https://dfw.autoscale.api.rackspacecloud.com/v1.0/execute/1/982e24858723f9e8bc2afea42a73a3c357c8f518857735400a7f7d8b3f14ccdb/",
				Rel:  "capability",
			},
		},
		Metadata: map[string]string{
			"notes": "a note about this webhook",
		},
	}
)

// HandleWebhookListSuccessfully sets up the test server to respond to a webhooks List request.
func HandleWebhookListSuccessfully(t *testing.T) {
	path := "/groups/10eb3219-1b12-4b34-b1e4-e10ee4f24c65/policies/2b48d247-0282-4b9d-8775-5c4b67e8e649/webhooks"

	th.Mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "GET")
		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)

		w.Header().Add("Content-Type", "application/json")

		fmt.Fprintf(w, WebhookListBody)
	})
}

// HandleWebhookCreateSuccessfully sets up the test server to respond to a webhooks Create request.
func HandleWebhookCreateSuccessfully(t *testing.T) {
	path := "/groups/10eb3219-1b12-4b34-b1e4-e10ee4f24c65/policies/2b48d247-0282-4b9d-8775-5c4b67e8e649/webhooks"

	th.Mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "POST")
		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
		th.TestHeader(t, r, "Content-Type", "application/json")
		th.TestHeader(t, r, "Accept", "application/json")

		th.TestJSONRequest(t, r, WebhookCreateRequest)

		w.Header().Add("Content-Type", "application/json")
		w.WriteHeader(http.StatusCreated)

		fmt.Fprintf(w, WebhookCreateBody)
	})
}

// HandleWebhookGetSuccessfully sets up the test server to respond to a webhooks Get request.
func HandleWebhookGetSuccessfully(t *testing.T) {
	groupID := "10eb3219-1b12-4b34-b1e4-e10ee4f24c65"
	policyID := "2b48d247-0282-4b9d-8775-5c4b67e8e649"
	webhookID := "2bd1822c-58c5-49fd-8b3d-ed44781a58d1"

	path := fmt.Sprintf("/groups/%s/policies/%s/webhooks/%s", groupID, policyID, webhookID)

	th.Mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "GET")
		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)

		w.Header().Add("Content-Type", "application/json")

		fmt.Fprintf(w, WebhookGetBody)
	})
}

// HandleWebhookUpdateSuccessfully sets up the test server to respond to a webhooks Update request.
func HandleWebhookUpdateSuccessfully(t *testing.T) {
	groupID := "10eb3219-1b12-4b34-b1e4-e10ee4f24c65"
	policyID := "2b48d247-0282-4b9d-8775-5c4b67e8e649"
	webhookID := "2bd1822c-58c5-49fd-8b3d-ed44781a58d1"

	path := fmt.Sprintf("/groups/%s/policies/%s/webhooks/%s", groupID, policyID, webhookID)

	th.Mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "PUT")
		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)

		th.TestJSONRequest(t, r, WebhookUpdateRequest)

		w.WriteHeader(http.StatusNoContent)
	})
}

// HandleWebhookDeleteSuccessfully sets up the test server to respond to a webhooks Delete request.
func HandleWebhookDeleteSuccessfully(t *testing.T) {
	groupID := "10eb3219-1b12-4b34-b1e4-e10ee4f24c65"
	policyID := "2b48d247-0282-4b9d-8775-5c4b67e8e649"
	webhookID := "2bd1822c-58c5-49fd-8b3d-ed44781a58d1"

	path := fmt.Sprintf("/groups/%s/policies/%s/webhooks/%s", groupID, policyID, webhookID)

	th.Mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "DELETE")
		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)

		w.WriteHeader(http.StatusNoContent)
	})
}