Debian Codegraph @

fastly/health_check_test.go

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 package fastly
2
3 import "testing"
4
5 func TestClient_HealthChecks(t *testing.T) {
6 t.Parallel()
7
8 var err error
9 var tv *Version
10 record(t, "health_checks/version", func(c *Client) {
11 tv = testVersion(t, c)
12 })
13
14 // Create
15 var hc *HealthCheck
16 record(t, "health_checks/create", func(c *Client) {
17 hc, err = c.CreateHealthCheck(&CreateHealthCheckInput{
18 Service: testServiceID,
19 Version: tv.Number,
20 Name: "test-healthcheck",
21 Method: "HEAD",
22 Host: "example.com",
23 Path: "/foo",
24 HTTPVersion: "1.1",
25 Timeout: 1500,
26 CheckInterval: 2500,
27 ExpectedResponse: 200,
28 Window: 5000,
29 Threshold: 10,
30 Initial: 10,
31 })
32 })
33 if err != nil {
34 t.Fatal(err)
35 }
36
37 // Ensure deleted
38 defer func() {
39 record(t, "health_checks/cleanup", func(c *Client) {
40 c.DeleteHealthCheck(&DeleteHealthCheckInput{
41 Service: testServiceID,
42 Version: tv.Number,
43 Name: "test-healthcheck",
44 })
45
46 c.DeleteHealthCheck(&DeleteHealthCheckInput{
47 Service: testServiceID,
48 Version: tv.Number,
49 Name: "new-test-healthcheck",
50 })
51 })
52 }()
53
54 if hc.Name != "test-healthcheck" {
55 t.Errorf("bad name: %q", hc.Name)
56 }
57 if hc.Method != "HEAD" {
58 t.Errorf("bad address: %q", hc.Method)
59 }
60 if hc.Host != "example.com" {
61 t.Errorf("bad host: %q", hc.Host)
62 }
63 if hc.Path != "/foo" {
64 t.Errorf("bad path: %q", hc.Path)
65 }
66 if hc.HTTPVersion != "1.1" {
67 t.Errorf("bad http_version: %q", hc.HTTPVersion)
68 }
69 if hc.Timeout != 1500 {
70 t.Errorf("bad timeout: %q", hc.Timeout)
71 }
72 if hc.CheckInterval != 2500 {
73 t.Errorf("bad check_interval: %q", hc.CheckInterval)
74 }
75 if hc.ExpectedResponse != 200 {
76 t.Errorf("bad timeout: %q", hc.ExpectedResponse)
77 }
78 if hc.Window != 5000 {
79 t.Errorf("bad window: %q", hc.Window)
80 }
81 if hc.Threshold != 10 {
82 t.Errorf("bad threshold: %q", hc.Threshold)
83 }
84 if hc.Initial != 10 {
85 t.Errorf("bad initial: %q", hc.Initial)
86 }
87
88 // List
89 var hcs []*HealthCheck
90 record(t, "health_checks/list", func(c *Client) {
91 hcs, err = c.ListHealthChecks(&ListHealthChecksInput{
92 Service: testServiceID,
93 Version: tv.Number,
94 })
95 })
96 if err != nil {
97 t.Fatal(err)
98 }
99 if len(hcs) < 1 {
100 t.Errorf("bad health checks: %v", hcs)
101 }
102
103 // Get
104 var nhc *HealthCheck
105 record(t, "health_checks/get", func(c *Client) {
106 nhc, err = c.GetHealthCheck(&GetHealthCheckInput{
107 Service: testServiceID,
108 Version: tv.Number,
109 Name: "test-healthcheck",
110 })
111 })
112 if err != nil {
113 t.Fatal(err)
114 }
115 if hc.Name != nhc.Name {
116 t.Errorf("bad name: %q (%q)", hc.Name, nhc.Name)
117 }
118 if hc.Method != nhc.Method {
119 t.Errorf("bad address: %q", hc.Method)
120 }
121 if hc.Host != nhc.Host {
122 t.Errorf("bad host: %q", hc.Host)
123 }
124 if hc.Path != nhc.Path {
125 t.Errorf("bad path: %q", hc.Path)
126 }
127 if hc.HTTPVersion != nhc.HTTPVersion {
128 t.Errorf("bad http_version: %q", hc.HTTPVersion)
129 }
130 if hc.Timeout != nhc.Timeout {
131 t.Errorf("bad timeout: %q", hc.Timeout)
132 }
133 if hc.CheckInterval != nhc.CheckInterval {
134 t.Errorf("bad check_interval: %q", hc.CheckInterval)
135 }
136 if hc.ExpectedResponse != nhc.ExpectedResponse {
137 t.Errorf("bad timeout: %q", hc.ExpectedResponse)
138 }
139 if hc.Window != nhc.Window {
140 t.Errorf("bad window: %q", hc.Window)
141 }
142 if hc.Threshold != nhc.Threshold {
143 t.Errorf("bad threshold: %q", hc.Threshold)
144 }
145 if hc.Initial != nhc.Initial {
146 t.Errorf("bad initial: %q", hc.Initial)
147 }
148
149 // Update
150 var uhc *HealthCheck
151 record(t, "health_checks/update", func(c *Client) {
152 uhc, err = c.UpdateHealthCheck(&UpdateHealthCheckInput{
153 Service: testServiceID,
154 Version: tv.Number,
155 Name: "test-healthcheck",
156 NewName: "new-test-healthcheck",
157 })
158 })
159 if err != nil {
160 t.Fatal(err)
161 }
162 if uhc.Name != "new-test-healthcheck" {
163 t.Errorf("bad name: %q", uhc.Name)
164 }
165
166 // Delete
167 record(t, "health_checks/delete", func(c *Client) {
168 err = c.DeleteHealthCheck(&DeleteHealthCheckInput{
169 Service: testServiceID,
170 Version: tv.Number,
171 Name: "new-test-healthcheck",
172 })
173 })
174 if err != nil {
175 t.Fatal(err)
176 }
177 }
178
179 func TestClient_ListHealthChecks_validation(t *testing.T) {
180 var err error
181 _, err = testClient.ListHealthChecks(&ListHealthChecksInput{
182 Service: "",
183 })
184 if err != ErrMissingService {
185 t.Errorf("bad error: %s", err)
186 }
187
188 _, err = testClient.ListHealthChecks(&ListHealthChecksInput{
189 Service: "foo",
190 Version: 0,
191 })
192 if err != ErrMissingVersion {
193 t.Errorf("bad error: %s", err)
194 }
195 }
196
197 func TestClient_CreateHealthCheck_validation(t *testing.T) {
198 var err error
199 _, err = testClient.CreateHealthCheck(&CreateHealthCheckInput{
200 Service: "",
201 })
202 if err != ErrMissingService {
203 t.Errorf("bad error: %s", err)
204 }
205
206 _, err = testClient.CreateHealthCheck(&CreateHealthCheckInput{
207 Service: "foo",
208 Version: 0,
209 })
210 if err != ErrMissingVersion {
211 t.Errorf("bad error: %s", err)
212 }
213 }
214
215 func TestClient_GetHealthCheck_validation(t *testing.T) {
216 var err error
217 _, err = testClient.GetHealthCheck(&GetHealthCheckInput{
218 Service: "",
219 })
220 if err != ErrMissingService {
221 t.Errorf("bad error: %s", err)
222 }
223
224 _, err = testClient.GetHealthCheck(&GetHealthCheckInput{
225 Service: "foo",
226 Version: 0,
227 })
228 if err != ErrMissingVersion {
229 t.Errorf("bad error: %s", err)
230 }
231
232 _, err = testClient.GetHealthCheck(&GetHealthCheckInput{
233 Service: "foo",
234 Version: 1,
235 Name: "",
236 })
237 if err != ErrMissingName {
238 t.Errorf("bad error: %s", err)
239 }
240 }
241
242 func TestClient_UpdateHealthCheck_validation(t *testing.T) {
243 var err error
244 _, err = testClient.UpdateHealthCheck(&UpdateHealthCheckInput{
245 Service: "",
246 })
247 if err != ErrMissingService {
248 t.Errorf("bad error: %s", err)
249 }
250
251 _, err = testClient.UpdateHealthCheck(&UpdateHealthCheckInput{
252 Service: "foo",
253 Version: 0,
254 })
255 if err != ErrMissingVersion {
256 t.Errorf("bad error: %s", err)
257 }
258
259 _, err = testClient.UpdateHealthCheck(&UpdateHealthCheckInput{
260 Service: "foo",
261 Version: 1,
262 Name: "",
263 })
264 if err != ErrMissingName {
265 t.Errorf("bad error: %s", err)
266 }
267 }
268
269 func TestClient_DeleteHealthCheck_validation(t *testing.T) {
270 var err error
271 err = testClient.DeleteHealthCheck(&DeleteHealthCheckInput{
272 Service: "",
273 })
274 if err != ErrMissingService {
275 t.Errorf("bad error: %s", err)
276 }
277
278 err = testClient.DeleteHealthCheck(&DeleteHealthCheckInput{
279 Service: "foo",
280 Version: 0,
281 })
282 if err != ErrMissingVersion {
283 t.Errorf("bad error: %s", err)
284 }
285
286 err = testClient.DeleteHealthCheck(&DeleteHealthCheckInput{
287 Service: "foo",
288 Version: 1,
289 Name: "",
290 })
291 if err != ErrMissingName {
292 t.Errorf("bad error: %s", err)
293 }
294 }