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
|
before(:each) do
|
7
7
|
Flapjack::Diner.base_uri('localhost:19081')
|
@@ -11,87 +11,177 @@ describe Flapjack::Diner::Resources::Checks, :pact => true do
|
|
11
11
|
context 'create' do
|
12
12
|
|
13
13
|
it "submits a POST request for a check" do
|
14
|
-
|
15
|
-
|
16
|
-
:entity_id => '1234'
|
17
|
-
}]
|
14
|
+
req_data = check_json(check_data)
|
15
|
+
resp_data = req_data.merge(:relationships => check_rel(check_data))
|
18
16
|
|
19
|
-
flapjack.given("
|
17
|
+
flapjack.given("no data exists").
|
20
18
|
upon_receiving("a POST request with one check").
|
21
19
|
with(:method => :post, :path => '/checks',
|
22
20
|
:headers => {'Content-Type' => 'application/vnd.api+json'},
|
23
|
-
:body => {:
|
21
|
+
:body => {:data => req_data}).
|
24
22
|
will_respond_with(
|
25
23
|
:status => 201,
|
26
|
-
:headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
|
27
|
-
:body =>
|
24
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
25
|
+
:body => {:data => resp_data})
|
28
26
|
|
29
27
|
result = Flapjack::Diner.create_checks(check_data)
|
30
|
-
expect(result).to
|
28
|
+
expect(result).to eq(resultify(resp_data))
|
31
29
|
end
|
32
30
|
|
33
31
|
it "submits a POST request for several checks" do
|
34
|
-
|
35
|
-
|
36
|
-
:
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
flapjack.given("entities 'www.example.com', id '1234' and 'www2.example.com', id '5678' exist").
|
32
|
+
req_data = [check_json(check_data), check_json(check_2_data)]
|
33
|
+
resp_data = [
|
34
|
+
req_data[0].merge(:relationships => check_rel(check_data)),
|
35
|
+
req_data[1].merge(:relationships => check_rel(check_2_data))
|
36
|
+
]
|
37
|
+
|
38
|
+
flapjack.given("no data exists").
|
43
39
|
upon_receiving("a POST request with two checks").
|
40
|
+
with(:method => :post, :path => '/checks',
|
41
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; ext=bulk'},
|
42
|
+
:body => {:data => req_data}).
|
43
|
+
will_respond_with(
|
44
|
+
:status => 201,
|
45
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
46
|
+
:body => {'data' => resp_data})
|
47
|
+
|
48
|
+
result = Flapjack::Diner.create_checks(check_data, check_2_data)
|
49
|
+
expect(result).to eq(resultify(resp_data))
|
50
|
+
end
|
51
|
+
|
52
|
+
# TODO fails to create with invalid data
|
53
|
+
|
54
|
+
it "creates a check and links it to a tag" do
|
55
|
+
req_data = check_json(check_data).merge(
|
56
|
+
:relationships => {
|
57
|
+
:tags => {
|
58
|
+
:data => [{:type => 'tag', :id => tag_data[:id]}]
|
59
|
+
}
|
60
|
+
}
|
61
|
+
)
|
62
|
+
resp_data = req_data.merge(:relationships => check_rel(check_data))
|
63
|
+
|
64
|
+
flapjack.given("a tag exists").
|
65
|
+
upon_receiving("a POST request with a check linking to a tag").
|
44
66
|
with(:method => :post, :path => '/checks',
|
45
67
|
:headers => {'Content-Type' => 'application/vnd.api+json'},
|
46
|
-
:body => {:
|
68
|
+
:body => {:data => req_data}).
|
47
69
|
will_respond_with(
|
48
70
|
:status => 201,
|
49
|
-
:headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
|
50
|
-
:body =>
|
71
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
72
|
+
:body => {:data => resp_data})
|
51
73
|
|
52
|
-
result = Flapjack::Diner.create_checks(check_data)
|
53
|
-
expect(result).to
|
74
|
+
result = Flapjack::Diner.create_checks(check_data.merge(:tags => [tag_data[:id]]))
|
75
|
+
expect(result).to eq(resultify(resp_data))
|
54
76
|
end
|
55
77
|
|
56
78
|
end
|
57
79
|
|
58
80
|
context 'read' do
|
59
81
|
|
60
|
-
let(:check_data) { {:id => 'www.example.com:SSH',
|
61
|
-
:name => 'SSH',
|
62
|
-
:entity_name => 'www.example.com',
|
63
|
-
:links => {
|
64
|
-
:entities => ['1234']
|
65
|
-
}
|
66
|
-
}
|
67
|
-
}
|
68
|
-
|
69
82
|
context 'GET all checks' do
|
70
83
|
|
71
84
|
it "has no data" do
|
72
|
-
flapjack.given("no
|
85
|
+
flapjack.given("no data exists").
|
73
86
|
upon_receiving("a GET request for all checks").
|
74
87
|
with(:method => :get, :path => '/checks').
|
75
88
|
will_respond_with(
|
76
89
|
:status => 200,
|
77
|
-
:headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
|
78
|
-
:body => {:
|
90
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
91
|
+
:body => {:data => []} )
|
79
92
|
|
80
93
|
result = Flapjack::Diner.checks
|
81
94
|
expect(result).to eq([])
|
82
95
|
end
|
83
96
|
|
84
97
|
it "has some data" do
|
85
|
-
|
98
|
+
resp_data = [check_json(check_data).merge(:relationships => check_rel(check_data))]
|
99
|
+
|
100
|
+
flapjack.given("a check exists").
|
86
101
|
upon_receiving("a GET request for all checks").
|
87
102
|
with(:method => :get, :path => '/checks').
|
88
103
|
will_respond_with(
|
89
104
|
:status => 200,
|
90
|
-
:headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
|
91
|
-
:body => {:
|
105
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
106
|
+
:body => {:data => resp_data} )
|
92
107
|
|
93
108
|
result = Flapjack::Diner.checks
|
94
|
-
expect(result).to eq(
|
109
|
+
expect(result).to eq(resultify(resp_data))
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
context 'GET several checks' do
|
115
|
+
|
116
|
+
it 'has some data' do
|
117
|
+
resp_data = [
|
118
|
+
check_json(check_data).merge(:relationships => check_rel(check_data)),
|
119
|
+
check_json(check_2_data).merge(:relationships => check_rel(check_2_data))
|
120
|
+
]
|
121
|
+
|
122
|
+
flapjack.given("two checks exist").
|
123
|
+
upon_receiving("a GET request for two checks").
|
124
|
+
with(:method => :get, :path => "/checks",
|
125
|
+
:query => "filter%5B%5D=id%3A#{check_data[:id]}%7C#{check_2_data[:id]}").
|
126
|
+
will_respond_with(
|
127
|
+
:status => 200,
|
128
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
129
|
+
:body => {:data => resp_data})
|
130
|
+
|
131
|
+
result = Flapjack::Diner.checks(check_data[:id], check_2_data[:id])
|
132
|
+
expect(result).to eq(resultify(resp_data))
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'has no data' do
|
136
|
+
flapjack.given("no data exists").
|
137
|
+
upon_receiving("a GET request for two checks").
|
138
|
+
with(:method => :get, :path => "/checks",
|
139
|
+
:query => "filter%5B%5D=id%3A#{check_data[:id]}%7C#{check_2_data[:id]}").
|
140
|
+
will_respond_with(
|
141
|
+
:status => 200,
|
142
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
143
|
+
:body => {:data => []}
|
144
|
+
)
|
145
|
+
|
146
|
+
result = Flapjack::Diner.checks(check_data[:id], check_2_data[:id])
|
147
|
+
expect(result).to eq([])
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
context 'GET checks by name' do
|
153
|
+
|
154
|
+
let(:name) { CGI.escape(check_data[:name]) }
|
155
|
+
|
156
|
+
it 'has some data' do
|
157
|
+
resp_data = [check_json(check_data).merge(:relationships => check_rel(check_data))]
|
158
|
+
|
159
|
+
flapjack.given("a check exists").
|
160
|
+
upon_receiving("a GET request for checks by name").
|
161
|
+
with(:method => :get, :path => "/checks",
|
162
|
+
:query => "filter%5B%5D=name%3A#{name}").
|
163
|
+
will_respond_with(
|
164
|
+
:status => 200,
|
165
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
166
|
+
:body => {:data => resp_data} )
|
167
|
+
|
168
|
+
result = Flapjack::Diner.checks(:filter => {:name => check_data[:name]})
|
169
|
+
expect(result).to eq(resultify(resp_data))
|
170
|
+
end
|
171
|
+
|
172
|
+
it "can't find check" do
|
173
|
+
flapjack.given("no data exists").
|
174
|
+
upon_receiving("a GET request for checks by name").
|
175
|
+
with(:method => :get, :path => "/checks",
|
176
|
+
:query => "filter%5B%5D=name%3A#{name}").
|
177
|
+
will_respond_with(
|
178
|
+
:status => 200,
|
179
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
180
|
+
:body => {:data => []}
|
181
|
+
)
|
182
|
+
|
183
|
+
result = Flapjack::Diner.checks(:filter => {:name => check_data[:name]})
|
184
|
+
expect(result).to eq([])
|
95
185
|
end
|
96
186
|
|
97
187
|
end
|
@@ -99,71 +189,121 @@ describe Flapjack::Diner::Resources::Checks, :pact => true do
|
|
99
189
|
context 'GET a single check' do
|
100
190
|
|
101
191
|
it "has some data" do
|
102
|
-
|
103
|
-
|
104
|
-
|
192
|
+
resp_data = check_json(check_data).merge(:relationships => check_rel(check_data))
|
193
|
+
|
194
|
+
flapjack.given("a check exists").
|
195
|
+
upon_receiving("a GET request for a check").
|
196
|
+
with(:method => :get, :path => "/checks/#{check_data[:id]}").
|
105
197
|
will_respond_with(
|
106
198
|
:status => 200,
|
107
|
-
:headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
|
108
|
-
:body => {:
|
199
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
200
|
+
:body => {:data => resp_data} )
|
109
201
|
|
110
|
-
result = Flapjack::Diner.checks(
|
111
|
-
expect(result).to eq(
|
202
|
+
result = Flapjack::Diner.checks(check_data[:id])
|
203
|
+
expect(result).to eq(resultify(resp_data))
|
112
204
|
end
|
113
205
|
|
114
|
-
it "can't find
|
115
|
-
flapjack.given("no
|
116
|
-
upon_receiving("a GET request for check
|
117
|
-
with(:method => :get, :path =>
|
206
|
+
it "can't find check" do
|
207
|
+
flapjack.given("no data exists").
|
208
|
+
upon_receiving("a GET request for a check").
|
209
|
+
with(:method => :get, :path => "/checks/#{check_data[:id]}").
|
118
210
|
will_respond_with(
|
119
211
|
:status => 404,
|
120
|
-
:headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
|
121
|
-
:body => {:errors => [
|
122
|
-
|
123
|
-
|
212
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
213
|
+
:body => {:errors => [{
|
214
|
+
:status => '404',
|
215
|
+
:detail => "could not find Check record, id: '#{check_data[:id]}'"
|
216
|
+
}]}
|
217
|
+
)
|
218
|
+
|
219
|
+
result = Flapjack::Diner.checks(check_data[:id])
|
124
220
|
expect(result).to be_nil
|
125
|
-
expect(Flapjack::Diner.
|
126
|
-
:
|
221
|
+
expect(Flapjack::Diner.error).to eq([{:status => '404',
|
222
|
+
:detail => "could not find Check record, id: '#{check_data[:id]}'"}])
|
127
223
|
end
|
128
|
-
|
129
224
|
end
|
130
|
-
|
131
225
|
end
|
132
226
|
|
133
227
|
context 'update' do
|
134
228
|
|
135
|
-
it
|
136
|
-
flapjack.given("a check
|
229
|
+
it 'submits a PATCH request for a check' do
|
230
|
+
flapjack.given("a check exists").
|
137
231
|
upon_receiving("a PATCH request for a single check").
|
138
232
|
with(:method => :patch,
|
139
|
-
:path =>
|
140
|
-
:body =>
|
141
|
-
:headers => {'Content-Type'=>'application/
|
233
|
+
:path => "/checks/#{check_data[:id]}",
|
234
|
+
:body => {:data => {:id => check_data[:id], :type => 'check', :attributes => {:enabled => false}}},
|
235
|
+
:headers => {'Content-Type' => 'application/vnd.api+json'}).
|
236
|
+
will_respond_with(
|
237
|
+
:status => 204,
|
238
|
+
:body => '' )
|
239
|
+
|
240
|
+
result = Flapjack::Diner.update_checks(:id => check_data[:id], :enabled => false)
|
241
|
+
expect(result).to be_a(TrueClass)
|
242
|
+
end
|
243
|
+
|
244
|
+
it 'submits a PATCH request for several checks' do
|
245
|
+
flapjack.given("two checks exist").
|
246
|
+
upon_receiving("a PATCH request for two checks").
|
247
|
+
with(:method => :patch,
|
248
|
+
:path => "/checks",
|
249
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; ext=bulk'},
|
250
|
+
:body => {:data => [{:id => check_data[:id], :type => 'check', :attributes => {:enabled => false}},
|
251
|
+
{:id => check_2_data[:id], :type => 'check', :attributes => {:enabled => true}}]}).
|
142
252
|
will_respond_with(
|
143
253
|
:status => 204,
|
144
|
-
:body => '')
|
254
|
+
:body => '' )
|
145
255
|
|
146
|
-
result = Flapjack::Diner.update_checks(
|
147
|
-
|
148
|
-
|
256
|
+
result = Flapjack::Diner.update_checks(
|
257
|
+
{:id => check_data[:id], :enabled => false},
|
258
|
+
{:id => check_2_data[:id], :enabled => true})
|
259
|
+
expect(result).to be_a(TrueClass)
|
149
260
|
end
|
150
261
|
|
151
|
-
it "
|
152
|
-
flapjack.given("no
|
262
|
+
it "can't find the check to update" do
|
263
|
+
flapjack.given("no data exists").
|
153
264
|
upon_receiving("a PATCH request for a single check").
|
154
265
|
with(:method => :patch,
|
155
|
-
:path =>
|
156
|
-
:body =>
|
157
|
-
:headers => {'Content-Type'=>'application/
|
266
|
+
:path => "/checks/#{check_data[:id]}",
|
267
|
+
:body => {:data => {:id => check_data[:id], :type => 'check', :attributes => {:enabled => false}}},
|
268
|
+
:headers => {'Content-Type' => 'application/vnd.api+json'}).
|
158
269
|
will_respond_with(
|
159
270
|
:status => 404,
|
160
|
-
:headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
|
161
|
-
:body => {:errors => [
|
162
|
-
|
163
|
-
|
271
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
272
|
+
:body => {:errors => [{
|
273
|
+
:status => '404',
|
274
|
+
:detail => "could not find Check record, id: '#{check_data[:id]}'"
|
275
|
+
}]}
|
276
|
+
)
|
277
|
+
|
278
|
+
result = Flapjack::Diner.update_checks(:id => check_data[:id], :enabled => false)
|
164
279
|
expect(result).to be_nil
|
165
|
-
expect(Flapjack::Diner.
|
166
|
-
:
|
280
|
+
expect(Flapjack::Diner.error).to eq([{:status => '404',
|
281
|
+
:detail => "could not find Check record, id: '#{check_data[:id]}'"}])
|
282
|
+
end
|
283
|
+
|
284
|
+
it "replaces the tags for a check" do
|
285
|
+
req_data = {
|
286
|
+
:id => check_data[:id],
|
287
|
+
:type => 'check',
|
288
|
+
:relationships => {
|
289
|
+
:tags => {
|
290
|
+
:data => [{:type => 'tag', :id => tag_data[:id]}]
|
291
|
+
}
|
292
|
+
}
|
293
|
+
}
|
294
|
+
|
295
|
+
flapjack.given("a check and a tag exist").
|
296
|
+
upon_receiving("a PATCH request for a single check").
|
297
|
+
with(:method => :patch,
|
298
|
+
:path => "/checks/#{check_data[:id]}",
|
299
|
+
:body => {:data => req_data},
|
300
|
+
:headers => {'Content-Type' => 'application/vnd.api+json'}).
|
301
|
+
will_respond_with(
|
302
|
+
:status => 204,
|
303
|
+
:body => '' )
|
304
|
+
|
305
|
+
result = Flapjack::Diner.update_checks(:id => check_data[:id], :tags => [tag_data[:id]])
|
306
|
+
expect(result).to be_a(TrueClass)
|
167
307
|
end
|
168
308
|
|
169
309
|
end
|