flapjack-diner 2.0.0.pre.alpha.3 → 2.0.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 (46) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +6 -10
  3. data/README.md +165 -272
  4. data/flapjack-diner.gemspec +1 -1
  5. data/lib/flapjack-diner.rb +54 -25
  6. data/lib/flapjack-diner/argument_validator.rb +0 -17
  7. data/lib/flapjack-diner/configuration.rb +417 -0
  8. data/lib/flapjack-diner/log_formatter.rb +22 -0
  9. data/lib/flapjack-diner/query.rb +114 -0
  10. data/lib/flapjack-diner/relationships.rb +180 -0
  11. data/lib/flapjack-diner/request.rb +280 -0
  12. data/lib/flapjack-diner/resources.rb +64 -0
  13. data/lib/flapjack-diner/response.rb +91 -0
  14. data/lib/flapjack-diner/tools.rb +46 -456
  15. data/lib/flapjack-diner/utility.rb +16 -0
  16. data/lib/flapjack-diner/version.rb +1 -1
  17. data/spec/flapjack-diner_spec.rb +9 -18
  18. data/spec/{resources/relationships_spec.rb → relationships_spec.rb} +75 -29
  19. data/spec/resources/checks_spec.rb +7 -7
  20. data/spec/resources/contacts_spec.rb +21 -19
  21. data/spec/resources/events_spec.rb +13 -13
  22. data/spec/resources/maintenance_periods_spec.rb +3 -3
  23. data/spec/resources/media_spec.rb +3 -3
  24. data/spec/resources/metrics_spec.rb +1 -1
  25. data/spec/resources/rules_spec.rb +278 -0
  26. data/spec/resources/states_spec.rb +1 -1
  27. data/spec/resources/statistics_spec.rb +1 -1
  28. data/spec/resources/tags_spec.rb +75 -19
  29. data/spec/support/fixture_data.rb +57 -98
  30. metadata +21 -29
  31. data/.rubocop.yml +0 -21
  32. data/.rubocop_todo.yml +0 -135
  33. data/lib/flapjack-diner/resources/acceptors.rb +0 -77
  34. data/lib/flapjack-diner/resources/checks.rb +0 -52
  35. data/lib/flapjack-diner/resources/contacts.rb +0 -54
  36. data/lib/flapjack-diner/resources/events.rb +0 -54
  37. data/lib/flapjack-diner/resources/maintenance_periods.rb +0 -76
  38. data/lib/flapjack-diner/resources/media.rb +0 -75
  39. data/lib/flapjack-diner/resources/metrics.rb +0 -23
  40. data/lib/flapjack-diner/resources/rejectors.rb +0 -77
  41. data/lib/flapjack-diner/resources/relationships.rb +0 -314
  42. data/lib/flapjack-diner/resources/states.rb +0 -24
  43. data/lib/flapjack-diner/resources/statistics.rb +0 -24
  44. data/lib/flapjack-diner/resources/tags.rb +0 -47
  45. data/spec/resources/acceptors_spec.rb +0 -278
  46. data/spec/resources/rejectors_spec.rb +0 -278
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'flapjack-diner'
3
3
 
4
- describe Flapjack::Diner::Resources::Events, :pact => true do
4
+ describe Flapjack::Diner::Resources, :pact => true do
5
5
 
6
6
  before(:each) do
7
7
  Flapjack::Diner.base_uri('localhost:19081')
@@ -41,7 +41,7 @@ describe Flapjack::Diner::Resources::Events, :pact => true do
41
41
  req_data = test_notification_json(test_notification_data).merge(
42
42
  :relationships => {
43
43
  :tag => {
44
- :data => {:type => 'tag', :id => tag_data[:name]}
44
+ :data => {:type => 'tag', :id => tag_data[:id]}
45
45
  }
46
46
  }
47
47
  )
@@ -57,7 +57,7 @@ describe Flapjack::Diner::Resources::Events, :pact => true do
57
57
  :headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
58
58
  :body => {:data => resp_data})
59
59
 
60
- result = Flapjack::Diner.create_test_notifications(test_notification_data.merge(:tag => tag_data[:name]))
60
+ result = Flapjack::Diner.create_test_notifications(test_notification_data.merge(:tag => tag_data[:id]))
61
61
  expect(result).not_to be_nil
62
62
  expect(result).to eq(resultify(resp_data))
63
63
  end
@@ -107,14 +107,14 @@ describe Flapjack::Diner::Resources::Events, :pact => true do
107
107
  test_notification_json(test_notification_data).merge(
108
108
  :relationships => {
109
109
  :tag => {
110
- :data => {:type => 'tag', :id => tag_data[:name]}
110
+ :data => {:type => 'tag', :id => tag_data[:id]}
111
111
  }
112
112
  }
113
113
  ),
114
114
  test_notification_json(test_notification_2_data).merge(
115
115
  :relationships => {
116
116
  :tag => {
117
- :data => {:type => 'tag', :id => tag_data[:name]}
117
+ :data => {:type => 'tag', :id => tag_data[:id]}
118
118
  }
119
119
  }
120
120
  )
@@ -136,8 +136,8 @@ describe Flapjack::Diner::Resources::Events, :pact => true do
136
136
  :body => {:data => resp_data})
137
137
 
138
138
  result = Flapjack::Diner.create_test_notifications(
139
- test_notification_data.merge(:tag => tag_data[:name]),
140
- test_notification_2_data.merge(:tag => tag_data[:name])
139
+ test_notification_data.merge(:tag => tag_data[:id]),
140
+ test_notification_2_data.merge(:tag => tag_data[:id])
141
141
  )
142
142
  expect(result).not_to be_nil
143
143
  expect(result).to eq(resultify(resp_data))
@@ -168,7 +168,7 @@ describe Flapjack::Diner::Resources::Events, :pact => true do
168
168
 
169
169
  result = Flapjack::Diner.create_test_notifications(test_notification_data.merge(:check => check_data[:id]))
170
170
  expect(result).to be_nil
171
- expect(Flapjack::Diner.last_error).to eq([{:status => '404',
171
+ expect(Flapjack::Diner.error).to eq([{:status => '404',
172
172
  :detail => "could not find Check record, id: '#{check_data[:id]}'"}])
173
173
  end
174
174
 
@@ -176,7 +176,7 @@ describe Flapjack::Diner::Resources::Events, :pact => true do
176
176
  req_data = test_notification_json(test_notification_data).merge(
177
177
  :relationships => {
178
178
  :tag => {
179
- :data => {:type => 'tag', :id => tag_data[:name]}
179
+ :data => {:type => 'tag', :id => tag_data[:id]}
180
180
  }
181
181
  }
182
182
  )
@@ -191,14 +191,14 @@ describe Flapjack::Diner::Resources::Events, :pact => true do
191
191
  :headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
192
192
  :body => {:errors => [{
193
193
  :status => '404',
194
- :detail => "could not find Tag record, id: '#{tag_data[:name]}'"
194
+ :detail => "could not find Tag record, id: '#{tag_data[:id]}'"
195
195
  }]}
196
196
  )
197
197
 
198
- result = Flapjack::Diner.create_test_notifications(test_notification_data.merge(:tag => tag_data[:name]))
198
+ result = Flapjack::Diner.create_test_notifications(test_notification_data.merge(:tag => tag_data[:id]))
199
199
  expect(result).to be_nil
200
- expect(Flapjack::Diner.last_error).to eq([{:status => '404',
201
- :detail => "could not find Tag record, id: '#{tag_data[:name]}'"}])
200
+ expect(Flapjack::Diner.error).to eq([{:status => '404',
201
+ :detail => "could not find Tag record, id: '#{tag_data[:id]}'"}])
202
202
  end
203
203
 
204
204
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'flapjack-diner'
3
3
 
4
- describe Flapjack::Diner::Resources::MaintenancePeriods, :pact => true do
4
+ describe Flapjack::Diner::Resources, :pact => true do
5
5
 
6
6
  let(:time) { Time.now }
7
7
 
@@ -148,7 +148,7 @@ describe Flapjack::Diner::Resources::MaintenancePeriods, :pact => true do
148
148
 
149
149
  result = Flapjack::Diner.update_unscheduled_maintenances(:id => unscheduled_maintenance_data[:id], :end_time => time)
150
150
  expect(result).to be_nil
151
- expect(Flapjack::Diner.last_error).to eq([{:status => '404',
151
+ expect(Flapjack::Diner.error).to eq([{:status => '404',
152
152
  :detail => "could not find UnscheduledMaintenance record, id: '#{unscheduled_maintenance_data[:id]}'"}])
153
153
  end
154
154
 
@@ -206,7 +206,7 @@ describe Flapjack::Diner::Resources::MaintenancePeriods, :pact => true do
206
206
 
207
207
  result = Flapjack::Diner.delete_scheduled_maintenances(scheduled_maintenance_data[:id])
208
208
  expect(result).to be_nil
209
- expect(Flapjack::Diner.last_error).to eq([{:status => '404',
209
+ expect(Flapjack::Diner.error).to eq([{:status => '404',
210
210
  :detail => "could not find ScheduledMaintenance record, id: '#{scheduled_maintenance_data[:id]}'"}])
211
211
  end
212
212
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'flapjack-diner'
3
3
 
4
- describe Flapjack::Diner::Resources::Media, :pact => true do
4
+ describe Flapjack::Diner::Resources, :pact => true do
5
5
 
6
6
  before(:each) do
7
7
  Flapjack::Diner.base_uri('localhost:19081')
@@ -198,7 +198,7 @@ describe Flapjack::Diner::Resources::Media, :pact => true do
198
198
 
199
199
  result = Flapjack::Diner.update_media(:id => email_data[:id], :interval => 50)
200
200
  expect(result).to be_nil
201
- expect(Flapjack::Diner.last_error).to eq([{:status => '404',
201
+ expect(Flapjack::Diner.error).to eq([{:status => '404',
202
202
  :detail => "could not find Medium record, id: '#{email_data[:id]}'"}])
203
203
  end
204
204
 
@@ -254,7 +254,7 @@ describe Flapjack::Diner::Resources::Media, :pact => true do
254
254
 
255
255
  result = Flapjack::Diner.delete_media(sms_data[:id])
256
256
  expect(result).to be_nil
257
- expect(Flapjack::Diner.last_error).to eq([{:status => '404',
257
+ expect(Flapjack::Diner.error).to eq([{:status => '404',
258
258
  :detail => "could not find Medium record, id: '#{sms_data[:id]}'"}])
259
259
  end
260
260
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'flapjack-diner'
3
3
 
4
- describe Flapjack::Diner::Resources::Metrics, :pact => true do
4
+ describe Flapjack::Diner::Resources, :pact => true do
5
5
 
6
6
  before(:each) do
7
7
  Flapjack::Diner.base_uri('localhost:19081')
@@ -0,0 +1,278 @@
1
+ require 'spec_helper'
2
+ require 'flapjack-diner'
3
+
4
+ describe Flapjack::Diner::Resources, :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 rule" do
14
+ req_data = rule_json(rule_data).merge(
15
+ :relationships => {
16
+ :contact => {
17
+ :data => {
18
+ :type => 'contact',
19
+ :id => contact_data[:id]
20
+ }
21
+ }
22
+ }
23
+ )
24
+ resp_data = rule_json(rule_data).merge(:relationships => rule_rel(rule_data))
25
+
26
+ flapjack.given("a contact exists").
27
+ upon_receiving("a POST request with one rule").
28
+ with(:method => :post, :path => '/rules',
29
+ :headers => {'Content-Type' => 'application/vnd.api+json'},
30
+ :body => {:data => req_data}).
31
+ will_respond_with(
32
+ :status => 201,
33
+ :headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
34
+ :body => {:data => resp_data}
35
+ )
36
+
37
+ result = Flapjack::Diner.create_rules(rule_data.merge(:contact => contact_data[:id]))
38
+ expect(result).not_to be_nil
39
+ expect(result).to eq(resultify(resp_data))
40
+ end
41
+
42
+ it "submits a POST request for several rules" do
43
+ req_data = [rule_json(rule_data).merge(
44
+ :relationships => {
45
+ :contact => {
46
+ :data => {
47
+ :type => 'contact',
48
+ :id => contact_data[:id]
49
+ }
50
+ }
51
+ }
52
+ ), rule_json(rule_2_data).merge(
53
+ :relationships => {
54
+ :contact => {
55
+ :data => {
56
+ :type => 'contact',
57
+ :id => contact_data[:id]
58
+ }
59
+ }
60
+ }
61
+ )]
62
+ resp_data = [
63
+ rule_json(rule_data).merge(:relationships => rule_rel(rule_data)),
64
+ rule_json(rule_2_data).merge(:relationships => rule_rel(rule_2_data))
65
+ ]
66
+
67
+ flapjack.given("a contact exists").
68
+ upon_receiving("a POST request with two rules").
69
+ with(:method => :post, :path => '/rules',
70
+ :headers => {'Content-Type' => 'application/vnd.api+json; ext=bulk'},
71
+ :body => {:data => req_data}).
72
+ will_respond_with(
73
+ :status => 201,
74
+ :headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
75
+ :body => {:data => resp_data}
76
+ )
77
+
78
+ result = Flapjack::Diner.create_rules(rule_data.merge(:contact => contact_data[:id]),
79
+ rule_2_data.merge(:contact => contact_data[:id]))
80
+ expect(result).not_to be_nil
81
+ expect(result).to eq(resultify(resp_data))
82
+ end
83
+
84
+ # TODO error due to invalid data
85
+
86
+ end
87
+
88
+ context 'read' do
89
+
90
+ it "submits a GET request for all rules" do
91
+ resp_data = [rule_json(rule_data).merge(:relationships => rule_rel(rule_data))]
92
+
93
+ flapjack.given("a rule exists").
94
+ upon_receiving("a GET request for all rules").
95
+ with(:method => :get, :path => '/rules').
96
+ will_respond_with(
97
+ :status => 200,
98
+ :headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
99
+ :body => {:data => resp_data} )
100
+
101
+ result = Flapjack::Diner.rules
102
+ expect(result).not_to be_nil
103
+ expect(result).to eq(resultify(resp_data))
104
+ end
105
+
106
+ it "submits a GET request for one rule" do
107
+ resp_data = rule_json(rule_data).merge(:relationships => rule_rel(rule_data))
108
+
109
+ flapjack.given("a rule exists").
110
+ upon_receiving("a GET request for a single rule").
111
+ with(:method => :get, :path => "/rules/#{rule_data[:id]}").
112
+ will_respond_with(
113
+ :status => 200,
114
+ :headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
115
+ :body => {:data => resp_data}
116
+ )
117
+
118
+ result = Flapjack::Diner.rules(rule_data[:id])
119
+ expect(result).not_to be_nil
120
+ expect(result).to eq(resultify(resp_data))
121
+ end
122
+
123
+ it "submits a GET request for several rules" do
124
+ resp_data = [
125
+ rule_json(rule_data).merge(:relationships => rule_rel(rule_data)),
126
+ rule_json(rule_2_data).merge(:relationships => rule_rel(rule_2_data))
127
+ ]
128
+
129
+ rules_data = [rule_data.merge(:type => 'rule'), rule_2_data.merge(:type => 'rule')]
130
+
131
+ flapjack.given("two rules exist").
132
+ upon_receiving("a GET request for two rules").
133
+ with(:method => :get, :path => "/rules",
134
+ :query => "filter%5B%5D=id%3A#{rule_data[:id]}%7C#{rule_2_data[:id]}").
135
+ will_respond_with(
136
+ :status => 200,
137
+ :headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
138
+ :body => {:data => resp_data} )
139
+
140
+ result = Flapjack::Diner.rules(rule_data[:id], rule_2_data[:id])
141
+ expect(result).not_to be_nil
142
+ expect(result).to eq(resultify(resp_data))
143
+ end
144
+
145
+ it "can't find the rule to read" do
146
+ flapjack.given("no data exists").
147
+ upon_receiving("a GET request for a single rule").
148
+ with(:method => :get, :path => "/rules/#{rule_data[:id]}").
149
+ will_respond_with(
150
+ :status => 404,
151
+ :headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
152
+ :body => {:errors => [{
153
+ :status => '404',
154
+ :detail => "could not find Rule record, id: '#{rule_data[:id]}'"
155
+ }]}
156
+ )
157
+
158
+ result = Flapjack::Diner.rules(rule_data[:id])
159
+ expect(result).to be_nil
160
+ expect(Flapjack::Diner.error).to eq([{:status => '404',
161
+ :detail => "could not find Rule record, id: '#{rule_data[:id]}'"}])
162
+ end
163
+
164
+ end
165
+
166
+ context 'update' do
167
+
168
+ it 'submits a PATCH request for a rule' do
169
+ flapjack.given("a rule exists").
170
+ upon_receiving("a PATCH request for a single rule").
171
+ with(:method => :patch,
172
+ :path => "/rules/#{rule_data[:id]}",
173
+ :body => {:data => {:id => rule_data[:id], :type => 'rule', :attributes => {:strategy => 'global'}}},
174
+ :headers => {'Content-Type' => 'application/vnd.api+json'}).
175
+ will_respond_with(
176
+ :status => 204,
177
+ :body => '' )
178
+
179
+ result = Flapjack::Diner.update_rules(:id => rule_data[:id], :strategy => 'global')
180
+ expect(result).to be_a(TrueClass)
181
+ end
182
+
183
+ it 'submits a PATCH request for several rules' do
184
+ flapjack.given("two rules exist").
185
+ upon_receiving("a PATCH request for two rules").
186
+ with(:method => :patch,
187
+ :path => "/rules",
188
+ :headers => {'Content-Type' => 'application/vnd.api+json; ext=bulk'},
189
+ :body => {:data => [{:id => rule_data[:id], :type => 'rule', :attributes => {:conditions_list => 'warning'}},
190
+ {:id => rule_2_data[:id], :type => 'rule', :attributes => {:strategy => 'any_tag'}}]}).
191
+ will_respond_with(
192
+ :status => 204,
193
+ :body => '' )
194
+
195
+ result = Flapjack::Diner.update_rules(
196
+ {:id => rule_data[:id], :conditions_list => 'warning'},
197
+ {:id => rule_2_data[:id], :strategy => 'any_tag'})
198
+ expect(result).to be_a(TrueClass)
199
+ end
200
+
201
+ it "can't find the rule to update" do
202
+ flapjack.given("no data exists").
203
+ upon_receiving("a PATCH request for a single rule").
204
+ with(:method => :patch,
205
+ :path => "/rules/#{rule_data[:id]}",
206
+ :body => {:data => {:id => rule_data[:id], :type => 'rule', :attributes => {:strategy => 'global'}}},
207
+ :headers => {'Content-Type' => 'application/vnd.api+json'}).
208
+ will_respond_with(
209
+ :status => 404,
210
+ :headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
211
+ :body => {:errors => [{
212
+ :status => '404',
213
+ :detail => "could not find Rule record, id: '#{rule_data[:id]}'"
214
+ }]}
215
+ )
216
+
217
+ result = Flapjack::Diner.update_rules(:id => rule_data[:id], :strategy => 'global')
218
+ expect(result).to be_nil
219
+ expect(Flapjack::Diner.error).to eq([{:status => '404',
220
+ :detail => "could not find Rule record, id: '#{rule_data[:id]}'"}])
221
+ end
222
+ end
223
+
224
+ context 'delete' do
225
+
226
+ it "submits a DELETE request for an rule" do
227
+ flapjack.given("a rule exists").
228
+ upon_receiving("a DELETE request for a single rule").
229
+ with(:method => :delete,
230
+ :path => "/rules/#{rule_data[:id]}",
231
+ :body => nil).
232
+ will_respond_with(:status => 204,
233
+ :body => '')
234
+
235
+ result = Flapjack::Diner.delete_rules(rule_data[:id])
236
+ expect(result).to be_a(TrueClass)
237
+ end
238
+
239
+ it "submits a DELETE request for several rules" do
240
+ rules_data = [{:type => 'rule', :id => rule_data[:id]},
241
+ {:type => 'rule', :id => rule_2_data[:id]}]
242
+
243
+ flapjack.given("two rules exist").
244
+ upon_receiving("a DELETE request for two rules").
245
+ with(:method => :delete,
246
+ :headers => {'Content-Type' => 'application/vnd.api+json; ext=bulk'},
247
+ :path => "/rules",
248
+ :body => {:data => rules_data}).
249
+ will_respond_with(:status => 204,
250
+ :body => '')
251
+
252
+ result = Flapjack::Diner.delete_rules(rule_data[:id], rule_2_data[:id])
253
+ expect(result).to be_a(TrueClass)
254
+ end
255
+
256
+ it "can't find the rule to delete" do
257
+ flapjack.given("no data exists").
258
+ upon_receiving("a DELETE request for a single rule").
259
+ with(:method => :delete,
260
+ :path => "/rules/#{rule_data[:id]}",
261
+ :body => nil).
262
+ will_respond_with(
263
+ :status => 404,
264
+ :headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
265
+ :body => {:errors => [{
266
+ :status => '404',
267
+ :detail => "could not find Rule record, id: '#{rule_data[:id]}'"
268
+ }]}
269
+ )
270
+
271
+ result = Flapjack::Diner.delete_rules(rule_data[:id])
272
+ expect(result).to be_nil
273
+ expect(Flapjack::Diner.error).to eq([{:status => '404',
274
+ :detail => "could not find Rule record, id: '#{rule_data[:id]}'"}])
275
+ end
276
+ end
277
+
278
+ end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
  require 'flapjack-diner'
3
3
  require 'flapjack-diner/index_range'
4
4
 
5
- describe Flapjack::Diner::Resources::States, :pact => true do
5
+ describe Flapjack::Diner::Resources, :pact => true do
6
6
 
7
7
  let(:time) { Time.now }
8
8
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'flapjack-diner'
3
3
 
4
- describe Flapjack::Diner::Resources::Statistics, :pact => true do
4
+ describe Flapjack::Diner::Resources, :pact => true do
5
5
 
6
6
  before(:each) do
7
7
  Flapjack::Diner.base_uri('localhost:19081')