sensu-plugins-cucumber 0.0.1.alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +1 -0
- data/LICENSE +22 -0
- data/README.md +80 -0
- data/bin/README.md +5 -0
- data/bin/check-cucumber.rb +515 -0
- data/bin/cucumber-example/features/failing.feature +6 -0
- data/bin/cucumber-example/features/passing.feature +6 -0
- data/bin/cucumber-example/features/step_definitions/failing.js +7 -0
- data/bin/cucumber-example/features/step_definitions/passing.js +19 -0
- data/bin/cucumber-example/features/support/hooks.js +12 -0
- data/bin/cucumber-example/features/support/world.js +11 -0
- data/bin/cucumber-example/package.json +6 -0
- data/lib/sensu-plugins-cucumber.rb +7 -0
- data.tar.gz.sig +0 -0
- metadata +278 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9c216905081998e9ce597513b19044cb75b2c83c
|
4
|
+
data.tar.gz: 73ed8e64e71c6443b65b020891b21827228917e0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8c5db2a1034753d33889d8e2d234ba131ba3134596b6f0fc1249561804cd272043afbf8c4b643d881f8f759d5b1221337e86f68de2e9c21b5376ae597cf1506d
|
7
|
+
data.tar.gz: 3abadaa0dab57436340a4e9ba8bc9d11f1257441570ed460fece397b5f8231580fdbee5ae17e8dd21787a7362a313e333db283b91629808146cb19931ddff71c
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
#### 0.0.1.alpha.1
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 devops@yieldbot.com
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
## Sensu-Plugins-cucumber
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/sensu-plugins/sensu-plugins-cucumber.svg?branch=master)](https://travis-ci.org/sensu-plugins/sensu-plugins-cucumber)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/sensu-plugins-cucumber.svg)](http://badge.fury.io/rb/sensu-plugins-cucumber)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/sensu-plugins/sensu-plugins-cucumber/badges/gpa.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-cucumber)
|
6
|
+
[![Test Coverage](https://codeclimate.com/github/sensu-plugins/sensu-plugins-cucumber/badges/coverage.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-cucumber)
|
7
|
+
[![Dependency Status](https://gemnasium.com/sensu-plugins/sensu-plugins-cucumber.svg)](https://gemnasium.com/sensu-plugins/sensu-plugins-cucumber)
|
8
|
+
|
9
|
+
## Functionality
|
10
|
+
|
11
|
+
## Files
|
12
|
+
* bin.check-cucumber
|
13
|
+
*
|
14
|
+
*
|
15
|
+
*
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
Example check_cucumber.json:
|
20
|
+
|
21
|
+
``` json
|
22
|
+
{
|
23
|
+
"checks": {
|
24
|
+
"check_cucumber_example": {
|
25
|
+
"handlers": ["default"],
|
26
|
+
"command": "check-cucumber.rb --name cucumber-example --handler cucumber --metric-handler metrics --metric-prefix example-metrics-prefix --command \"cucumber-js -f json features/\" --working-dir cucumber-example/",
|
27
|
+
"interval": 60,
|
28
|
+
"subscribers": [ "cucumber" ]
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
32
|
+
```
|
33
|
+
|
34
|
+
|
35
|
+
## Installation
|
36
|
+
|
37
|
+
Add the public key (if you haven’t already) as a trusted certificate
|
38
|
+
|
39
|
+
```
|
40
|
+
gem cert --add <(curl -Ls https://raw.githubusercontent.com/sensu-plugins/sensu-plugins.github.io/master/certs/sensu-plugins.pem)
|
41
|
+
gem install sensu-plugins-cucumber -P MediumSecurity
|
42
|
+
```
|
43
|
+
|
44
|
+
You can also download the key from /certs/ within each repository.
|
45
|
+
|
46
|
+
#### Rubygems
|
47
|
+
|
48
|
+
`gem install sensu-plugins-cucumber`
|
49
|
+
|
50
|
+
#### Bundler
|
51
|
+
|
52
|
+
Add *sensu-plugins-cucumber* to your Gemfile and run `bundle install` or `bundle update`
|
53
|
+
|
54
|
+
#### Chef
|
55
|
+
|
56
|
+
Using the Sensu **sensu_gem** LWRP
|
57
|
+
```
|
58
|
+
sensu_gem 'sensu-plugins-cucumber' do
|
59
|
+
options('--prerelease')
|
60
|
+
version '0.0.1'
|
61
|
+
end
|
62
|
+
```
|
63
|
+
|
64
|
+
Using the Chef **gem_package** resource
|
65
|
+
```
|
66
|
+
gem_package 'sensu-plugins-cucumber' do
|
67
|
+
options('--prerelease')
|
68
|
+
version '0.0.1'
|
69
|
+
end
|
70
|
+
```
|
71
|
+
|
72
|
+
## Notes
|
73
|
+
|
74
|
+
Sensu check that executes Cucumber tests
|
75
|
+
|
76
|
+
The check supports:
|
77
|
+
* cucumber-js
|
78
|
+
* cucumber-jvm
|
79
|
+
* Ruby Cucumber
|
80
|
+
* parallel-cucumber-js
|
data/bin/README.md
ADDED
@@ -0,0 +1,515 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-cucumber
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# A check that executes Cucumber tests
|
7
|
+
#
|
8
|
+
# OUTPUT:
|
9
|
+
# plain text
|
10
|
+
#
|
11
|
+
# PLATFORMS:
|
12
|
+
# Linux
|
13
|
+
#
|
14
|
+
# DEPENDENCIES:
|
15
|
+
# gem: sensu-plugin
|
16
|
+
# gem: <?>
|
17
|
+
#
|
18
|
+
# USAGE:
|
19
|
+
# #YELLOW
|
20
|
+
#
|
21
|
+
# NOTES:
|
22
|
+
#
|
23
|
+
# LICENSE:
|
24
|
+
# Copyright 2014 Simon Dean <simon@simondean.org>
|
25
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
26
|
+
# for details.
|
27
|
+
#
|
28
|
+
|
29
|
+
require 'sensu-plugin/check/cli'
|
30
|
+
require 'optparse'
|
31
|
+
require 'timeout'
|
32
|
+
require 'json'
|
33
|
+
require 'yaml'
|
34
|
+
require 'socket'
|
35
|
+
require 'English'
|
36
|
+
|
37
|
+
#
|
38
|
+
# Check Cucumber
|
39
|
+
#
|
40
|
+
class CheckCucumber < Sensu::Plugin::Check::CLI
|
41
|
+
OK = 0
|
42
|
+
WARNING = 1
|
43
|
+
CRITICAL = 2
|
44
|
+
UNKNOWN = 3
|
45
|
+
|
46
|
+
INFINITE_TIMEOUT = 0
|
47
|
+
|
48
|
+
option :name,
|
49
|
+
description: 'Name to use in sensu events',
|
50
|
+
short: '-n NAME',
|
51
|
+
long: '--name NAME'
|
52
|
+
|
53
|
+
option :handler,
|
54
|
+
description: 'Handler to use for sensu events',
|
55
|
+
short: '-h HANDLER',
|
56
|
+
long: '--handler HANDLER'
|
57
|
+
|
58
|
+
option :metric_handler,
|
59
|
+
description: 'Handler to use for metric events',
|
60
|
+
short: '-m HANDLER',
|
61
|
+
long: '--metric-handler HANDLER'
|
62
|
+
|
63
|
+
option :metric_prefix,
|
64
|
+
description: 'Metric prefix to use with metric paths in sensu events',
|
65
|
+
short: '-p METRIC_PREFIX',
|
66
|
+
long: '--metric-prefix METRIC_PREFIX'
|
67
|
+
|
68
|
+
option :command,
|
69
|
+
description: 'Cucumber command line, including arguments',
|
70
|
+
short: '-c COMMAND',
|
71
|
+
long: '--command COMMAND'
|
72
|
+
|
73
|
+
option :working_dir,
|
74
|
+
description: 'Working directory to use with Cucumber',
|
75
|
+
short: '-w WORKING_DIR',
|
76
|
+
long: '--working-dir WORKING_DIR'
|
77
|
+
|
78
|
+
option :timeout,
|
79
|
+
description: 'Amount of seconds to wait for Cucumber to wait before killing the Cucumber process',
|
80
|
+
short: '-t TIMEOUT',
|
81
|
+
long: '--timeout TIMEOUT'
|
82
|
+
|
83
|
+
option :env,
|
84
|
+
description: 'Environment variable to pass to Cucumber. Can be specified more than once to set multiple environment variables',
|
85
|
+
short: '-n NAME=VALUE',
|
86
|
+
long: '--env NAME=VALUE'
|
87
|
+
|
88
|
+
option :event_data,
|
89
|
+
description: 'Used to add custom data to the sensu events that are raised. Can be specified more than once to set multiple data items',
|
90
|
+
short: '-d NAME=VALUE',
|
91
|
+
long: '--event-data NAME=VALUE'
|
92
|
+
|
93
|
+
option :attachments,
|
94
|
+
description: 'Specifies whether Cucumber attachments should be included in sensu events. ' \
|
95
|
+
'Cucumber attachments can be multi-megabyte if they include screenshots',
|
96
|
+
short: '-a BOOLEAN',
|
97
|
+
long: '--attachments BOOLEAN'
|
98
|
+
|
99
|
+
option :debug,
|
100
|
+
description: 'Print debug information',
|
101
|
+
long: '--debug',
|
102
|
+
boolean: true
|
103
|
+
|
104
|
+
def parse_options(argv) # rubocop:disable all
|
105
|
+
env = {}
|
106
|
+
event_data = {}
|
107
|
+
|
108
|
+
process_env_option = lambda do |config_value|
|
109
|
+
name, value = config_value.split('=', 2)
|
110
|
+
env[name] = value
|
111
|
+
env
|
112
|
+
end
|
113
|
+
|
114
|
+
process_event_data_option = lambda do |config_value|
|
115
|
+
name, value = config_value.split('=', 2)
|
116
|
+
event_data[name] = value
|
117
|
+
event_data
|
118
|
+
end
|
119
|
+
|
120
|
+
options[:env][:proc] = process_env_option
|
121
|
+
options[:event_data][:proc] = process_event_data_option
|
122
|
+
|
123
|
+
super(argv)
|
124
|
+
end
|
125
|
+
|
126
|
+
def run # rubocop:disable all
|
127
|
+
return unless config_is_valid?
|
128
|
+
|
129
|
+
result = nil
|
130
|
+
|
131
|
+
begin
|
132
|
+
result = execute_cucumber(config[:env], config[:command], config[:working_dir], config[:timeout])
|
133
|
+
rescue Timeout::Error
|
134
|
+
unknown_error "Cucumber exceeded the timeout of #{config[:timeout]} seconds"
|
135
|
+
return
|
136
|
+
end
|
137
|
+
|
138
|
+
puts "Results: #{result[:results]}" if config[:debug]
|
139
|
+
puts "Exit status: #{result[:exit_status]}" if config[:debug]
|
140
|
+
|
141
|
+
unless [0, 1].include? result[:exit_status]
|
142
|
+
unknown_error "Cucumber returned exit code #{result[:exit_status]}"
|
143
|
+
return
|
144
|
+
end
|
145
|
+
|
146
|
+
results = JSON.parse(result[:results], symbolize_names: true)
|
147
|
+
|
148
|
+
outcome = :ok
|
149
|
+
scenario_count = 0
|
150
|
+
statuses = [:passed, :failed, :pending, :undefined]
|
151
|
+
status_counts = {}
|
152
|
+
statuses.each { |scenario_status| status_counts[scenario_status] = 0 }
|
153
|
+
sensu_events = []
|
154
|
+
utc_timestamp = Time.now.getutc.to_i
|
155
|
+
|
156
|
+
results.each do |feature|
|
157
|
+
# #YELLOW
|
158
|
+
Array(feature[:elements]).each do |element| # rubocop:disable Style/Next
|
159
|
+
if element[:type] == 'scenario'
|
160
|
+
event_name = "#{config[:name]}.#{generate_name_from_scenario(feature, element)}"
|
161
|
+
scenario_status = get_scenario_status(element)
|
162
|
+
|
163
|
+
sensu_events << generate_sensu_event(event_name, feature, element, scenario_status)
|
164
|
+
|
165
|
+
metrics = generate_metrics_from_scenario(feature, element, scenario_status, utc_timestamp)
|
166
|
+
|
167
|
+
unless metrics.nil?
|
168
|
+
sensu_events << generate_metric_event(event_name, metrics)
|
169
|
+
end
|
170
|
+
|
171
|
+
scenario_count += 1
|
172
|
+
status_counts[scenario_status] += 1
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
puts "Sensu events: #{JSON.pretty_generate(sensu_events)}" if config[:debug]
|
178
|
+
|
179
|
+
errors = raise_sensu_events(sensu_events)
|
180
|
+
|
181
|
+
if errors.length > 0
|
182
|
+
outcome = :unknown
|
183
|
+
elsif scenario_count == 0
|
184
|
+
outcome = :warning
|
185
|
+
end
|
186
|
+
|
187
|
+
data = {
|
188
|
+
'status' => outcome.to_s,
|
189
|
+
'scenarios' => scenario_count
|
190
|
+
}
|
191
|
+
|
192
|
+
statuses.each do |status|
|
193
|
+
data[status.to_s] = status_counts[status] if status_counts[status] > 0
|
194
|
+
end
|
195
|
+
|
196
|
+
data['errors'] = errors if errors.length > 0
|
197
|
+
|
198
|
+
data = dump_yaml(data)
|
199
|
+
|
200
|
+
case outcome
|
201
|
+
when :ok
|
202
|
+
ok data
|
203
|
+
when :warning
|
204
|
+
warning data
|
205
|
+
when :unknown
|
206
|
+
unknown data
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
def config_is_valid? # rubocop:disable all
|
211
|
+
if config[:name].nil?
|
212
|
+
unknown_error 'No name specified'
|
213
|
+
return false
|
214
|
+
end
|
215
|
+
|
216
|
+
if config[:handler].nil?
|
217
|
+
unknown_error 'No handler specified'
|
218
|
+
return false
|
219
|
+
end
|
220
|
+
|
221
|
+
if config[:metric_handler].nil?
|
222
|
+
unknown_error 'No metric handler specified'
|
223
|
+
return false
|
224
|
+
end
|
225
|
+
|
226
|
+
if config[:metric_prefix].nil?
|
227
|
+
unknown_error 'No metric prefix specified'
|
228
|
+
return false
|
229
|
+
end
|
230
|
+
|
231
|
+
if config[:command].nil?
|
232
|
+
unknown_error 'No cucumber command line specified'
|
233
|
+
return false
|
234
|
+
end
|
235
|
+
|
236
|
+
if config[:working_dir].nil?
|
237
|
+
unknown_error 'No working directory specified'
|
238
|
+
return false
|
239
|
+
end
|
240
|
+
|
241
|
+
config[:timeout] ||= INFINITE_TIMEOUT
|
242
|
+
config[:timeout] = Float(config[:timeout]) unless config[:timeout].nil?
|
243
|
+
config[:env] ||= {}
|
244
|
+
config[:event_data] ||= {}
|
245
|
+
|
246
|
+
config[:attachments] = 'true' if config[:attachments].nil?
|
247
|
+
|
248
|
+
case config[:attachments]
|
249
|
+
when 'true'
|
250
|
+
config[:attachments] = true
|
251
|
+
when 'false'
|
252
|
+
config[:attachments] = false
|
253
|
+
else
|
254
|
+
unknown_error 'Attachments argument is not a valid boolean'
|
255
|
+
return false
|
256
|
+
end
|
257
|
+
|
258
|
+
true
|
259
|
+
end
|
260
|
+
|
261
|
+
def remove_attachments_from_scenario(scenario)
|
262
|
+
Array(scenario[:steps]).each do |step|
|
263
|
+
step[:embeddings] = [] if step.key?(:embeddings)
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
def generate_name_from_scenario(feature, scenario) # rubocop:disable all
|
268
|
+
name = scenario[:id]
|
269
|
+
name += ";#{feature[:profile]}" if feature.key? :profile
|
270
|
+
|
271
|
+
name = name.gsub(/\./, '-')
|
272
|
+
.gsub(/;/, '.')
|
273
|
+
.gsub(/[^a-zA-Z0-9\._-]/, '-')
|
274
|
+
.gsub(/^\.+/, '')
|
275
|
+
.gsub(/\.+$/, '')
|
276
|
+
.gsub(/\.+/, '.')
|
277
|
+
|
278
|
+
parts = []
|
279
|
+
|
280
|
+
name.split('.').each do |part|
|
281
|
+
part = part.gsub(/^-+/, '')
|
282
|
+
.gsub(/-+$/, '')
|
283
|
+
.gsub(/-+/, '-')
|
284
|
+
|
285
|
+
parts << part unless part.length == 0
|
286
|
+
end
|
287
|
+
|
288
|
+
name = parts.join('.')
|
289
|
+
name
|
290
|
+
end
|
291
|
+
|
292
|
+
def raise_sensu_events(sensu_events)
|
293
|
+
errors = []
|
294
|
+
|
295
|
+
sensu_events.each do |sensu_event|
|
296
|
+
data = escape_unicode_characters_in_json(sensu_event.to_json)
|
297
|
+
|
298
|
+
begin
|
299
|
+
send_sensu_event(data)
|
300
|
+
rescue StandardError => error
|
301
|
+
errors << {
|
302
|
+
'message' => "Failed to raise event #{sensu_event[:name]}",
|
303
|
+
'error' => {
|
304
|
+
'message' => error.message,
|
305
|
+
'backtrace' => error.backtrace
|
306
|
+
}
|
307
|
+
}
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
errors
|
312
|
+
end
|
313
|
+
|
314
|
+
def generate_metrics_from_scenario(feature, scenario, scenario_status, utc_timestamp) # rubocop:disable all
|
315
|
+
metrics = []
|
316
|
+
|
317
|
+
if scenario_status == :passed
|
318
|
+
scenario_duration = 0
|
319
|
+
|
320
|
+
if scenario.key?(:steps)
|
321
|
+
has_step_durations = false
|
322
|
+
scenario_metric_prefix = "#{config[:metric_prefix]}.#{generate_name_from_scenario(feature, scenario)}"
|
323
|
+
|
324
|
+
scenario[:steps].each.with_index do |step, step_index|
|
325
|
+
if step.key?(:result) && step[:result].key?(:duration)
|
326
|
+
has_step_durations = true
|
327
|
+
step_duration = step[:result][:duration]
|
328
|
+
step_duration = step_duration
|
329
|
+
metrics << "#{scenario_metric_prefix}.step-#{step_index + 1}.duration #{step_duration} #{utc_timestamp}"
|
330
|
+
scenario_duration += step_duration
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
if has_step_durations
|
335
|
+
scenario_metrics = [
|
336
|
+
"#{scenario_metric_prefix}.duration #{scenario_duration} #{utc_timestamp}",
|
337
|
+
"#{scenario_metric_prefix}.step-count #{scenario[:steps].length} #{utc_timestamp}"
|
338
|
+
]
|
339
|
+
metrics.unshift scenario_metrics
|
340
|
+
end
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
if metrics.length == 0
|
345
|
+
metrics = nil
|
346
|
+
else
|
347
|
+
metrics = metrics.join("\n")
|
348
|
+
end
|
349
|
+
|
350
|
+
metrics
|
351
|
+
end
|
352
|
+
|
353
|
+
private
|
354
|
+
|
355
|
+
def output(msg)
|
356
|
+
puts msg
|
357
|
+
end
|
358
|
+
|
359
|
+
def execute_cucumber(env, command, working_dir, timeout)
|
360
|
+
results = nil
|
361
|
+
pipe = nil
|
362
|
+
|
363
|
+
begin
|
364
|
+
begin
|
365
|
+
Timeout.timeout(timeout) do
|
366
|
+
pipe = IO.popen(env, command, chdir: working_dir, external_encoding: Encoding::UTF_8)
|
367
|
+
results = pipe.read
|
368
|
+
end
|
369
|
+
rescue Timeout::Error
|
370
|
+
Process.kill 9, pipe.pid
|
371
|
+
raise Timeout::Error, 'Cucumber timed out'
|
372
|
+
end
|
373
|
+
ensure
|
374
|
+
pipe.close unless pipe.nil?
|
375
|
+
end
|
376
|
+
|
377
|
+
{ results: results, exit_status: $CHILD_STATUS.exitstatus }
|
378
|
+
end
|
379
|
+
|
380
|
+
def send_sensu_event(data)
|
381
|
+
socket = TCPSocket.new('127.0.0.1', 3030)
|
382
|
+
socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
383
|
+
|
384
|
+
index = 0
|
385
|
+
length = data.length
|
386
|
+
|
387
|
+
while index < length
|
388
|
+
bytes_sent = socket.send data[index..-1], 0
|
389
|
+
index += bytes_sent
|
390
|
+
end
|
391
|
+
|
392
|
+
socket.close
|
393
|
+
end
|
394
|
+
|
395
|
+
def generate_sensu_event(event_name, feature, scenario, scenario_status) # rubocop:disable all
|
396
|
+
scenario_clone = deep_dup(scenario)
|
397
|
+
remove_attachments_from_scenario(scenario_clone) unless config[:attachments]
|
398
|
+
feature_clone = deep_dup(feature)
|
399
|
+
feature_clone[:elements] = [scenario_clone]
|
400
|
+
scenario_results = [feature_clone]
|
401
|
+
|
402
|
+
scenario_output = get_output_for_scenario(scenario, scenario_status)
|
403
|
+
|
404
|
+
scenario_status_code = case scenario_status
|
405
|
+
when :passed
|
406
|
+
OK
|
407
|
+
when :failed
|
408
|
+
CRITICAL
|
409
|
+
when :pending, :undefined
|
410
|
+
WARNING
|
411
|
+
end
|
412
|
+
|
413
|
+
sensu_event = {
|
414
|
+
name: event_name,
|
415
|
+
handlers: [config[:handler]],
|
416
|
+
status: scenario_status_code,
|
417
|
+
output: scenario_output,
|
418
|
+
results: scenario_results
|
419
|
+
}
|
420
|
+
|
421
|
+
config[:event_data].each do |key, value|
|
422
|
+
if value =~ /^\A-?[0-9]+\z/
|
423
|
+
value = Integer(value)
|
424
|
+
elsif value =~ /^\A-?[0-9]+\.[0-9]+\z/
|
425
|
+
value = Float(value)
|
426
|
+
elsif value == 'true'
|
427
|
+
value = true
|
428
|
+
elsif value == 'false'
|
429
|
+
value = false
|
430
|
+
end
|
431
|
+
sensu_event[key] = value
|
432
|
+
end
|
433
|
+
|
434
|
+
sensu_event
|
435
|
+
end
|
436
|
+
|
437
|
+
def generate_metric_event(event_name, metrics)
|
438
|
+
metric_event = {
|
439
|
+
name: "#{event_name}.metrics",
|
440
|
+
type: 'metric',
|
441
|
+
handlers: [config[:metric_handler]],
|
442
|
+
output: metrics,
|
443
|
+
status: 0
|
444
|
+
}
|
445
|
+
|
446
|
+
metric_event
|
447
|
+
end
|
448
|
+
|
449
|
+
def get_scenario_status(scenario)
|
450
|
+
scenario_status = :passed
|
451
|
+
|
452
|
+
# #YELLOW
|
453
|
+
Array(scenario[:steps]).each do |step| # rubocop:disable Style/Next
|
454
|
+
if step.key? :result
|
455
|
+
step_status = step[:result][:status]
|
456
|
+
|
457
|
+
if %w(failed pending undefined).include? step_status
|
458
|
+
scenario_status = step_status.to_sym
|
459
|
+
break
|
460
|
+
end
|
461
|
+
end
|
462
|
+
end
|
463
|
+
|
464
|
+
scenario_status
|
465
|
+
end
|
466
|
+
|
467
|
+
def get_output_for_scenario(scenario, scenario_status) # rubocop:disable all
|
468
|
+
steps_output = []
|
469
|
+
|
470
|
+
Array(scenario[:steps]).each_with_index do |step, index|
|
471
|
+
has_result = step.key?(:result)
|
472
|
+
step_status = has_result ? step[:result][:status] : 'UNKNOWN'
|
473
|
+
step_output = {
|
474
|
+
'step' => "#{step_status.upcase} - #{index + 1} - #{step[:keyword]}#{step[:name]}"
|
475
|
+
}
|
476
|
+
|
477
|
+
if has_result && step[:result].key?(:error_message)
|
478
|
+
step_output['error'] = step[:result][:error_message]
|
479
|
+
end
|
480
|
+
|
481
|
+
steps_output << step_output
|
482
|
+
end
|
483
|
+
|
484
|
+
scenario_output = {
|
485
|
+
'status' => scenario_status.to_s,
|
486
|
+
'steps' => steps_output
|
487
|
+
}
|
488
|
+
|
489
|
+
dump_yaml(scenario_output)
|
490
|
+
end
|
491
|
+
|
492
|
+
def unknown_error(message)
|
493
|
+
data = {
|
494
|
+
'status' => 'unknown',
|
495
|
+
'errors' => [
|
496
|
+
{
|
497
|
+
'message' => message
|
498
|
+
}
|
499
|
+
]
|
500
|
+
}
|
501
|
+
unknown dump_yaml(data)
|
502
|
+
end
|
503
|
+
|
504
|
+
def deep_dup(obj)
|
505
|
+
Marshal.load(Marshal.dump(obj))
|
506
|
+
end
|
507
|
+
|
508
|
+
def dump_yaml(data)
|
509
|
+
data.to_yaml.gsub(/^---\r?\n/, '')
|
510
|
+
end
|
511
|
+
|
512
|
+
def escape_unicode_characters_in_json(json)
|
513
|
+
json.unpack('U*').map { |i| i < 128 ? i.chr : "\\u#{i.to_s(16).rjust(4, '0')}" }.join
|
514
|
+
end
|
515
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module.exports = function() {
|
2
|
+
this.Given(/^a passing pre-condition$/, function(callback) {
|
3
|
+
if (this.isDryRun()) { return callback(); }
|
4
|
+
|
5
|
+
callback();
|
6
|
+
});
|
7
|
+
|
8
|
+
this.When(/^a passing action is executed$/, function(callback) {
|
9
|
+
if (this.isDryRun()) { return callback(); }
|
10
|
+
|
11
|
+
callback();
|
12
|
+
});
|
13
|
+
|
14
|
+
this.Then(/^a post-condition passes$/, function(callback) {
|
15
|
+
if (this.isDryRun()) { return callback(); }
|
16
|
+
|
17
|
+
callback();
|
18
|
+
});
|
19
|
+
};
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module.exports = function() {
|
2
|
+
this.After(function (scenario, callback) {
|
3
|
+
if (scenario.isFailed()) {
|
4
|
+
scenario.attach(create1MegabyteBuffer(), 'text/plain');
|
5
|
+
}
|
6
|
+
callback();
|
7
|
+
});
|
8
|
+
|
9
|
+
function create1MegabyteBuffer() {
|
10
|
+
return new Buffer(1024 * 1024);
|
11
|
+
}
|
12
|
+
};
|
data.tar.gz.sig
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,278 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sensu-plugins-cucumber
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.alpha.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yieldbot, Inc. and contributors
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIDgDCCAmigAwIBAgIBATANBgkqhkiG9w0BAQUFADBDMRIwEAYDVQQDDAltYXR0
|
14
|
+
am9uZXMxGDAWBgoJkiaJk/IsZAEZFgh5aWVsZGJvdDETMBEGCgmSJomT8ixkARkW
|
15
|
+
A2NvbTAeFw0xNTAxMjgyMTAyNTFaFw0xNjAxMjgyMTAyNTFaMEMxEjAQBgNVBAMM
|
16
|
+
CW1hdHRqb25lczEYMBYGCgmSJomT8ixkARkWCHlpZWxkYm90MRMwEQYKCZImiZPy
|
17
|
+
LGQBGRYDY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyTSzVYnO
|
18
|
+
CLgyrIyT1mBQakArQyW8xhi6MlDqyzXHJGeERT790U6EgoBVeS4XoK0ptFZNR8Tf
|
19
|
+
zko0w+Nv47TarSCgkPOaxY+mxWnAVR10dOmfeLr7huiMyps+YD56/EF2FqQ3jf/+
|
20
|
+
qohENfKD91qy1ieEy+Fn7Pf74ltbNKUdkb9a9eFXQ0DQ4ip5vik7DzjQkUTj4lca
|
21
|
+
k6ArwnmHX4YDhZoYtrQJ8jVktN0/+NtA40M5qkCYHNe5tUW25b/tKVYuioxG6b2Z
|
22
|
+
oIzaZxRLxf6HVAWpCVRT/F5+/yjigkX4u++eYacfLGleXQzoK7BL65vHGMJygWEE
|
23
|
+
0TKGqFOrl/L0AQIDAQABo38wfTAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNV
|
24
|
+
HQ4EFgQUEf6a8Td7MrSZc8ImbLFZAENPbz0wIQYDVR0RBBowGIEWbWF0dGpvbmVz
|
25
|
+
QHlpZWxkYm90LmNvbTAhBgNVHRIEGjAYgRZtYXR0am9uZXNAeWllbGRib3QuY29t
|
26
|
+
MA0GCSqGSIb3DQEBBQUAA4IBAQBbzXAYA3BVGw8DZ0YYoY1VHPNEcH5qPIApmHO8
|
27
|
+
rvSmuUT0yMEi7u00H/5uHRFf4LleGT/+sTdyXKsNPGT9kdRuQEgwi+vf7Zfvd8aX
|
28
|
+
UF/+4VkEYf/8rV8Ere6u2QaWPgApdMV6JjKr1fAwCTd8AuGXNaWItiPPMseSQzLJ
|
29
|
+
JKP4hVvbc1d+oS925B1lcBiqn2aYvElbyNAVmQPywNNqkWmvtlqj9ZVJfV5HQLdu
|
30
|
+
8sHuVruarogxxKPBzlL2is4EUb6oN/RdpGx2l4254+nyR+abg//Ed27Ym0PkB4lk
|
31
|
+
HP0m8WSjZmFr109pE/sVsM5jtOCvogyujQOjNVGN4gz1wwPr
|
32
|
+
-----END CERTIFICATE-----
|
33
|
+
date: 2015-04-10 00:00:00.000000000 Z
|
34
|
+
dependencies:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rest-client
|
37
|
+
requirement: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 1.8.0
|
42
|
+
type: :runtime
|
43
|
+
prerelease: false
|
44
|
+
version_requirements: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 1.8.0
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: english
|
51
|
+
requirement: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 0.6.3
|
56
|
+
type: :runtime
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 0.6.3
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: timeout
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.0.1
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - '='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 0.0.1
|
77
|
+
- !ruby/object:Gem::Dependency
|
78
|
+
name: json
|
79
|
+
requirement: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - '='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 1.8.2
|
84
|
+
type: :runtime
|
85
|
+
prerelease: false
|
86
|
+
version_requirements: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 1.8.2
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: sensu-plugin
|
93
|
+
requirement: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - '='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 1.1.0
|
98
|
+
type: :runtime
|
99
|
+
prerelease: false
|
100
|
+
version_requirements: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - '='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: 1.1.0
|
105
|
+
- !ruby/object:Gem::Dependency
|
106
|
+
name: codeclimate-test-reporter
|
107
|
+
requirement: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0.4'
|
112
|
+
type: :development
|
113
|
+
prerelease: false
|
114
|
+
version_requirements: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - "~>"
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0.4'
|
119
|
+
- !ruby/object:Gem::Dependency
|
120
|
+
name: rubocop
|
121
|
+
requirement: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - '='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: 0.17.0
|
126
|
+
type: :development
|
127
|
+
prerelease: false
|
128
|
+
version_requirements: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - '='
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: 0.17.0
|
133
|
+
- !ruby/object:Gem::Dependency
|
134
|
+
name: rspec
|
135
|
+
requirement: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - "~>"
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '3.1'
|
140
|
+
type: :development
|
141
|
+
prerelease: false
|
142
|
+
version_requirements: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - "~>"
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '3.1'
|
147
|
+
- !ruby/object:Gem::Dependency
|
148
|
+
name: bundler
|
149
|
+
requirement: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - "~>"
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '1.7'
|
154
|
+
type: :development
|
155
|
+
prerelease: false
|
156
|
+
version_requirements: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - "~>"
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '1.7'
|
161
|
+
- !ruby/object:Gem::Dependency
|
162
|
+
name: rake
|
163
|
+
requirement: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - "~>"
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '10.0'
|
168
|
+
type: :development
|
169
|
+
prerelease: false
|
170
|
+
version_requirements: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - "~>"
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '10.0'
|
175
|
+
- !ruby/object:Gem::Dependency
|
176
|
+
name: github-markup
|
177
|
+
requirement: !ruby/object:Gem::Requirement
|
178
|
+
requirements:
|
179
|
+
- - "~>"
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '1.3'
|
182
|
+
type: :development
|
183
|
+
prerelease: false
|
184
|
+
version_requirements: !ruby/object:Gem::Requirement
|
185
|
+
requirements:
|
186
|
+
- - "~>"
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '1.3'
|
189
|
+
- !ruby/object:Gem::Dependency
|
190
|
+
name: redcarpet
|
191
|
+
requirement: !ruby/object:Gem::Requirement
|
192
|
+
requirements:
|
193
|
+
- - "~>"
|
194
|
+
- !ruby/object:Gem::Version
|
195
|
+
version: '3.2'
|
196
|
+
type: :development
|
197
|
+
prerelease: false
|
198
|
+
version_requirements: !ruby/object:Gem::Requirement
|
199
|
+
requirements:
|
200
|
+
- - "~>"
|
201
|
+
- !ruby/object:Gem::Version
|
202
|
+
version: '3.2'
|
203
|
+
- !ruby/object:Gem::Dependency
|
204
|
+
name: yard
|
205
|
+
requirement: !ruby/object:Gem::Requirement
|
206
|
+
requirements:
|
207
|
+
- - "~>"
|
208
|
+
- !ruby/object:Gem::Version
|
209
|
+
version: '0.8'
|
210
|
+
type: :development
|
211
|
+
prerelease: false
|
212
|
+
version_requirements: !ruby/object:Gem::Requirement
|
213
|
+
requirements:
|
214
|
+
- - "~>"
|
215
|
+
- !ruby/object:Gem::Version
|
216
|
+
version: '0.8'
|
217
|
+
- !ruby/object:Gem::Dependency
|
218
|
+
name: pry
|
219
|
+
requirement: !ruby/object:Gem::Requirement
|
220
|
+
requirements:
|
221
|
+
- - "~>"
|
222
|
+
- !ruby/object:Gem::Version
|
223
|
+
version: '0.10'
|
224
|
+
type: :development
|
225
|
+
prerelease: false
|
226
|
+
version_requirements: !ruby/object:Gem::Requirement
|
227
|
+
requirements:
|
228
|
+
- - "~>"
|
229
|
+
- !ruby/object:Gem::Version
|
230
|
+
version: '0.10'
|
231
|
+
description: Sensu plugins for cucumber
|
232
|
+
email: "<sensu-users@googlegroups.com>"
|
233
|
+
executables: []
|
234
|
+
extensions: []
|
235
|
+
extra_rdoc_files: []
|
236
|
+
files:
|
237
|
+
- CHANGELOG.md
|
238
|
+
- LICENSE
|
239
|
+
- README.md
|
240
|
+
- bin/README.md
|
241
|
+
- bin/check-cucumber.rb
|
242
|
+
- bin/cucumber-example/features/failing.feature
|
243
|
+
- bin/cucumber-example/features/passing.feature
|
244
|
+
- bin/cucumber-example/features/step_definitions/failing.js
|
245
|
+
- bin/cucumber-example/features/step_definitions/passing.js
|
246
|
+
- bin/cucumber-example/features/support/hooks.js
|
247
|
+
- bin/cucumber-example/features/support/world.js
|
248
|
+
- bin/cucumber-example/package.json
|
249
|
+
- lib/sensu-plugins-cucumber.rb
|
250
|
+
homepage: https://github.com/sensu-plugins/sensu-plugins-cucumber
|
251
|
+
licenses:
|
252
|
+
- MIT
|
253
|
+
metadata:
|
254
|
+
maintainer: ''
|
255
|
+
development_status: unmaintained
|
256
|
+
production_status: unstable - testing recommended
|
257
|
+
post_install_message:
|
258
|
+
rdoc_options: []
|
259
|
+
require_paths:
|
260
|
+
- lib
|
261
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
262
|
+
requirements:
|
263
|
+
- - ">="
|
264
|
+
- !ruby/object:Gem::Version
|
265
|
+
version: 1.9.3
|
266
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
267
|
+
requirements:
|
268
|
+
- - ">"
|
269
|
+
- !ruby/object:Gem::Version
|
270
|
+
version: 1.3.1
|
271
|
+
requirements: []
|
272
|
+
rubyforge_project:
|
273
|
+
rubygems_version: 2.2.2
|
274
|
+
signing_key:
|
275
|
+
specification_version: 4
|
276
|
+
summary: Sensu plugins for cucumber
|
277
|
+
test_files: []
|
278
|
+
has_rdoc:
|
metadata.gz.sig
ADDED
Binary file
|