flapjack-diner 1.4.0 → 2.0.0.a4

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 (51) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rspec +1 -1
  4. data/README.md +620 -413
  5. data/flapjack-diner.gemspec +1 -1
  6. data/lib/flapjack-diner/argument_validator.rb +77 -7
  7. data/lib/flapjack-diner/configuration.rb +409 -0
  8. data/lib/flapjack-diner/index_range.rb +42 -0
  9. data/lib/flapjack-diner/log_formatter.rb +22 -0
  10. data/lib/flapjack-diner/query.rb +114 -0
  11. data/lib/flapjack-diner/relationships.rb +180 -0
  12. data/lib/flapjack-diner/request.rb +280 -0
  13. data/lib/flapjack-diner/resources.rb +64 -0
  14. data/lib/flapjack-diner/response.rb +91 -0
  15. data/lib/flapjack-diner/tools.rb +47 -251
  16. data/lib/flapjack-diner/utility.rb +16 -0
  17. data/lib/flapjack-diner/version.rb +1 -1
  18. data/lib/flapjack-diner.rb +54 -20
  19. data/spec/argument_validator_spec.rb +87 -28
  20. data/spec/flapjack-diner_spec.rb +42 -64
  21. data/spec/relationships_spec.rb +211 -0
  22. data/spec/resources/checks_spec.rb +219 -79
  23. data/spec/resources/contacts_spec.rb +179 -151
  24. data/spec/resources/events_spec.rb +208 -0
  25. data/spec/resources/maintenance_periods_spec.rb +177 -565
  26. data/spec/resources/media_spec.rb +157 -171
  27. data/spec/resources/metrics_spec.rb +45 -0
  28. data/spec/resources/rules_spec.rb +278 -0
  29. data/spec/resources/states_spec.rb +93 -0
  30. data/spec/resources/statistics_spec.rb +53 -0
  31. data/spec/resources/tags_spec.rb +243 -0
  32. data/spec/spec_helper.rb +16 -0
  33. data/spec/support/fixture_data.rb +541 -0
  34. metadata +33 -31
  35. data/.rubocop.yml +0 -21
  36. data/.rubocop_todo.yml +0 -135
  37. data/lib/flapjack-diner/resources/checks.rb +0 -64
  38. data/lib/flapjack-diner/resources/contacts.rb +0 -70
  39. data/lib/flapjack-diner/resources/entities.rb +0 -68
  40. data/lib/flapjack-diner/resources/maintenance_periods.rb +0 -82
  41. data/lib/flapjack-diner/resources/media.rb +0 -61
  42. data/lib/flapjack-diner/resources/notification_rules.rb +0 -66
  43. data/lib/flapjack-diner/resources/notifications.rb +0 -28
  44. data/lib/flapjack-diner/resources/pagerduty_credentials.rb +0 -59
  45. data/lib/flapjack-diner/resources/reports.rb +0 -33
  46. data/spec/pacts/flapjack-diner-flapjack.json +0 -4515
  47. data/spec/resources/entities_spec.rb +0 -181
  48. data/spec/resources/notification_rules_spec.rb +0 -341
  49. data/spec/resources/notifications_spec.rb +0 -208
  50. data/spec/resources/pagerduty_credentials_spec.rb +0 -237
  51. data/spec/resources/reports_spec.rb +0 -255
@@ -1,208 +0,0 @@
1
- require 'spec_helper'
2
- require 'flapjack-diner'
3
-
4
- describe Flapjack::Diner::Resources::Notifications, :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 'entities' do
12
-
13
- context 'create' do
14
-
15
- context 'test notifications' do
16
-
17
- it "submits a POST request for an entity" do
18
- flapjack.given("an entity 'www.example.com' with id '1234' exists").
19
- upon_receiving("a POST request with one test notification").
20
- with(:method => :post, :path => '/test_notifications/entities/1234',
21
- :headers => {'Content-Type' => 'application/vnd.api+json'},
22
- :body => {:test_notifications => [{}]}).
23
- will_respond_with(
24
- :status => 204,
25
- :body => '')
26
-
27
- result = Flapjack::Diner.create_test_notifications_entities('1234', {})
28
- expect(result).not_to be_nil
29
- expect(result).to be_truthy
30
- end
31
-
32
- it "submits a POST request for several entities" do
33
- data = [{:summary => 'testing'}]
34
-
35
- flapjack.given("entities 'www.example.com', id '1234' and 'www2.example.com', id '5678' exist").
36
- upon_receiving("a POST request with one test notification").
37
- with(:method => :post, :path => '/test_notifications/entities/1234,5678',
38
- :headers => {'Content-Type' => 'application/vnd.api+json'},
39
- :body => {:test_notifications => data}).
40
- will_respond_with(
41
- :status => 204,
42
- :body => '')
43
-
44
- result = Flapjack::Diner.create_test_notifications_entities('1234', '5678', data)
45
- expect(result).not_to be_nil
46
- expect(result).to be_truthy
47
- end
48
-
49
- it "submits a POST request for multiple notifications on an entity" do
50
- data = [{:summary => 'testing'},
51
- {:summary => 'more tests'}]
52
-
53
- flapjack.given("an entity 'www.example.com' with id '1234' exists").
54
- upon_receiving("a POST request with two test notifications").
55
- with(:method => :post, :path => '/test_notifications/entities/1234',
56
- :headers => {'Content-Type' => 'application/vnd.api+json'},
57
- :body => {:test_notifications => data}).
58
- will_respond_with(
59
- :status => 204,
60
- :body => '')
61
-
62
- result = Flapjack::Diner.create_test_notifications_entities('1234', data)
63
- expect(result).not_to be_nil
64
- expect(result).to be_truthy
65
- end
66
-
67
- it "submits a POST request for multiple notifications on several entities" do
68
- data = [{:summary => 'testing'},
69
- {:summary => 'more tests'}]
70
-
71
- flapjack.given("entities 'www.example.com', id '1234' and 'www2.example.com', id '5678' exist").
72
- upon_receiving("a POST request with two test notifications").
73
- with(:method => :post, :path => '/test_notifications/entities/1234,5678',
74
- :headers => {'Content-Type' => 'application/vnd.api+json'},
75
- :body => {:test_notifications => data}).
76
- will_respond_with(
77
- :status => 204,
78
- :body => '')
79
-
80
- result = Flapjack::Diner.create_test_notifications_entities('1234', '5678', data)
81
- expect(result).not_to be_nil
82
- expect(result).to be_truthy
83
- end
84
-
85
- it "can't find the entity to create notifications for" do
86
- data = [{:summary => 'testing'}]
87
-
88
- flapjack.given("no entity exists").
89
- upon_receiving("a POST request with one test notification").
90
- with(:method => :post, :path => '/test_notifications/entities/1234',
91
- :headers => {'Content-Type' => 'application/vnd.api+json'},
92
- :body => {:test_notifications => data}).
93
- will_respond_with(
94
- :status => 404,
95
- :body => {:errors => ["could not find entity '1234'"]})
96
-
97
- result = Flapjack::Diner.create_test_notifications_entities('1234', data)
98
- expect(result).to be_nil
99
- expect(Flapjack::Diner.last_error).to eq(:status_code => 404,
100
- :errors => ["could not find entity '1234'"])
101
- end
102
-
103
- end
104
-
105
- end
106
-
107
- end
108
-
109
- context 'checks' do
110
- context 'create' do
111
-
112
- context 'test notifications' do
113
-
114
- it "submits a POST request for a check" do
115
- data = [{:summary => 'testing'}]
116
-
117
- flapjack.given("a check 'www.example.com:SSH' exists").
118
- upon_receiving("a POST request with one test notification").
119
- with(:method => :post, :path => '/test_notifications/checks/www.example.com:SSH',
120
- :headers => {'Content-Type' => 'application/vnd.api+json'},
121
- :body => {:test_notifications => data}).
122
- will_respond_with(
123
- :status => 204,
124
- :body => '')
125
-
126
- result = Flapjack::Diner.create_test_notifications_checks('www.example.com:SSH', data)
127
- expect(result).not_to be_nil
128
- expect(result).to be_truthy
129
- end
130
-
131
- it "submits a POST request for several checks" do
132
- data = [{:summary => 'testing'}]
133
-
134
- flapjack.given("checks 'www.example.com:SSH' and 'www2.example.com:PING' exist").
135
- upon_receiving("a POST request with one test notification").
136
- with(:method => :post, :path => '/test_notifications/checks/www.example.com:SSH,www2.example.com:PING',
137
- :headers => {'Content-Type' => 'application/vnd.api+json'},
138
- :body => {:test_notifications => data}).
139
- will_respond_with(
140
- :status => 204,
141
- :body => '')
142
-
143
- result = Flapjack::Diner.create_test_notifications_checks('www.example.com:SSH', 'www2.example.com:PING', data)
144
- expect(result).not_to be_nil
145
- expect(result).to be_truthy
146
- end
147
-
148
- it "submits a POST request for multiple notifications on a check" do
149
- data = [{:summary => 'testing'},
150
- {:summary => 'more tests'}]
151
-
152
- flapjack.given("a check 'www.example.com:SSH' exists").
153
- upon_receiving("a POST request with two test notifications").
154
- with(:method => :post, :path => '/test_notifications/checks/www.example.com:SSH',
155
- :headers => {'Content-Type' => 'application/vnd.api+json'},
156
- :body => {:test_notifications => data}).
157
- will_respond_with(
158
- :status => 204,
159
- :body => '')
160
-
161
- result = Flapjack::Diner.create_test_notifications_checks('www.example.com:SSH', data)
162
- expect(result).not_to be_nil
163
- expect(result).to be_truthy
164
- end
165
-
166
- it "submits a POST request for multiple notifications on several checks" do
167
- data = [{:summary => 'testing'},
168
- {:summary => 'more tests'}]
169
-
170
- flapjack.given("checks 'www.example.com:SSH' and 'www2.example.com:PING' exist").
171
- upon_receiving("a POST request with two test notifications").
172
- with(:method => :post, :path => '/test_notifications/checks/www.example.com:SSH,www2.example.com:PING',
173
- :headers => {'Content-Type' => 'application/vnd.api+json'},
174
- :body => {:test_notifications => data}).
175
- will_respond_with(
176
- :status => 204,
177
- :body => '')
178
-
179
- result = Flapjack::Diner.create_test_notifications_checks('www.example.com:SSH', 'www2.example.com:PING', data)
180
- expect(result).not_to be_nil
181
- expect(result).to be_truthy
182
- end
183
-
184
- it "can't find the check to create notifications for" do
185
- data = [{:summary => 'testing'}]
186
-
187
- flapjack.given("no check exists").
188
- upon_receiving("a POST request with one test notification").
189
- with(:method => :post, :path => '/test_notifications/checks/www.example.com:SSH',
190
- :headers => {'Content-Type' => 'application/vnd.api+json'},
191
- :body => {:test_notifications => data}).
192
- will_respond_with(
193
- :status => 404,
194
- :body => {:errors => ["could not find entity 'www.example.com'"]})
195
-
196
- result = Flapjack::Diner.create_test_notifications_checks('www.example.com:SSH', data)
197
- expect(result).to be_nil
198
- expect(Flapjack::Diner.last_error).to eq(:status_code => 404,
199
- :errors => ["could not find entity 'www.example.com'"])
200
- end
201
-
202
- end
203
-
204
- end
205
-
206
- end
207
-
208
- end
@@ -1,237 +0,0 @@
1
- require 'spec_helper'
2
- require 'flapjack-diner'
3
-
4
- describe Flapjack::Diner::Resources::PagerdutyCredentials, :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 pagerduty credentials" do
14
- data = [{:service_key => 'abc',
15
- :subdomain => 'def',
16
- :token => 'ghi',
17
- }]
18
-
19
- flapjack.given("a contact with id 'abc' exists").
20
- upon_receiving("a POST request with one set of pagerduty credentials").
21
- with(:method => :post, :path => '/contacts/abc/pagerduty_credentials',
22
- :headers => {'Content-Type' => 'application/vnd.api+json'},
23
- :body => {:pagerduty_credentials => data}).
24
- will_respond_with(
25
- :status => 201,
26
- :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
27
- :body => ['abc'] )
28
-
29
- result = Flapjack::Diner.create_contact_pagerduty_credentials('abc', data)
30
- expect(result).to eq(['abc'])
31
- end
32
-
33
- it "can't find the contact to create pagerduty credentials for" do
34
- data = [{:service_key => 'abc',
35
- :subdomain => 'def',
36
- :token => 'ghi',
37
- }]
38
-
39
- flapjack.given("no contact exists").
40
- upon_receiving("a POST request with one set of pagerduty credentials").
41
- with(:method => :post, :path => '/contacts/abc/pagerduty_credentials',
42
- :headers => {'Content-Type' => 'application/vnd.api+json'},
43
- :body => {:pagerduty_credentials => data}).
44
- will_respond_with(
45
- :status => 422,
46
- :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
47
- :body => {:errors => ["Contact id: 'abc' could not be loaded"]} )
48
-
49
- result = Flapjack::Diner.create_contact_pagerduty_credentials('abc', data)
50
- expect(result).to be_nil
51
- expect(Flapjack::Diner.last_error).to eq(:status_code => 422,
52
- :errors => ["Contact id: 'abc' could not be loaded"])
53
- end
54
-
55
- end
56
-
57
- context 'read' do
58
- it "submits a GET request for all pagerduty credentials" do
59
- pdc_data = [{
60
- :service_key => 'abc',
61
- :subdomain => 'def',
62
- :token => 'ghi',
63
- }]
64
-
65
- flapjack.given("a contact with id 'abc' has pagerduty credentials").
66
- upon_receiving("a GET request for all pagerduty credentials").
67
- with(:method => :get, :path => '/pagerduty_credentials').
68
- will_respond_with(
69
- :status => 200,
70
- :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
71
- :body => {:pagerduty_credentials => pdc_data} )
72
-
73
- result = Flapjack::Diner.pagerduty_credentials
74
- expect(result).to eq(pdc_data)
75
- end
76
-
77
- it "submits a GET request for one set of pagerduty credentials" do
78
- pdc_data = [{
79
- :service_key => 'abc',
80
- :subdomain => 'def',
81
- :token => 'ghi',
82
- }]
83
-
84
- flapjack.given("a contact with id 'abc' has pagerduty credentials").
85
- upon_receiving("a GET request for one set of pagerduty credentials").
86
- with(:method => :get, :path => '/pagerduty_credentials/abc').
87
- will_respond_with(
88
- :status => 200,
89
- :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
90
- :body => {:pagerduty_credentials => pdc_data} )
91
-
92
- result = Flapjack::Diner.pagerduty_credentials('abc')
93
- expect(result).to eq(pdc_data)
94
- end
95
-
96
- it "submits a GET request for several sets of pagerduty credentials" do
97
- pdc_data = [{
98
- :service_key => 'abc',
99
- :subdomain => 'def',
100
- :token => 'ghi',
101
- }, {
102
- :service_key => 'mno',
103
- :subdomain => 'pqr',
104
- :token => 'stu',
105
- }]
106
-
107
- flapjack.given("contacts with ids 'abc' and '872' have pagerduty credentials").
108
- upon_receiving("a GET request for two sets of pagerduty credentials").
109
- with(:method => :get, :path => '/pagerduty_credentials/abc,872').
110
- will_respond_with(
111
- :status => 200,
112
- :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
113
- :body => {:pagerduty_credentials => pdc_data} )
114
-
115
- result = Flapjack::Diner.pagerduty_credentials('abc', '872')
116
- expect(result).to eq(pdc_data)
117
- end
118
-
119
- it "can't find the contact with pagerduty credentials to read" do
120
- flapjack.given("no contact exists").
121
- upon_receiving("a GET request for one set of pagerduty credentials").
122
- with(:method => :get, :path => '/pagerduty_credentials/abc').
123
- will_respond_with(
124
- :status => 404,
125
- :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
126
- :body => {:errors => ["could not find contact 'abc'"]} )
127
-
128
- result = Flapjack::Diner.pagerduty_credentials('abc')
129
- expect(result).to be_nil
130
- expect(Flapjack::Diner.last_error).to eq(:status_code => 404,
131
- :errors => ["could not find contact 'abc'"])
132
- end
133
-
134
- end
135
-
136
- context 'update' do
137
-
138
- it "submits a PATCH request for one set of pagerduty credentials" do
139
- flapjack.given("a contact with id 'abc' has pagerduty credentials").
140
- upon_receiving("a PATCH request for pagerduty credentials").
141
- with(:method => :patch,
142
- :path => '/pagerduty_credentials/abc',
143
- :headers => {'Content-Type'=>'application/json-patch+json'},
144
- :body => [{:op => 'replace', :path => '/pagerduty_credentials/0/token', :value => 'token123'}]).
145
- will_respond_with(
146
- :status => 204,
147
- :body => '' )
148
-
149
- result = Flapjack::Diner.update_pagerduty_credentials('abc', :token => 'token123')
150
- expect(result).not_to be_nil
151
- expect(result).to be_truthy
152
- end
153
-
154
- it "submits a PATCH request for several sets of pagerduty credentials" do
155
- flapjack.given("contacts with ids 'abc' and '872' have pagerduty credentials").
156
- upon_receiving("a PATCH request for pagerduty credentials").
157
- with(:method => :patch,
158
- :path => '/pagerduty_credentials/abc,872',
159
- :headers => {'Content-Type'=>'application/json-patch+json'},
160
- :body => [{:op => 'replace', :path => '/pagerduty_credentials/0/token', :value => 'token123'}]).
161
- will_respond_with(
162
- :status => 204,
163
- :body => '' )
164
-
165
- result = Flapjack::Diner.update_pagerduty_credentials('abc', '872', :token => 'token123')
166
- expect(result).not_to be_nil
167
- expect(result).to be_truthy
168
- end
169
-
170
- it "can't find the contact with pagerduty credentials to update" do
171
- flapjack.given("no contact exists").
172
- upon_receiving("a PATCH request for pagerduty credentials").
173
- with(:method => :patch,
174
- :path => '/pagerduty_credentials/abc',
175
- :headers => {'Content-Type'=>'application/json-patch+json'},
176
- :body => [{:op => 'replace', :path => '/pagerduty_credentials/0/token', :value => 'token123'}]).
177
- will_respond_with(:status => 404,
178
- :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
179
- :body => {:errors => ["could not find contact 'abc'"]} )
180
-
181
- result = Flapjack::Diner.update_pagerduty_credentials('abc', :token => 'token123')
182
- expect(result).to be_nil
183
- expect(Flapjack::Diner.last_error).to eq(:status_code => 404,
184
- :errors => ["could not find contact 'abc'"])
185
- end
186
-
187
- end
188
-
189
- context 'delete' do
190
- it "submits a DELETE request for one set of pagerduty credentials" do
191
-
192
- flapjack.given("a contact with id 'abc' has pagerduty credentials").
193
- upon_receiving("a DELETE request for one set of pagerduty credentials").
194
- with(:method => :delete,
195
- :path => '/pagerduty_credentials/abc',
196
- :body => nil).
197
- will_respond_with(:status => 204,
198
- :body => '')
199
-
200
- result = Flapjack::Diner.delete_pagerduty_credentials('abc')
201
- expect(result).not_to be_nil
202
- expect(result).to be_truthy
203
- end
204
-
205
- it "submits a DELETE request for several sets of pagerduty credentials" do
206
- flapjack.given("contacts with ids 'abc' and '872' have pagerduty credentials").
207
- upon_receiving("a DELETE request for two sets of pagerduty credentials").
208
- with(:method => :delete,
209
- :path => '/pagerduty_credentials/abc,872',
210
- :body => nil).
211
- will_respond_with(:status => 204,
212
- :body => '')
213
-
214
- result = Flapjack::Diner.delete_pagerduty_credentials('abc', '872')
215
- expect(result).not_to be_nil
216
- expect(result).to be_truthy
217
- end
218
-
219
- it "can't find the contact with pagerduty credentials to delete" do
220
- flapjack.given("no contact exists").
221
- upon_receiving("a DELETE request for one set of pagerduty credentials").
222
- with(:method => :delete,
223
- :path => '/pagerduty_credentials/abc',
224
- :body => nil).
225
- will_respond_with(:status => 404,
226
- :headers => {'Content-Type' => 'application/vnd.api+json; charset=utf-8'},
227
- :body => {:errors => ["could not find contact 'abc'"]} )
228
-
229
- result = Flapjack::Diner.delete_pagerduty_credentials('abc')
230
- expect(result).to be_nil
231
- expect(Flapjack::Diner.last_error).to eq(:status_code => 404,
232
- :errors => ["could not find contact 'abc'"])
233
- end
234
-
235
- end
236
-
237
- end