flapjack-diner 1.4.0 → 2.0.0.a4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rspec +1 -1
- data/README.md +620 -413
- data/flapjack-diner.gemspec +1 -1
- data/lib/flapjack-diner/argument_validator.rb +77 -7
- data/lib/flapjack-diner/configuration.rb +409 -0
- data/lib/flapjack-diner/index_range.rb +42 -0
- data/lib/flapjack-diner/log_formatter.rb +22 -0
- data/lib/flapjack-diner/query.rb +114 -0
- data/lib/flapjack-diner/relationships.rb +180 -0
- data/lib/flapjack-diner/request.rb +280 -0
- data/lib/flapjack-diner/resources.rb +64 -0
- data/lib/flapjack-diner/response.rb +91 -0
- data/lib/flapjack-diner/tools.rb +47 -251
- data/lib/flapjack-diner/utility.rb +16 -0
- data/lib/flapjack-diner/version.rb +1 -1
- data/lib/flapjack-diner.rb +54 -20
- data/spec/argument_validator_spec.rb +87 -28
- data/spec/flapjack-diner_spec.rb +42 -64
- data/spec/relationships_spec.rb +211 -0
- data/spec/resources/checks_spec.rb +219 -79
- data/spec/resources/contacts_spec.rb +179 -151
- data/spec/resources/events_spec.rb +208 -0
- data/spec/resources/maintenance_periods_spec.rb +177 -565
- data/spec/resources/media_spec.rb +157 -171
- data/spec/resources/metrics_spec.rb +45 -0
- data/spec/resources/rules_spec.rb +278 -0
- data/spec/resources/states_spec.rb +93 -0
- data/spec/resources/statistics_spec.rb +53 -0
- data/spec/resources/tags_spec.rb +243 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/support/fixture_data.rb +541 -0
- metadata +33 -31
- data/.rubocop.yml +0 -21
- data/.rubocop_todo.yml +0 -135
- data/lib/flapjack-diner/resources/checks.rb +0 -64
- data/lib/flapjack-diner/resources/contacts.rb +0 -70
- data/lib/flapjack-diner/resources/entities.rb +0 -68
- data/lib/flapjack-diner/resources/maintenance_periods.rb +0 -82
- data/lib/flapjack-diner/resources/media.rb +0 -61
- data/lib/flapjack-diner/resources/notification_rules.rb +0 -66
- data/lib/flapjack-diner/resources/notifications.rb +0 -28
- data/lib/flapjack-diner/resources/pagerduty_credentials.rb +0 -59
- data/lib/flapjack-diner/resources/reports.rb +0 -33
- data/spec/pacts/flapjack-diner-flapjack.json +0 -4515
- data/spec/resources/entities_spec.rb +0 -181
- data/spec/resources/notification_rules_spec.rb +0 -341
- data/spec/resources/notifications_spec.rb +0 -208
- data/spec/resources/pagerduty_credentials_spec.rb +0 -237
- data/spec/resources/reports_spec.rb +0 -255
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'flapjack-diner'
|
3
3
|
|
4
|
-
describe Flapjack::Diner::Resources
|
4
|
+
describe Flapjack::Diner::Resources, :pact => true do
|
5
5
|
|
6
6
|
let(:time) { Time.now }
|
7
7
|
|
@@ -10,594 +10,206 @@ describe Flapjack::Diner::Resources::MaintenancePeriods, :pact => true do
|
|
10
10
|
Flapjack::Diner.logger = nil
|
11
11
|
end
|
12
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
|
-
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'}).
|
13
|
+
# TODO need tests for linkage to checks, deletion/ending from checks
|
14
|
+
|
15
|
+
context 'create' do
|
16
|
+
|
17
|
+
context 'scheduled maintenance periods' do
|
18
|
+
|
19
|
+
it "creates a scheduled maintenance period" do
|
20
|
+
req_data = maintenance_json('scheduled', scheduled_maintenance_data).merge(
|
21
|
+
:relationships => {
|
22
|
+
:check => {
|
23
|
+
:data => {:type => 'check', :id => check_data[:id]}
|
24
|
+
}
|
25
|
+
}
|
26
|
+
)
|
27
|
+
resp_data = maintenance_json('scheduled', scheduled_maintenance_data).
|
28
|
+
merge(:relationships => maintenance_rel('scheduled', scheduled_maintenance_data))
|
29
|
+
|
30
|
+
flapjack.given("a check exists").
|
31
|
+
upon_receiving("a POST request with one scheduled maintenance period").
|
32
|
+
with(:method => :post,
|
33
|
+
:path => '/scheduled_maintenances',
|
34
|
+
:headers => {'Content-Type' => 'application/vnd.api+json'},
|
35
|
+
:body => {:data => req_data}).
|
213
36
|
will_respond_with(
|
214
|
-
:status =>
|
215
|
-
:body =>
|
37
|
+
:status => 201,
|
38
|
+
:body => {:data => resp_data})
|
216
39
|
|
217
|
-
result = Flapjack::Diner.
|
40
|
+
result = Flapjack::Diner.create_scheduled_maintenances(scheduled_maintenance_data.merge(:check => check_data[:id]))
|
218
41
|
expect(result).not_to be_nil
|
219
|
-
expect(result).to
|
220
|
-
end
|
221
|
-
|
222
|
-
it "
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
42
|
+
expect(result).to eq(resultify(resp_data))
|
43
|
+
end
|
44
|
+
|
45
|
+
it "creates several scheduled maintenance periods" do
|
46
|
+
req_data = [
|
47
|
+
maintenance_json('scheduled', scheduled_maintenance_data).merge(
|
48
|
+
:relationships => {
|
49
|
+
:check => {
|
50
|
+
:data => {:type => 'check', :id => check_data[:id]}
|
51
|
+
}
|
52
|
+
}
|
53
|
+
),
|
54
|
+
maintenance_json('scheduled', scheduled_maintenance_2_data).merge(
|
55
|
+
:relationships => {
|
56
|
+
:check => {
|
57
|
+
:data => {:type => 'check', :id => check_data[:id]}
|
58
|
+
}
|
59
|
+
}
|
60
|
+
)
|
61
|
+
]
|
62
|
+
resp_data = [
|
63
|
+
maintenance_json('scheduled', scheduled_maintenance_data).
|
64
|
+
merge(:relationships => maintenance_rel('scheduled', scheduled_maintenance_data)),
|
65
|
+
maintenance_json('scheduled', scheduled_maintenance_2_data).
|
66
|
+
merge(:relationships => maintenance_rel('scheduled', scheduled_maintenance_2_data))
|
67
|
+
]
|
68
|
+
|
69
|
+
flapjack.given("a check exists").
|
70
|
+
upon_receiving("a POST request with two scheduled maintenance periods").
|
71
|
+
with(:method => :post,
|
72
|
+
:path => '/scheduled_maintenances',
|
73
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; ext=bulk'},
|
74
|
+
:body => {:data => req_data}).
|
229
75
|
will_respond_with(
|
230
|
-
:status =>
|
231
|
-
:
|
76
|
+
:status => 201,
|
77
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
78
|
+
:body => {:data => resp_data})
|
232
79
|
|
233
|
-
result = Flapjack::Diner.
|
80
|
+
result = Flapjack::Diner.create_scheduled_maintenances(scheduled_maintenance_data.merge(:check => check_data[:id]),
|
81
|
+
scheduled_maintenance_2_data.merge(:check => check_data[:id]))
|
234
82
|
expect(result).not_to be_nil
|
235
|
-
expect(result).to
|
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'"])
|
83
|
+
expect(result).to eq(resultify(resp_data))
|
253
84
|
end
|
254
85
|
|
255
86
|
end
|
256
87
|
|
257
|
-
|
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
|
88
|
+
end
|
288
89
|
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
90
|
+
context 'update' do
|
91
|
+
|
92
|
+
it 'submits a PATCH request for an unscheduled maintenance period' do
|
93
|
+
flapjack.given("an unscheduled maintenance period exists").
|
94
|
+
upon_receiving("a PATCH request for a single unscheduled maintenance period").
|
95
|
+
with(:method => :patch,
|
96
|
+
:path => "/unscheduled_maintenances/#{unscheduled_maintenance_data[:id]}",
|
97
|
+
:headers => {'Content-Type' => 'application/vnd.api+json'},
|
98
|
+
:body => {:data => {:id => unscheduled_maintenance_data[:id],
|
99
|
+
:type => 'unscheduled_maintenance',
|
100
|
+
:attributes => {:end_time => time.iso8601}}}).
|
101
|
+
will_respond_with(
|
102
|
+
:status => 204,
|
103
|
+
:body => '' )
|
104
|
+
|
105
|
+
result = Flapjack::Diner.update_unscheduled_maintenances(:id => unscheduled_maintenance_data[:id], :end_time => time)
|
106
|
+
expect(result).to be_a(TrueClass)
|
107
|
+
end
|
298
108
|
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
109
|
+
it 'submits a PATCH request for several unscheduled maintenance periods' do
|
110
|
+
flapjack.given("two unscheduled maintenance periods exist").
|
111
|
+
upon_receiving("a PATCH request for two unscheduled maintenance periods").
|
112
|
+
with(:method => :patch,
|
113
|
+
:path => "/unscheduled_maintenances",
|
114
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; ext=bulk'},
|
115
|
+
:body => {:data => [{:id => unscheduled_maintenance_data[:id],
|
116
|
+
:type => 'unscheduled_maintenance',
|
117
|
+
:attributes => {:end_time => time.iso8601}},
|
118
|
+
{:id => unscheduled_maintenance_2_data[:id],
|
119
|
+
:type => 'unscheduled_maintenance',
|
120
|
+
:attributes => {:end_time => (time + 3600).iso8601}}]}).
|
121
|
+
will_respond_with(
|
122
|
+
:status => 204,
|
123
|
+
:body => '' )
|
124
|
+
|
125
|
+
result = Flapjack::Diner.update_unscheduled_maintenances(
|
126
|
+
{:id => unscheduled_maintenance_data[:id], :end_time => time},
|
127
|
+
{:id => unscheduled_maintenance_2_data[:id], :end_time => time + 3600})
|
128
|
+
expect(result).to be_a(TrueClass)
|
129
|
+
end
|
304
130
|
|
131
|
+
it "can't find the unscheduled maintenance period to update" do
|
132
|
+
flapjack.given("no data exists").
|
133
|
+
upon_receiving("a PATCH request for a single unscheduled maintenance period").
|
134
|
+
with(:method => :patch,
|
135
|
+
:path => "/unscheduled_maintenances/#{unscheduled_maintenance_data[:id]}",
|
136
|
+
:headers => {'Content-Type' => 'application/vnd.api+json'},
|
137
|
+
:body => {:data => {:id => unscheduled_maintenance_data[:id],
|
138
|
+
:type => 'unscheduled_maintenance',
|
139
|
+
:attributes => {:end_time => time.iso8601}}}).
|
140
|
+
will_respond_with(
|
141
|
+
:status => 404,
|
142
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
143
|
+
:body => {:errors => [{
|
144
|
+
:status => '404',
|
145
|
+
:detail => "could not find UnscheduledMaintenance record, id: '#{unscheduled_maintenance_data[:id]}'"
|
146
|
+
}]}
|
147
|
+
)
|
148
|
+
|
149
|
+
result = Flapjack::Diner.update_unscheduled_maintenances(:id => unscheduled_maintenance_data[:id], :end_time => time)
|
150
|
+
expect(result).to be_nil
|
151
|
+
expect(Flapjack::Diner.error).to eq([{:status => '404',
|
152
|
+
:detail => "could not find UnscheduledMaintenance record, id: '#{unscheduled_maintenance_data[:id]}'"}])
|
305
153
|
end
|
306
154
|
|
307
155
|
end
|
308
156
|
|
309
|
-
context '
|
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
|
157
|
+
context 'delete' do
|
404
158
|
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
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
|
159
|
+
it "submits a DELETE request for a scheduled maintenance period" do
|
160
|
+
flapjack.given("a scheduled maintenance period exists").
|
161
|
+
upon_receiving("a DELETE request for a scheduled maintenance period").
|
162
|
+
with(:method => :delete,
|
163
|
+
:path => "/scheduled_maintenances/#{scheduled_maintenance_data[:id]}").
|
164
|
+
will_respond_with(
|
165
|
+
:status => 204,
|
166
|
+
:body => '')
|
496
167
|
|
168
|
+
result = Flapjack::Diner.delete_scheduled_maintenances(scheduled_maintenance_data[:id])
|
169
|
+
expect(result).to be_a(TrueClass)
|
497
170
|
end
|
498
171
|
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
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
|
-
|
172
|
+
it "submits a DELETE request for several scheduled maintenance periods" do
|
173
|
+
scheduled_maintenances_data = [
|
174
|
+
{:type => 'scheduled_maintenance', :id => scheduled_maintenance_data[:id]},
|
175
|
+
{:type => 'scheduled_maintenance', :id => scheduled_maintenance_2_data[:id]}
|
176
|
+
]
|
177
|
+
|
178
|
+
flapjack.given("two scheduled maintenance periods exist").
|
179
|
+
upon_receiving("a DELETE request for two scheduled maintenance periods").
|
180
|
+
with(:method => :delete,
|
181
|
+
:path => "/scheduled_maintenances",
|
182
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; ext=bulk'},
|
183
|
+
:body => {:data => scheduled_maintenances_data}).
|
184
|
+
will_respond_with(
|
185
|
+
:status => 204,
|
186
|
+
:body => '')
|
187
|
+
|
188
|
+
result = Flapjack::Diner.delete_scheduled_maintenances(scheduled_maintenance_data[:id], scheduled_maintenance_2_data[:id])
|
189
|
+
expect(result).to be_a(TrueClass)
|
550
190
|
end
|
551
191
|
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
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
|
-
|
192
|
+
it "can't find the scheduled maintenance period to delete" do
|
193
|
+
flapjack.given("no data exists").
|
194
|
+
upon_receiving("a DELETE request for a scheduled maintenance period").
|
195
|
+
with(:method => :delete,
|
196
|
+
:path => "/scheduled_maintenances/#{scheduled_maintenance_data[:id]}",
|
197
|
+
:body => nil).
|
198
|
+
will_respond_with(
|
199
|
+
:status => 404,
|
200
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
201
|
+
:body => {:errors => [{
|
202
|
+
:status => '404',
|
203
|
+
:detail => "could not find ScheduledMaintenance record, id: '#{scheduled_maintenance_data[:id]}'"
|
204
|
+
}]}
|
205
|
+
)
|
206
|
+
|
207
|
+
result = Flapjack::Diner.delete_scheduled_maintenances(scheduled_maintenance_data[:id])
|
208
|
+
expect(result).to be_nil
|
209
|
+
expect(Flapjack::Diner.error).to eq([{:status => '404',
|
210
|
+
:detail => "could not find ScheduledMaintenance record, id: '#{scheduled_maintenance_data[:id]}'"}])
|
600
211
|
end
|
212
|
+
|
601
213
|
end
|
602
214
|
|
603
215
|
end
|