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
@@ -0,0 +1,208 @@
|
|
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
|
+
context 'test notifications' do
|
14
|
+
|
15
|
+
it "submits a POST request for a check" do
|
16
|
+
req_data = test_notification_json(test_notification_data).merge(
|
17
|
+
:relationships => {
|
18
|
+
:check => {
|
19
|
+
:data => {:type => 'check', :id => check_data[:id]}
|
20
|
+
}
|
21
|
+
}
|
22
|
+
)
|
23
|
+
resp_data = test_notification_json(test_notification_data)
|
24
|
+
|
25
|
+
flapjack.given("a check exists").
|
26
|
+
upon_receiving("a POST request with one test notification").
|
27
|
+
with(:method => :post, :path => "/test_notifications",
|
28
|
+
:headers => {'Content-Type' => 'application/vnd.api+json'},
|
29
|
+
:body => {:data => req_data}).
|
30
|
+
will_respond_with(
|
31
|
+
:status => 201,
|
32
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
33
|
+
:body => {:data => resp_data})
|
34
|
+
|
35
|
+
result = Flapjack::Diner.create_test_notifications(test_notification_data.merge(:check => check_data[:id]))
|
36
|
+
expect(result).not_to be_nil
|
37
|
+
expect(result).to eq(resultify(resp_data))
|
38
|
+
end
|
39
|
+
|
40
|
+
it "submits a POST request for checks linked to a tag" do
|
41
|
+
req_data = test_notification_json(test_notification_data).merge(
|
42
|
+
:relationships => {
|
43
|
+
:tag => {
|
44
|
+
:data => {:type => 'tag', :id => tag_data[:id]}
|
45
|
+
}
|
46
|
+
}
|
47
|
+
)
|
48
|
+
resp_data = test_notification_json(test_notification_data)
|
49
|
+
|
50
|
+
flapjack.given("a tag exists").
|
51
|
+
upon_receiving("a POST request with one test notification").
|
52
|
+
with(:method => :post, :path => "/test_notifications",
|
53
|
+
:headers => {'Content-Type' => 'application/vnd.api+json'},
|
54
|
+
:body => {:data => req_data}).
|
55
|
+
will_respond_with(
|
56
|
+
:status => 201,
|
57
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
58
|
+
:body => {:data => resp_data})
|
59
|
+
|
60
|
+
result = Flapjack::Diner.create_test_notifications(test_notification_data.merge(:tag => tag_data[:id]))
|
61
|
+
expect(result).not_to be_nil
|
62
|
+
expect(result).to eq(resultify(resp_data))
|
63
|
+
end
|
64
|
+
|
65
|
+
it "submits a POST request for multiple notifications on a check" do
|
66
|
+
req_data = [
|
67
|
+
test_notification_json(test_notification_data).merge(
|
68
|
+
:relationships => {
|
69
|
+
:check => {
|
70
|
+
:data => {:type => 'check', :id => check_data[:id]}
|
71
|
+
}
|
72
|
+
}
|
73
|
+
),
|
74
|
+
test_notification_json(test_notification_2_data).merge(
|
75
|
+
:relationships => {
|
76
|
+
:check => {
|
77
|
+
:data => {:type => 'check', :id => check_data[:id]}
|
78
|
+
}
|
79
|
+
}
|
80
|
+
)
|
81
|
+
]
|
82
|
+
resp_data = [
|
83
|
+
test_notification_json(test_notification_data),
|
84
|
+
test_notification_json(test_notification_2_data)
|
85
|
+
]
|
86
|
+
|
87
|
+
flapjack.given("a check exists").
|
88
|
+
upon_receiving("a POST request with two test notifications").
|
89
|
+
with(:method => :post, :path => "/test_notifications",
|
90
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; ext=bulk'},
|
91
|
+
:body => {:data => req_data}).
|
92
|
+
will_respond_with(
|
93
|
+
:status => 201,
|
94
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
95
|
+
:body => {:data => resp_data})
|
96
|
+
|
97
|
+
result = Flapjack::Diner.create_test_notifications(
|
98
|
+
test_notification_data.merge(:check => check_data[:id]),
|
99
|
+
test_notification_2_data.merge(:check => check_data[:id])
|
100
|
+
)
|
101
|
+
expect(result).not_to be_nil
|
102
|
+
expect(result).to eq(resultify(resp_data))
|
103
|
+
end
|
104
|
+
|
105
|
+
it "submits a POST request for multiple notifications for checks linked to a tag" do
|
106
|
+
req_data = [
|
107
|
+
test_notification_json(test_notification_data).merge(
|
108
|
+
:relationships => {
|
109
|
+
:tag => {
|
110
|
+
:data => {:type => 'tag', :id => tag_data[:id]}
|
111
|
+
}
|
112
|
+
}
|
113
|
+
),
|
114
|
+
test_notification_json(test_notification_2_data).merge(
|
115
|
+
:relationships => {
|
116
|
+
:tag => {
|
117
|
+
:data => {:type => 'tag', :id => tag_data[:id]}
|
118
|
+
}
|
119
|
+
}
|
120
|
+
)
|
121
|
+
]
|
122
|
+
|
123
|
+
resp_data = [
|
124
|
+
test_notification_json(test_notification_data),
|
125
|
+
test_notification_json(test_notification_2_data)
|
126
|
+
]
|
127
|
+
|
128
|
+
flapjack.given("a tag exists").
|
129
|
+
upon_receiving("a POST request with two test notifications").
|
130
|
+
with(:method => :post, :path => "/test_notifications",
|
131
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; ext=bulk'},
|
132
|
+
:body => {:data => req_data}).
|
133
|
+
will_respond_with(
|
134
|
+
:status => 201,
|
135
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
136
|
+
:body => {:data => resp_data})
|
137
|
+
|
138
|
+
result = Flapjack::Diner.create_test_notifications(
|
139
|
+
test_notification_data.merge(:tag => tag_data[:id]),
|
140
|
+
test_notification_2_data.merge(:tag => tag_data[:id])
|
141
|
+
)
|
142
|
+
expect(result).not_to be_nil
|
143
|
+
expect(result).to eq(resultify(resp_data))
|
144
|
+
end
|
145
|
+
|
146
|
+
it "can't find the check to create notifications for" do
|
147
|
+
req_data = test_notification_json(test_notification_data).merge(
|
148
|
+
:relationships => {
|
149
|
+
:check => {
|
150
|
+
:data => {:type => 'check', :id => check_data[:id]}
|
151
|
+
}
|
152
|
+
}
|
153
|
+
)
|
154
|
+
|
155
|
+
flapjack.given("no data exists").
|
156
|
+
upon_receiving("a POST request with one test notification for a check").
|
157
|
+
with(:method => :post, :path => "/test_notifications",
|
158
|
+
:headers => {'Content-Type' => 'application/vnd.api+json'},
|
159
|
+
:body => {:data => req_data}).
|
160
|
+
will_respond_with(
|
161
|
+
:status => 404,
|
162
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
163
|
+
:body => {:errors => [{
|
164
|
+
:status => '404',
|
165
|
+
:detail => "could not find Check record, id: '#{check_data[:id]}'"
|
166
|
+
}]}
|
167
|
+
)
|
168
|
+
|
169
|
+
result = Flapjack::Diner.create_test_notifications(test_notification_data.merge(:check => check_data[:id]))
|
170
|
+
expect(result).to be_nil
|
171
|
+
expect(Flapjack::Diner.error).to eq([{:status => '404',
|
172
|
+
:detail => "could not find Check record, id: '#{check_data[:id]}'"}])
|
173
|
+
end
|
174
|
+
|
175
|
+
it "can't find the tag to create notifications for" do
|
176
|
+
req_data = test_notification_json(test_notification_data).merge(
|
177
|
+
:relationships => {
|
178
|
+
:tag => {
|
179
|
+
:data => {:type => 'tag', :id => tag_data[:id]}
|
180
|
+
}
|
181
|
+
}
|
182
|
+
)
|
183
|
+
|
184
|
+
flapjack.given("no data exists").
|
185
|
+
upon_receiving("a POST request with one test notification for a tag").
|
186
|
+
with(:method => :post, :path => "/test_notifications",
|
187
|
+
:headers => {'Content-Type' => 'application/vnd.api+json'},
|
188
|
+
:body => {:data => req_data}).
|
189
|
+
will_respond_with(
|
190
|
+
:status => 404,
|
191
|
+
:headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
|
192
|
+
:body => {:errors => [{
|
193
|
+
:status => '404',
|
194
|
+
:detail => "could not find Tag record, id: '#{tag_data[:id]}'"
|
195
|
+
}]}
|
196
|
+
)
|
197
|
+
|
198
|
+
result = Flapjack::Diner.create_test_notifications(test_notification_data.merge(:tag => tag_data[:id]))
|
199
|
+
expect(result).to be_nil
|
200
|
+
expect(Flapjack::Diner.error).to eq([{:status => '404',
|
201
|
+
:detail => "could not find Tag record, id: '#{tag_data[:id]}'"}])
|
202
|
+
end
|
203
|
+
|
204
|
+
end
|
205
|
+
|
206
|
+
end
|
207
|
+
|
208
|
+
end
|