flapjack-diner 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.rubocop.yml +21 -0
  4. data/.rubocop_todo.yml +135 -0
  5. data/Gemfile +7 -0
  6. data/README.md +86 -20
  7. data/flapjack-diner.gemspec +11 -15
  8. data/lib/flapjack-diner.rb +23 -548
  9. data/lib/flapjack-diner/argument_validator.rb +31 -22
  10. data/lib/flapjack-diner/resources/checks.rb +58 -0
  11. data/lib/flapjack-diner/resources/contacts.rb +70 -0
  12. data/lib/flapjack-diner/resources/entities.rb +68 -0
  13. data/lib/flapjack-diner/resources/maintenance_periods.rb +82 -0
  14. data/lib/flapjack-diner/resources/media.rb +61 -0
  15. data/lib/flapjack-diner/resources/notification_rules.rb +66 -0
  16. data/lib/flapjack-diner/resources/notifications.rb +27 -0
  17. data/lib/flapjack-diner/resources/pagerduty_credentials.rb +60 -0
  18. data/lib/flapjack-diner/resources/reports.rb +33 -0
  19. data/lib/flapjack-diner/tools.rb +277 -0
  20. data/lib/flapjack-diner/version.rb +1 -1
  21. data/spec/argument_validator_spec.rb +15 -15
  22. data/spec/flapjack-diner_spec.rb +58 -1275
  23. data/spec/pacts/flapjack-diner-flapjack.json +4522 -0
  24. data/spec/resources/checks_spec.rb +171 -0
  25. data/spec/resources/contacts_spec.rb +297 -0
  26. data/spec/resources/entities_spec.rb +181 -0
  27. data/spec/resources/maintenance_periods_spec.rb +603 -0
  28. data/spec/resources/media_spec.rb +277 -0
  29. data/spec/resources/notification_rules_spec.rb +341 -0
  30. data/spec/resources/notifications_spec.rb +210 -0
  31. data/spec/resources/pagerduty_credentials_spec.rb +243 -0
  32. data/spec/resources/reports_spec.rb +255 -0
  33. data/spec/spec_helper.rb +14 -2
  34. metadata +35 -72
@@ -0,0 +1,181 @@
1
+ require 'spec_helper'
2
+ require 'flapjack-diner'
3
+
4
+ describe Flapjack::Diner, :pact => true do
5
+
6
+ before(:each) do
7
+ Flapjack::Diner.base_uri('localhost:19081')
8
+ Flapjack::Diner.logger = nil
9
+ end
10
+
11
+ context 'create' do
12
+
13
+ it "submits a POST request for an entity" do
14
+ entity_data = [{
15
+ :name => 'example.org',
16
+ :id => '57_example'
17
+ }]
18
+
19
+ flapjack.given("no entity exists").
20
+ upon_receiving("a POST request with one entity").
21
+ with(:method => :post, :path => '/entities',
22
+ :headers => {'Content-Type' => 'application/vnd.api+json'},
23
+ :body => {:entities => entity_data}).
24
+ will_respond_with(
25
+ :status => 201,
26
+ :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
27
+ :body => ['57_example'] )
28
+
29
+ result = Flapjack::Diner.create_entities(entity_data)
30
+ expect(result).not_to be_nil
31
+ expect(result).to eq(['57_example'])
32
+ end
33
+
34
+ it "submits a POST request for several entities" do
35
+ entity_data = [{
36
+ :name => 'example.org',
37
+ :id => '57_example'
38
+ }, {
39
+ :name => 'example2.org',
40
+ :id => '58'
41
+ }]
42
+
43
+ flapjack.given("no entity exists").
44
+ upon_receiving("a POST request with two entities").
45
+ with(:method => :post, :path => '/entities',
46
+ :headers => {'Content-Type' => 'application/vnd.api+json'},
47
+ :body => {:entities => entity_data}).
48
+ will_respond_with(
49
+ :status => 201,
50
+ :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
51
+ :body => ['57_example', '58'] )
52
+
53
+ result = Flapjack::Diner.create_entities(entity_data)
54
+ expect(result).not_to be_nil
55
+ expect(result).to eq(['57_example', '58'])
56
+ end
57
+
58
+ end
59
+
60
+ context 'read' do
61
+
62
+ context 'GET all entities' do
63
+
64
+ it 'has some data' do
65
+ entity_data = {
66
+ :name => 'www.example.com',
67
+ :id => '1234'
68
+ }
69
+
70
+ flapjack.given("an entity 'www.example.com' with id '1234' exists").
71
+ upon_receiving("a GET request for all entities").
72
+ with(:method => :get, :path => '/entities').
73
+ will_respond_with(
74
+ :status => 200,
75
+ :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
76
+ :body => {:entities => [entity_data]} )
77
+
78
+ result = Flapjack::Diner.entities
79
+ expect(result).not_to be_nil
80
+ expect(result).to eq([entity_data])
81
+ end
82
+
83
+ it 'has no data' do
84
+ flapjack.given("no entity exists").
85
+ upon_receiving("a GET request for all entities").
86
+ with(:method => :get, :path => '/entities').
87
+ will_respond_with(
88
+ :status => 200,
89
+ :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
90
+ :body => {:entities => []} )
91
+
92
+ result = Flapjack::Diner.entities
93
+ expect(result).not_to be_nil
94
+ expect(result).to eq([])
95
+ end
96
+
97
+ end
98
+
99
+ context 'GET a single entity' do
100
+
101
+ it 'finds the entity' do
102
+ entity_data = {
103
+ :name => 'www.example.com',
104
+ :id => '1234'
105
+ }
106
+
107
+ flapjack.given("an entity 'www.example.com' with id '1234' exists").
108
+ upon_receiving("a GET request for a single entity").
109
+ with(:method => :get, :path => '/entities/1234').
110
+ will_respond_with(
111
+ :status => 200,
112
+ :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
113
+ :body => {:entities => [entity_data]} )
114
+
115
+ result = Flapjack::Diner.entities('1234')
116
+ expect(result).not_to be_nil
117
+ expect(result).to eq([entity_data])
118
+ end
119
+
120
+ it "can't find the entity" do
121
+ entity_data = {
122
+ :name => 'www.example.com',
123
+ :id => '1234'
124
+ }
125
+
126
+ flapjack.given("no entity exists").
127
+ upon_receiving("a GET request for a single entity").
128
+ with(:method => :get, :path => '/entities/1234').
129
+ will_respond_with(
130
+ :status => 404,
131
+ :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
132
+ :body => {:errors => ["could not find entities: '1234'"]} )
133
+
134
+ result = Flapjack::Diner.entities('1234')
135
+ expect(result).to be_nil
136
+ expect(Flapjack::Diner.last_error).to eq(:status_code => 404,
137
+ :errors => ["could not find entities: '1234'"])
138
+ end
139
+
140
+ end
141
+
142
+ end
143
+
144
+ context 'update' do
145
+
146
+ it "submits a PATCH request for an entity" do
147
+ flapjack.given("an entity 'www.example.com' with id '1234' exists").
148
+ upon_receiving("a PATCH request for a single entity").
149
+ with(:method => :patch,
150
+ :path => '/entities/1234',
151
+ :body => [{:op => 'replace', :path => '/entities/0/name', :value => 'example3.com'}],
152
+ :headers => {'Content-Type'=>'application/json-patch+json'}).
153
+ will_respond_with(
154
+ :status => 204,
155
+ :body => '')
156
+
157
+ result = Flapjack::Diner.update_entities('1234', :name => 'example3.com')
158
+ expect(result).not_to be_nil
159
+ expect(result).to be_truthy
160
+ end
161
+
162
+ it "can't find the entity to update" do
163
+ flapjack.given("no entity exists").
164
+ upon_receiving("a PATCH request for a single entity").
165
+ with(:method => :patch,
166
+ :path => '/entities/1234',
167
+ :body => [{:op => 'replace', :path => '/entities/0/name', :value => 'example3.com'}],
168
+ :headers => {'Content-Type'=>'application/json-patch+json'}).
169
+ will_respond_with(
170
+ :status => 404,
171
+ :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
172
+ :body => {:errors => ["could not find entity '1234'"]} )
173
+
174
+ result = Flapjack::Diner.update_entities('1234', :name => 'example3.com')
175
+ expect(Flapjack::Diner.last_error).to eq(:status_code => 404,
176
+ :errors => ["could not find entity '1234'"])
177
+ end
178
+
179
+ end
180
+
181
+ end
@@ -0,0 +1,603 @@
1
+ require 'spec_helper'
2
+ require 'flapjack-diner'
3
+
4
+ describe Flapjack::Diner::Resources::MaintenancePeriods, :pact => true do
5
+
6
+ let(:time) { Time.now }
7
+
8
+ before(:each) do
9
+ Flapjack::Diner.base_uri('localhost:19081')
10
+ Flapjack::Diner.logger = nil
11
+ end
12
+
13
+ context 'entities' do
14
+
15
+ context 'create' do
16
+
17
+ context 'scheduled maintenance periods' do
18
+
19
+ it "submits a POST request on an entity" do
20
+ data = [{:start_time => time.iso8601, :duration => 3600, :summary => 'working'}]
21
+
22
+ flapjack.given("an entity 'www.example.com' with id '1234' exists").
23
+ upon_receiving("a POST request with one scheduled maintenance period").
24
+ with(:method => :post, :path => '/scheduled_maintenances/entities/1234',
25
+ :headers => {'Content-Type' => 'application/vnd.api+json'},
26
+ :body => {:scheduled_maintenances => data}).
27
+ will_respond_with(
28
+ :status => 204,
29
+ :body => '')
30
+
31
+ result = Flapjack::Diner.create_scheduled_maintenances_entities('1234', data)
32
+ expect(result).not_to be_nil
33
+ expect(result).to be_truthy
34
+ end
35
+
36
+ it "submits a POST request on several entities" do
37
+ data = [{:start_time => time.iso8601, :duration => 3600, :summary => 'working'}]
38
+
39
+ flapjack.given("entities 'www.example.com', id '1234' and 'www2.example.com', id '5678' exist").
40
+ upon_receiving("a POST request with one scheduled maintenance period").
41
+ with(:method => :post, :path => '/scheduled_maintenances/entities/1234,5678',
42
+ :headers => {'Content-Type' => 'application/vnd.api+json'},
43
+ :body => {:scheduled_maintenances => data}).
44
+ will_respond_with(
45
+ :status => 204,
46
+ :body => '')
47
+
48
+ result = Flapjack::Diner.create_scheduled_maintenances_entities('1234', '5678', data)
49
+ expect(result).not_to be_nil
50
+ expect(result).to be_truthy
51
+ end
52
+
53
+ it "submits a POST request for multiple periods on an entity" do
54
+ data = [{:start_time => time.iso8601, :duration => 3600, :summary => 'working'},
55
+ {:start_time => (time + 7200).iso8601, :duration => 3600, :summary => 'more work'}]
56
+
57
+ flapjack.given("an entity 'www.example.com' with id '1234' exists").
58
+ upon_receiving("a POST request with two scheduled maintenance periods").
59
+ with(:method => :post, :path => '/scheduled_maintenances/entities/1234',
60
+ :headers => {'Content-Type' => 'application/vnd.api+json'},
61
+ :body => {:scheduled_maintenances => data}).
62
+ will_respond_with(
63
+ :status => 204,
64
+ :body => '')
65
+
66
+ result = Flapjack::Diner.create_scheduled_maintenances_entities('1234', data)
67
+ expect(result).not_to be_nil
68
+ expect(result).to be_truthy
69
+ end
70
+
71
+ it "submits a POST request for multiple periods on several entities" do
72
+ data = [{:start_time => time.iso8601, :duration => 3600, :summary => 'working'},
73
+ {:start_time => (time + 7200).iso8601, :duration => 3600, :summary => 'more work'}]
74
+
75
+ flapjack.given("entities 'www.example.com', id '1234' and 'www2.example.com', id '5678' exist").
76
+ upon_receiving("a POST request with two scheduled maintenance periods").
77
+ with(:method => :post, :path => '/scheduled_maintenances/entities/1234,5678',
78
+ :headers => {'Content-Type' => 'application/vnd.api+json'},
79
+ :body => {:scheduled_maintenances => data}).
80
+ will_respond_with(
81
+ :status => 204,
82
+ :body => '')
83
+
84
+ result = Flapjack::Diner.create_scheduled_maintenances_entities('1234', '5678', data)
85
+ expect(result).not_to be_nil
86
+ expect(result).to be_truthy
87
+ end
88
+
89
+ it "can't find the entity to create scheduled maintenance for" do
90
+ data = [{:start_time => time.iso8601, :duration => 3600, :summary => 'working'}]
91
+
92
+ flapjack.given("no entity exists").
93
+ upon_receiving("a POST request with one scheduled maintenance period").
94
+ with(:method => :post, :path => '/scheduled_maintenances/entities/1234',
95
+ :headers => {'Content-Type' => 'application/vnd.api+json'},
96
+ :body => {:scheduled_maintenances => data}).
97
+ will_respond_with(
98
+ :status => 404,
99
+ :body => {:errors => ["could not find entity '1234'"]})
100
+
101
+ result = Flapjack::Diner.create_scheduled_maintenances_entities('1234', data)
102
+ expect(result).to be_nil
103
+ expect(Flapjack::Diner.last_error).to eq(:status_code => 404,
104
+ :errors => ["could not find entity '1234'"])
105
+ end
106
+
107
+ end
108
+
109
+ context 'unscheduled maintenance periods' do
110
+
111
+ it "submits a POST request on an entity" do
112
+ data = [{:duration => 3600, :summary => 'working'}]
113
+
114
+ flapjack.given("an entity 'www.example.com' with id '1234' exists").
115
+ upon_receiving("a POST request with one unscheduled maintenance period").
116
+ with(:method => :post, :path => '/unscheduled_maintenances/entities/1234',
117
+ :headers => {'Content-Type' => 'application/vnd.api+json'},
118
+ :body => {:unscheduled_maintenances => data}).
119
+ will_respond_with(
120
+ :status => 204,
121
+ :body => '')
122
+
123
+ result = Flapjack::Diner.create_unscheduled_maintenances_entities('1234', data)
124
+ expect(result).not_to be_nil
125
+ expect(result).to be_truthy
126
+ end
127
+
128
+ it "submits a POST request on several entities" do
129
+ data = [{:duration => 3600, :summary => 'working'}]
130
+
131
+ flapjack.given("entities 'www.example.com', id '1234' and 'www2.example.com', id '5678' exist").
132
+ upon_receiving("a POST request with one unscheduled maintenance period").
133
+ with(:method => :post, :path => '/unscheduled_maintenances/entities/1234,5678',
134
+ :headers => {'Content-Type' => 'application/vnd.api+json'},
135
+ :body => {:unscheduled_maintenances => data}).
136
+ will_respond_with(
137
+ :status => 204,
138
+ :body => '')
139
+
140
+ result = Flapjack::Diner.create_unscheduled_maintenances_entities('1234', '5678', data)
141
+ expect(result).not_to be_nil
142
+ expect(result).to be_truthy
143
+ end
144
+
145
+ it "submits a POST request for multiple periods on an entity" do
146
+ data = [{:duration => 3600, :summary => 'working'},
147
+ {:duration => 3600, :summary => 'more work'}]
148
+
149
+ flapjack.given("an entity 'www.example.com' with id '1234' exists").
150
+ upon_receiving("a POST request with two unscheduled maintenance periods").
151
+ with(:method => :post, :path => '/unscheduled_maintenances/entities/1234',
152
+ :headers => {'Content-Type' => 'application/vnd.api+json'},
153
+ :body => {:unscheduled_maintenances => data}).
154
+ will_respond_with(
155
+ :status => 204,
156
+ :body => '')
157
+
158
+ result = Flapjack::Diner.create_unscheduled_maintenances_entities('1234', data)
159
+ expect(result).not_to be_nil
160
+ expect(result).to be_truthy
161
+ end
162
+
163
+ it "submits a POST request for multiple periods on several entities" do
164
+ data = [{:duration => 3600, :summary => 'working'},
165
+ {:duration => 3600, :summary => 'more work'}]
166
+
167
+ flapjack.given("entities 'www.example.com', id '1234' and 'www2.example.com', id '5678' exist").
168
+ upon_receiving("a POST request with two unscheduled maintenance periods").
169
+ with(:method => :post, :path => '/unscheduled_maintenances/entities/1234,5678',
170
+ :headers => {'Content-Type' => 'application/vnd.api+json'},
171
+ :body => {:unscheduled_maintenances => data}).
172
+ will_respond_with(
173
+ :status => 204,
174
+ :body => '')
175
+
176
+ result = Flapjack::Diner.create_unscheduled_maintenances_entities('1234', '5678', data)
177
+ expect(result).not_to be_nil
178
+ expect(result).to be_truthy
179
+ end
180
+
181
+ it "can't find the entity to create unscheduled maintenance for" do
182
+ data = [{:duration => 3600, :summary => 'working'}]
183
+
184
+ flapjack.given("no entity exists").
185
+ upon_receiving("a POST request with one unscheduled maintenance period").
186
+ with(:method => :post, :path => '/unscheduled_maintenances/entities/1234',
187
+ :headers => {'Content-Type' => 'application/vnd.api+json'},
188
+ :body => {:unscheduled_maintenances => data}).
189
+ will_respond_with(
190
+ :status => 404,
191
+ :body => {:errors => ["could not find entity '1234'"]})
192
+
193
+ result = Flapjack::Diner.create_unscheduled_maintenances_entities('1234', data)
194
+ expect(result).to be_nil
195
+ expect(Flapjack::Diner.last_error).to eq(:status_code => 404,
196
+ :errors => ["could not find entity '1234'"])
197
+
198
+ end
199
+
200
+ end
201
+
202
+ end
203
+
204
+ context 'update' do
205
+
206
+ it "submits a PATCH request for unscheduled maintenances on an entity" do
207
+ flapjack.given("an entity 'www.example.com' with id '1234' exists").
208
+ upon_receiving("a PATCH request for an unscheduled maintenance period").
209
+ with(:method => :patch,
210
+ :path => '/unscheduled_maintenances/entities/1234',
211
+ :body => [{:op => 'replace', :path => '/unscheduled_maintenances/0/end_time', :value => time.iso8601}],
212
+ :headers => {'Content-Type'=>'application/json-patch+json'}).
213
+ will_respond_with(
214
+ :status => 204,
215
+ :body => '')
216
+
217
+ result = Flapjack::Diner.update_unscheduled_maintenances_entities('1234', :end_time => time)
218
+ expect(result).not_to be_nil
219
+ expect(result).to be_truthy
220
+ end
221
+
222
+ it "submits a PATCH request for unscheduled maintenances on several entities" do
223
+ flapjack.given("entities 'www.example.com', id '1234' and 'www2.example.com', id '5678' exist").
224
+ upon_receiving("a PATCH request for an unscheduled maintenance period").
225
+ with(:method => :patch,
226
+ :path => '/unscheduled_maintenances/entities/1234,5678',
227
+ :body => [{:op => 'replace', :path => '/unscheduled_maintenances/0/end_time', :value => time.iso8601}],
228
+ :headers => {'Content-Type'=>'application/json-patch+json'}).
229
+ will_respond_with(
230
+ :status => 204,
231
+ :body => '')
232
+
233
+ result = Flapjack::Diner.update_unscheduled_maintenances_entities('1234', '5678', :end_time => time)
234
+ expect(result).not_to be_nil
235
+ expect(result).to be_truthy
236
+ end
237
+
238
+ it "can't find the entity to update maintenance for" do
239
+ flapjack.given("no entity exists").
240
+ upon_receiving("a PATCH request for an unscheduled maintenance period").
241
+ with(:method => :patch,
242
+ :path => '/unscheduled_maintenances/entities/1234',
243
+ :body => [{:op => 'replace', :path => '/unscheduled_maintenances/0/end_time', :value => time.iso8601}],
244
+ :headers => {'Content-Type'=>'application/json-patch+json'}).
245
+ will_respond_with(
246
+ :status => 404,
247
+ :body => {:errors => ["could not find entity '1234'"]})
248
+
249
+ result = Flapjack::Diner.update_unscheduled_maintenances_entities('1234', :end_time => time)
250
+ expect(result).to be_nil
251
+ expect(Flapjack::Diner.last_error).to eq(:status_code => 404,
252
+ :errors => ["could not find entity '1234'"])
253
+ end
254
+
255
+ end
256
+
257
+ context 'delete' do
258
+
259
+ it "submits a DELETE request for scheduled maintenances on an entity" do
260
+ flapjack.given("an entity 'www.example.com' with id '1234' exists").
261
+ upon_receiving("a DELETE request for a scheduled maintenance period").
262
+ with(:method => :delete,
263
+ :path => '/scheduled_maintenances/entities/1234',
264
+ :query => "start_time=#{URI.encode_www_form_component(time.iso8601)}").
265
+ will_respond_with(
266
+ :status => 204,
267
+ :body => '')
268
+
269
+ result = Flapjack::Diner.delete_scheduled_maintenances_entities('1234', :start_time => time.iso8601)
270
+ expect(result).not_to be_nil
271
+ expect(result).to be_truthy
272
+ end
273
+
274
+ it "submits a DELETE request for scheduled maintenances on several entities" do
275
+ flapjack.given("entities 'www.example.com', id '1234' and 'www2.example.com', id '5678' exist").
276
+ upon_receiving("a DELETE request for a scheduled maintenance period").
277
+ with(:method => :delete,
278
+ :path => '/scheduled_maintenances/entities/1234,5678',
279
+ :query => "start_time=#{URI.encode_www_form_component(time.iso8601)}").
280
+ will_respond_with(
281
+ :status => 204,
282
+ :body => '')
283
+
284
+ result = Flapjack::Diner.delete_scheduled_maintenances_entities('1234', '5678', :start_time => time.iso8601)
285
+ expect(result).not_to be_nil
286
+ expect(result).to be_truthy
287
+ end
288
+
289
+ it "can't find the entity to delete maintenance for" do
290
+ flapjack.given("no entity exists").
291
+ upon_receiving("a DELETE request for a scheduled maintenance period").
292
+ with(:method => :delete,
293
+ :path => '/scheduled_maintenances/entities/1234',
294
+ :query => "start_time=#{URI.encode_www_form_component(time.iso8601)}").
295
+ will_respond_with(
296
+ :status => 404,
297
+ :body => {:errors => ["could not find entity '1234'"]})
298
+
299
+ result = Flapjack::Diner.delete_scheduled_maintenances_entities('1234', :start_time => time.iso8601)
300
+ expect(result).to be_nil
301
+ expect(Flapjack::Diner.last_error).to eq(:status_code => 404,
302
+ :errors => ["could not find entity '1234'"])
303
+ end
304
+
305
+ end
306
+
307
+ end
308
+
309
+ context 'checks' do
310
+
311
+ context 'create' do
312
+
313
+ context 'scheduled maintenance periods' do
314
+
315
+ it "submits a POST request on a check" do
316
+ data = [{:start_time => time.iso8601, :duration => 3600, :summary => 'working'}]
317
+
318
+ flapjack.given("a check 'www.example.com:SSH' exists").
319
+ upon_receiving("a POST request with one scheduled maintenance period").
320
+ with(:method => :post, :path => '/scheduled_maintenances/checks/www.example.com:SSH',
321
+ :headers => {'Content-Type' => 'application/vnd.api+json'},
322
+ :body => {:scheduled_maintenances => data}).
323
+ will_respond_with(
324
+ :status => 204,
325
+ :body => '')
326
+
327
+ result = Flapjack::Diner.create_scheduled_maintenances_checks('www.example.com:SSH', data)
328
+ expect(result).not_to be_nil
329
+ expect(result).to be_truthy
330
+ end
331
+
332
+ it "submits a POST request on several checks" do
333
+ data = [{:start_time => time.iso8601, :duration => 3600, :summary => 'working'}]
334
+
335
+ flapjack.given("checks 'www.example.com:SSH' and 'www2.example.com:PING' exist").
336
+ upon_receiving("a POST request with one scheduled maintenance period").
337
+ with(:method => :post, :path => '/scheduled_maintenances/checks/www.example.com:SSH,www2.example.com:PING',
338
+ :headers => {'Content-Type' => 'application/vnd.api+json'},
339
+ :body => {:scheduled_maintenances => data}).
340
+ will_respond_with(
341
+ :status => 204,
342
+ :body => '')
343
+
344
+ result = Flapjack::Diner.create_scheduled_maintenances_checks('www.example.com:SSH', 'www2.example.com:PING', data)
345
+ expect(result).not_to be_nil
346
+ expect(result).to be_truthy
347
+ end
348
+
349
+ it "submits a POST request for multiple periods on a check" do
350
+ data = [{:start_time => time.iso8601, :duration => 3600, :summary => 'working'},
351
+ {:start_time => (time + 7200).iso8601, :duration => 3600, :summary => 'more work'}]
352
+
353
+ flapjack.given("a check 'www.example.com:SSH' exists").
354
+ upon_receiving("a POST request with two scheduled maintenance periods").
355
+ with(:method => :post, :path => '/scheduled_maintenances/checks/www.example.com:SSH',
356
+ :headers => {'Content-Type' => 'application/vnd.api+json'},
357
+ :body => {:scheduled_maintenances => data}).
358
+ will_respond_with(
359
+ :status => 204,
360
+ :body => '')
361
+
362
+ result = Flapjack::Diner.create_scheduled_maintenances_checks('www.example.com:SSH', data)
363
+ expect(result).not_to be_nil
364
+ expect(result).to be_truthy
365
+ end
366
+
367
+ it "submits a POST request for multiple periods on several checks" do
368
+ data = [{:start_time => time.iso8601, :duration => 3600, :summary => 'working'},
369
+ {:start_time => (time + 7200).iso8601, :duration => 3600, :summary => 'more work'}]
370
+
371
+ flapjack.given("checks 'www.example.com:SSH' and 'www2.example.com:PING' exist").
372
+ upon_receiving("a POST request with two scheduled maintenance periods").
373
+ with(:method => :post, :path => '/scheduled_maintenances/checks/www.example.com:SSH,www2.example.com:PING',
374
+ :headers => {'Content-Type' => 'application/vnd.api+json'},
375
+ :body => {:scheduled_maintenances => data}).
376
+ will_respond_with(
377
+ :status => 204,
378
+ :body => '')
379
+
380
+ result = Flapjack::Diner.create_scheduled_maintenances_checks('www.example.com:SSH', 'www2.example.com:PING', data)
381
+ expect(result).not_to be_nil
382
+ expect(result).to be_truthy
383
+ end
384
+
385
+ it "can't find the check to create scheduled maintenance for" do
386
+ data = [{:start_time => time.iso8601, :duration => 3600, :summary => 'working'}]
387
+
388
+ flapjack.given("no check exists").
389
+ upon_receiving("a POST request with one scheduled maintenance period").
390
+ with(:method => :post, :path => '/scheduled_maintenances/checks/www.example.com:SSH',
391
+ :headers => {'Content-Type' => 'application/vnd.api+json'},
392
+ :body => {:scheduled_maintenances => data}).
393
+ will_respond_with(
394
+ :status => 404,
395
+ :body => {:errors => ["could not find entity 'www.example.com'"]})
396
+
397
+ result = Flapjack::Diner.create_scheduled_maintenances_checks('www.example.com:SSH', data)
398
+ expect(result).to be_nil
399
+ expect(Flapjack::Diner.last_error).to eq(:status_code => 404,
400
+ :errors => ["could not find entity 'www.example.com'"])
401
+ end
402
+
403
+ end
404
+
405
+ context 'unscheduled maintenance periods' do
406
+
407
+ it "submits a POST request on a check" do
408
+ data = [{:duration => 3600, :summary => 'working'}]
409
+
410
+ flapjack.given("a check 'www.example.com:SSH' exists").
411
+ upon_receiving("a POST request with one unscheduled maintenance period").
412
+ with(:method => :post, :path => '/unscheduled_maintenances/checks/www.example.com:SSH',
413
+ :headers => {'Content-Type' => 'application/vnd.api+json'},
414
+ :body => {:unscheduled_maintenances => data}).
415
+ will_respond_with(
416
+ :status => 204,
417
+ :body => '')
418
+
419
+ result = Flapjack::Diner.create_unscheduled_maintenances_checks('www.example.com:SSH', data)
420
+ expect(result).not_to be_nil
421
+ expect(result).to be_truthy
422
+ end
423
+
424
+ it "submits a POST request on several checks" do
425
+ data = [{:duration => 3600, :summary => 'working'}]
426
+
427
+ flapjack.given("checks 'www.example.com:SSH' and 'www2.example.com:PING' exist").
428
+ upon_receiving("a POST request with one unscheduled maintenance period").
429
+ with(:method => :post, :path => '/unscheduled_maintenances/checks/www.example.com:SSH,www2.example.com:PING',
430
+ :headers => {'Content-Type' => 'application/vnd.api+json'},
431
+ :body => {:unscheduled_maintenances => data}).
432
+ will_respond_with(
433
+ :status => 204,
434
+ :body => '')
435
+
436
+ result = Flapjack::Diner.create_unscheduled_maintenances_checks('www.example.com:SSH', 'www2.example.com:PING', data)
437
+ expect(result).not_to be_nil
438
+ expect(result).to be_truthy
439
+ end
440
+
441
+ it "submits a POST request for multiple periods on a check" do
442
+ data = [{:duration => 3600, :summary => 'working'},
443
+ {:duration => 3600, :summary => 'more work'}]
444
+
445
+ flapjack.given("a check 'www.example.com:SSH' exists").
446
+ upon_receiving("a POST request with two unscheduled maintenance periods").
447
+ with(:method => :post, :path => '/unscheduled_maintenances/checks/www.example.com:SSH',
448
+ :headers => {'Content-Type' => 'application/vnd.api+json'},
449
+ :body => {:unscheduled_maintenances => data}).
450
+ will_respond_with(
451
+ :status => 204,
452
+ :body => '')
453
+
454
+ result = Flapjack::Diner.create_unscheduled_maintenances_checks('www.example.com:SSH', data)
455
+ expect(result).not_to be_nil
456
+ expect(result).to be_truthy
457
+ end
458
+
459
+ it "submits a POST request for multiple periods on several checks" do
460
+ data = [{:duration => 3600, :summary => 'working'},
461
+ {:duration => 3600, :summary => 'more work'}]
462
+
463
+ flapjack.given("checks 'www.example.com:SSH' and 'www2.example.com:PING' exist").
464
+ upon_receiving("a POST request with two unscheduled maintenance periods").
465
+ with(:method => :post, :path => '/unscheduled_maintenances/checks/www.example.com:SSH,www2.example.com:PING',
466
+ :headers => {'Content-Type' => 'application/vnd.api+json'},
467
+ :body => {:unscheduled_maintenances => data}).
468
+ will_respond_with(
469
+ :status => 204,
470
+ :body => '')
471
+
472
+ result = Flapjack::Diner.create_unscheduled_maintenances_checks('www.example.com:SSH', 'www2.example.com:PING', data)
473
+ expect(result).not_to be_nil
474
+ expect(result).to be_truthy
475
+ end
476
+
477
+ it "can't find the check to create unscheduled maintenance for" do
478
+ data = [{:duration => 3600, :summary => 'working'}]
479
+
480
+ flapjack.given("no check exists").
481
+ upon_receiving("a POST request with one unscheduled maintenance period").
482
+ with(:method => :post, :path => '/unscheduled_maintenances/checks/www.example.com:SSH',
483
+ :headers => {'Content-Type' => 'application/vnd.api+json'},
484
+ :body => {:unscheduled_maintenances => data}).
485
+ will_respond_with(
486
+ :status => 404,
487
+ :body => {:errors => ["could not find entity 'www.example.com'"]})
488
+
489
+ result = Flapjack::Diner.create_unscheduled_maintenances_checks('www.example.com:SSH', data)
490
+ expect(result).to be_nil
491
+ expect(Flapjack::Diner.last_error).to eq(:status_code => 404,
492
+ :errors => ["could not find entity 'www.example.com'"])
493
+ end
494
+
495
+ end
496
+
497
+ end
498
+
499
+ context 'update' do
500
+
501
+ it "submits a PATCH request for unscheduled maintenances on a check" do
502
+ flapjack.given("a check 'www.example.com:SSH' exists").
503
+ upon_receiving("a PATCH request for an unscheduled maintenance period").
504
+ with(:method => :patch,
505
+ :path => '/unscheduled_maintenances/checks/www.example.com:SSH',
506
+ :body => [{:op => 'replace', :path => '/unscheduled_maintenances/0/end_time', :value => time.iso8601}],
507
+ :headers => {'Content-Type'=>'application/json-patch+json'}).
508
+ will_respond_with(
509
+ :status => 204,
510
+ :body => '')
511
+
512
+ result = Flapjack::Diner.update_unscheduled_maintenances_checks('www.example.com:SSH', :end_time => time)
513
+ expect(result).not_to be_nil
514
+ expect(result).to be_truthy
515
+ end
516
+
517
+ it "submits a PATCH request for unscheduled maintenances on several checks" do
518
+ flapjack.given("checks 'www.example.com:SSH' and 'www2.example.com:PING' exist").
519
+ upon_receiving("a PATCH request for an unscheduled maintenance period").
520
+ with(:method => :patch,
521
+ :path => '/unscheduled_maintenances/checks/www.example.com:SSH,www2.example.com:PING',
522
+ :body => [{:op => 'replace', :path => '/unscheduled_maintenances/0/end_time', :value => time.iso8601}],
523
+ :headers => {'Content-Type'=>'application/json-patch+json'}).
524
+ will_respond_with(
525
+ :status => 204,
526
+ :body => '')
527
+
528
+ result = Flapjack::Diner.update_unscheduled_maintenances_checks('www.example.com:SSH', 'www2.example.com:PING', :end_time => time)
529
+ expect(result).not_to be_nil
530
+ expect(result).to be_truthy
531
+ end
532
+
533
+ it "can't find the check to update maintenance for" do
534
+ flapjack.given("no check exists").
535
+ upon_receiving("a PATCH request for an unscheduled maintenance period").
536
+ with(:method => :patch,
537
+ :path => '/unscheduled_maintenances/checks/www.example.com:SSH',
538
+ :body => [{:op => 'replace', :path => '/unscheduled_maintenances/0/end_time', :value => time.iso8601}],
539
+ :headers => {'Content-Type'=>'application/json-patch+json'}).
540
+ will_respond_with(
541
+ :status => 404,
542
+ :body => {:errors => ["could not find entity 'www.example.com'"]})
543
+
544
+ result = Flapjack::Diner.update_unscheduled_maintenances_checks('www.example.com:SSH', :end_time => time)
545
+ expect(result).to be_nil
546
+ expect(Flapjack::Diner.last_error).to eq(:status_code => 404,
547
+ :errors => ["could not find entity 'www.example.com'"])
548
+ end
549
+
550
+ end
551
+
552
+ context 'delete' do
553
+
554
+ it "submits a DELETE request for scheduled maintenances on a check" do
555
+ flapjack.given("a check 'www.example.com:SSH' exists").
556
+ upon_receiving("a DELETE request for a scheduled maintenance period").
557
+ with(:method => :delete,
558
+ :path => '/scheduled_maintenances/checks/www.example.com:SSH',
559
+ :query => "start_time=#{URI.encode_www_form_component(time.iso8601)}").
560
+ will_respond_with(
561
+ :status => 204,
562
+ :body => '')
563
+
564
+ result = Flapjack::Diner.delete_scheduled_maintenances_checks('www.example.com:SSH', :start_time => time.iso8601)
565
+ expect(result).not_to be_nil
566
+ expect(result).to be_truthy
567
+ end
568
+
569
+ it "submits a DELETE request for scheduled maintenances on several checks" do
570
+ flapjack.given("checks 'www.example.com:SSH' and 'www2.example.com:PING' exist").
571
+ upon_receiving("a DELETE request for a scheduled maintenance period").
572
+ with(:method => :delete,
573
+ :path => '/scheduled_maintenances/checks/www.example.com:SSH,www2.example.com:PING',
574
+ :query => "start_time=#{URI.encode_www_form_component(time.iso8601)}").
575
+ will_respond_with(
576
+ :status => 204,
577
+ :body => '')
578
+
579
+ result = Flapjack::Diner.delete_scheduled_maintenances_checks('www.example.com:SSH', 'www2.example.com:PING', :start_time => time.iso8601)
580
+ expect(result).not_to be_nil
581
+ expect(result).to be_truthy
582
+ end
583
+
584
+ it "can't find the check to delete maintenance for" do
585
+ flapjack.given("no check exists").
586
+ upon_receiving("a DELETE request for a scheduled maintenance period").
587
+ with(:method => :delete,
588
+ :path => '/scheduled_maintenances/checks/www.example.com:SSH',
589
+ :query => "start_time=#{URI.encode_www_form_component(time.iso8601)}").
590
+ will_respond_with(
591
+ :status => 404,
592
+ :body => {:errors => ["could not find entity 'www.example.com'"]})
593
+
594
+ result = Flapjack::Diner.delete_scheduled_maintenances_checks('www.example.com:SSH', :start_time => time.iso8601)
595
+ expect(result).to be_nil
596
+ expect(Flapjack::Diner.last_error).to eq(:status_code => 404,
597
+ :errors => ["could not find entity 'www.example.com'"])
598
+ end
599
+
600
+ end
601
+ end
602
+
603
+ end