sensu-plugins-rspec 0.0.1.alpha.3 → 0.0.1.alpha.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9c2fccfcf3ebb4a3dcf5961c832e36d6696ddf26
4
- data.tar.gz: c4332f1aeb0cd53e9c6462c57a5548f3240c62f9
3
+ metadata.gz: 691e9d04d8b81e7606ce89ed1fc90845d0fa78d0
4
+ data.tar.gz: 93d743ebd2837b3b820cf990d0368d1f02ae378e
5
5
  SHA512:
6
- metadata.gz: 17a852636807d900b7cb2b340fba6da785d6d8d76d5ffda6a3f63c51f10644452b48067b109d606f42171be23813b2d0ba71e1b29a352b8de2753815c642a609
7
- data.tar.gz: 5fdb12daf09837d2d07966b6d2f2a3475abfb9e1c50e3d4b2658165df75d2aba9c306de91d67f1fe424bca4bc98574611d96302695e330abbf7c406fe79ddfe5
6
+ metadata.gz: 60a3abf9d667c0ba24089d5d85a7c0fe5bc0d2caf2788fa85509c583a4ec77d1101881fe8a0605c4bb45a5525ea490bade3a6ddb8230d8298a615b7a35bfef53
7
+ data.tar.gz: 2e0c9e5e5e8935977e525b5efba9fdea217cc743848a178761570769fa872c5a78bc7f268749a7a78588b7ae098d22498171b9fea7605bc40eea37e555e53e34
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -12,3 +12,6 @@
12
12
  #### 0.0.1.alpha.3
13
13
 
14
14
  * pin all runtime dependencies
15
+ * fix rubocop issues
16
+ * add new version modules
17
+ * add new bump and version rake tasks
data/README.md CHANGED
@@ -47,7 +47,7 @@ You can also download the key from /certs/ within each repository.
47
47
 
48
48
  #### Bundler
49
49
 
50
- Add *sensu-plugins-disk-checks* to your Gemfile and run `bundle install` or `bundle update`
50
+ Add *sensu-plugins-rspec* to your Gemfile and run `bundle install` or `bundle update`
51
51
 
52
52
  #### Chef
53
53
 
@@ -0,0 +1,189 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+ # check-test-suite
4
+ #
5
+ # DESCRIPTION:
6
+ # This plugin attempts to run rspec and return the results of the run to the handler.
7
+ #
8
+ # When a run begins, it creates a file cache that it will reference on the next run to
9
+ # prevent false positives from being returned to the handler. If the run fails a particular
10
+ # codebase twice, then it will return critical to the handler, not on the first fail.
11
+ #
12
+ # OUTPUT:
13
+ # plain text
14
+ #
15
+ # PLATFORMS:
16
+ # Linux
17
+ #
18
+ # DEPENDENCIES:
19
+ # gem: sensu-plugin
20
+ # gem: json
21
+ # gem: rspec
22
+ # gem: fileutils
23
+ #
24
+ # USAGE:
25
+ # Recommended usage:
26
+ # sudo /opt/sensu/embedded/bin/ruby /etc/sensu/plugins/check-test-suite.rb -p codebase1,codebase2,codebase3 -b /path/to/codebase's/ruby
27
+ #
28
+ # NOTES:
29
+ # codebase should be a full path to the root of the codebase (current folder ideally)
30
+ # sudo is preferred but may not be necessary
31
+ # Depending on your test suite, the sensu user may not have write permissions to the directories where the code is to deal with things like coverage gem)
32
+ # The codebases must be managed through git to be effective, the check relies on being able to find the commits in the filesystem.
33
+ #
34
+ # LICENSE:
35
+ # Louis Alridge louis@socialcentiv.com (loualrid@gmail.com)
36
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
37
+ # for details.
38
+
39
+ require 'json'
40
+ require 'rspec'
41
+ require 'fileutils'
42
+ require 'sensu-plugin/check/cli'
43
+
44
+ #
45
+ # CheckTestSuite Class
46
+ #
47
+ class CheckTestSuite < Sensu::Plugin::Check::CLI
48
+ option :paths,
49
+ description: 'Paths to run the tests, comma delimited',
50
+ short: '-p PATHS',
51
+ long: '--path PATHS'
52
+
53
+ option :ruby_bin,
54
+ description: 'Location of ruby bin, it is highly recommended to use the rvm gemset ruby if utilizing rvm',
55
+ short: '-b ruby',
56
+ long: '--ruby-bin ruby',
57
+ default: 'ruby'
58
+
59
+ option :environment_variables,
60
+ description: 'Optional additional environmental variables to pass to ruby and/or rspec',
61
+ short: '-e aws_access_key_id=XXX',
62
+ long: '--env-var aws_access_key_id=XXX',
63
+ required: false
64
+
65
+ option :test_suite,
66
+ description: 'Test suite to test against, defaults to rspec',
67
+ short: '-t SUITE',
68
+ long: '--test-suite SUITE',
69
+ default: 'rspec'
70
+
71
+ option :suite_arguments,
72
+ description: 'Optional args to pass to rspec, defaults to --fail-fast. Enclose args in quotes or else the plugin will error',
73
+ short: '-a "RSPEC_ARGS"',
74
+ long: '--args "RSPEC_ARGS"',
75
+ default: '--fail-fast'
76
+
77
+ option :gem_home,
78
+ description: 'Attempts to utilize the bundle stored in vendor/bundle. Cookbooks not using the standard gem location will need to set this',
79
+ short: '-d GEM_HOME',
80
+ long: '--gem-home GEM_HOME',
81
+ default: 'vendor/bundle'
82
+
83
+ def initialize_file_cache(branch, commit)
84
+ commit_file_directory = "/var/log/sensu/check-test-suite-#{ branch }"
85
+
86
+ FileUtils.mkdir_p commit_file_directory
87
+
88
+ write_file_cache_message "#{ commit_file_directory }/#{ commit }", 'verified'
89
+ end
90
+
91
+ def write_file_cache_message(location, message)
92
+ if !File.exist?(location)
93
+ File.open(location, 'w') { |f| f.write(message) }
94
+ else
95
+ File.open(location, 'a') { |f| f.puts(message) }
96
+ end
97
+ end
98
+
99
+ def run #rubocop:disable all
100
+ full_start = Time.now
101
+ tests = {}
102
+ successful_tests = {}
103
+
104
+ final_gem_home = config[:gem_home]
105
+
106
+ config[:paths].split(',').each do |path|
107
+ start = Time.now
108
+ tests[path] = {}
109
+
110
+ tests[path]['commit'] = `/bin/readlink #{ path }`.split('/').last.chomp.strip
111
+ tests[path]['branch'] = `cd #{ path } && /usr/bin/git branch -r --contains #{ tests[path]['commit'] }`.split("\n").last.chomp.strip.split('origin/').last
112
+
113
+ initialize_file_cache tests[path]['branch'], tests[path]['commit']
114
+
115
+ commit_file = "/var/log/sensu/check-test-suite-#{ tests[path]['branch'] }/#{ tests[path]['commit'] }"
116
+
117
+ next if File.exist?(commit_file) && File.read(commit_file).include?('successful')
118
+
119
+ if config[:gem_home] == 'vendor/bundle'
120
+ target_ruby = ''
121
+ target_rubies = Dir.entries("#{ path }/#{ config[:gem_home] }/ruby").select { |item| item =~ /(\d+\.\d+\.\d+)/ }
122
+
123
+ target_rubies.each do |ruby|
124
+ target_rubies.each do |other_ruby|
125
+ target_ruby = if ruby != other_ruby
126
+ ruby if Gem::Version.new(ruby) > Gem::Version.new(other_ruby)
127
+ elsif target_rubies.count == 1
128
+ ruby
129
+ end
130
+ end
131
+ end
132
+
133
+ final_gem_home = `/bin/readlink #{ path }`.chomp.strip + "/#{ config[:gem_home] }/ruby/#{ target_ruby }"
134
+ end
135
+
136
+ ENV['GEM_HOME'] = final_gem_home
137
+ test_suite_args = [
138
+ "cd #{ path };",
139
+ "#{ config[:environment_variables] } #{config[:ruby_bin]} -S #{ config[:test_suite] }",
140
+ "#{ config[:suite_arguments] } --failure-exit-code 2"
141
+ ]
142
+
143
+ tests[path]['test_suite_out'] = `#{ test_suite_args.join(' ') }`
144
+ tests[path]['runtime'] = Time.now - start
145
+ tests[path]['exitstatus'] = $CHILD_STATUS.exitstatus
146
+ tests[path]['commit'] = `/bin/readlink #{ path }`.split('/').last
147
+ target_branch = `cd #{ path } && /usr/bin/git branch -r --contains #{ tests[path]['commit'] }`
148
+ tests[path]['branch'] = target_branch.split("\n").last.chomp.strip.split('origin/').last
149
+ tests[path]['metadata'] = `cd #{ path } && /usr/bin/git show #{ tests[path]['commit'] }`
150
+
151
+ case tests[path]['exitstatus']
152
+ when 2
153
+ test_suite_lines = tests[path]['test_suite_out'].split("\n")
154
+ test_suite_out_fail_line = test_suite_lines.index(test_suite_lines.select { |line| line.include?('Failures:') }.first)
155
+
156
+ write_file_cache_message commit_file, 'failure'
157
+
158
+ # To eliminate false positives, we run a failing suite twice before sending the response
159
+ next if File.read(commit_file).scan(/failure/).count < 2
160
+
161
+ critical_out = [
162
+ "CRITICAL! Rspec returned failed tests for #{ tests[path]['branch'] }!",
163
+ "#{ tests[path]['metadata'] }#{ test_suite_lines[test_suite_out_fail_line..(test_suite_lines.count)].join("\n") }",
164
+ "Error'd in #{ tests[path]['runtime'] } seconds."
165
+ ]
166
+
167
+ critical critical_out.join("\n\n")
168
+ when 0
169
+ successful_tests[path] = tests[path]
170
+
171
+ write_file_cache_message commit_file, 'successful'
172
+
173
+ if config[:paths].split(',').length == 1
174
+ ok "OK! Rspec returned no failed tests for #{ tests[path]['branch'] }.\n\n#{ tests[path]['metadata'] }\n\nCompleted in #{ tests[path]['runtime'] }"
175
+ end
176
+ else
177
+ unknown "Strange exit status detected for rspec on #{ tests[path]['branch'] }.\n\n#{ tests[path]['test_suite_out'] }"
178
+ end
179
+ end
180
+
181
+ successful_branches = []
182
+
183
+ successful_tests.each_pair { |_key, hash| successful_branches << hash['branch'] }
184
+
185
+ ok "OK! Rspec returned no failed tests for #{ successful_branches.join(', ') }.\nCompleted in #{ full_start - Time.now } seconds."
186
+ rescue StandardError => e
187
+ critical "Error message: #{ e }\n#{ e.backtrace.join("\n") }"
188
+ end
189
+ end
@@ -1,7 +1,15 @@
1
+
2
+ require 'sensu-plugins-rspec/version'
3
+
4
+ # Load the defaults
5
+
1
6
  #
2
- # Set gem version
7
+ # Default class
3
8
  #
4
- module SensuPluginsRspec
5
- # Gem version
6
- VERSION = '0.0.1.alpha.3'
9
+ module SensuPluginsRSpec
10
+ class << self
11
+ end
12
+
13
+ class << self
14
+ end
7
15
  end
@@ -0,0 +1,28 @@
1
+ require 'json'
2
+
3
+ # encoding: utf-8
4
+ module SensuPluginsRSpec
5
+ # This defines the version of the gem
6
+ module Version
7
+ MAJOR = 0
8
+ MINOR = 0
9
+ PATCH = 1
10
+
11
+ VER_STRING = [MAJOR, MINOR, PATCH, 'alpha.4'].compact.join('.')
12
+
13
+ NAME = 'sensu-plugins-rspec'
14
+ BANNER = "#{NAME} v%s"
15
+
16
+ module_function
17
+
18
+ def version
19
+ format(BANNER, VER_STRING)
20
+ end
21
+
22
+ def json_version
23
+ {
24
+ 'version' => VER_STRING
25
+ }.to_json
26
+ end
27
+ end
28
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.alpha.3
4
+ version: 0.0.1.alpha.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yieldbot, Inc. and contributors
@@ -30,7 +30,7 @@ cert_chain:
30
30
  8sHuVruarogxxKPBzlL2is4EUb6oN/RdpGx2l4254+nyR+abg//Ed27Ym0PkB4lk
31
31
  HP0m8WSjZmFr109pE/sVsM5jtOCvogyujQOjNVGN4gz1wwPr
32
32
  -----END CERTIFICATE-----
33
- date: 2015-03-06 00:00:00.000000000 Z
33
+ date: 2015-04-02 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: sensu-plugin
@@ -50,58 +50,64 @@ dependencies:
50
50
  name: json
51
51
  requirement: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - "~>"
53
+ - - '='
54
54
  - !ruby/object:Gem::Version
55
- version: '1.8'
55
+ version: 1.8.2
56
56
  type: :runtime
57
57
  prerelease: false
58
58
  version_requirements: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - "~>"
60
+ - - '='
61
61
  - !ruby/object:Gem::Version
62
- version: '1.8'
62
+ version: 1.8.2
63
63
  - !ruby/object:Gem::Dependency
64
64
  name: rspec
65
65
  requirement: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '3.1'
69
+ version: '3.2'
70
+ - - '='
71
+ - !ruby/object:Gem::Version
72
+ version: 3.2.0
70
73
  type: :runtime
71
74
  prerelease: false
72
75
  version_requirements: !ruby/object:Gem::Requirement
73
76
  requirements:
74
77
  - - "~>"
75
78
  - !ruby/object:Gem::Version
76
- version: '3.1'
79
+ version: '3.2'
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 3.2.0
77
83
  - !ruby/object:Gem::Dependency
78
84
  name: codeclimate-test-reporter
79
85
  requirement: !ruby/object:Gem::Requirement
80
86
  requirements:
81
- - - ">="
87
+ - - "~>"
82
88
  - !ruby/object:Gem::Version
83
- version: '0'
89
+ version: '0.4'
84
90
  type: :development
85
91
  prerelease: false
86
92
  version_requirements: !ruby/object:Gem::Requirement
87
93
  requirements:
88
- - - ">="
94
+ - - "~>"
89
95
  - !ruby/object:Gem::Version
90
- version: '0'
96
+ version: '0.4'
91
97
  - !ruby/object:Gem::Dependency
92
98
  name: rubocop
93
99
  requirement: !ruby/object:Gem::Requirement
94
100
  requirements:
95
- - - "~>"
101
+ - - '='
96
102
  - !ruby/object:Gem::Version
97
- version: '0.17'
103
+ version: 0.17.0
98
104
  type: :development
99
105
  prerelease: false
100
106
  version_requirements: !ruby/object:Gem::Requirement
101
107
  requirements:
102
- - - "~>"
108
+ - - '='
103
109
  - !ruby/object:Gem::Version
104
- version: '0.17'
110
+ version: 0.17.0
105
111
  - !ruby/object:Gem::Dependency
106
112
  name: bundler
107
113
  requirement: !ruby/object:Gem::Requirement
@@ -186,10 +192,9 @@ dependencies:
186
192
  - - "~>"
187
193
  - !ruby/object:Gem::Version
188
194
  version: '0.10'
189
- description: Checks for RSpec test completion and status
195
+ description: Sensu plugins for working with RSpec
190
196
  email: "<sensu-users@googlegroups.com>"
191
- executables:
192
- - check-rspec.rb
197
+ executables: []
193
198
  extensions: []
194
199
  extra_rdoc_files: []
195
200
  files:
@@ -197,11 +202,16 @@ files:
197
202
  - LICENSE
198
203
  - README.md
199
204
  - bin/check-rspec.rb
205
+ - bin/check-test-suite.rb
200
206
  - lib/sensu-plugins-rspec.rb
207
+ - lib/sensu-plugins-rspec/version.rb
201
208
  homepage: https://github.com/sensu-plugins/sensu-plugins-rspec
202
209
  licenses:
203
210
  - MIT
204
- metadata: {}
211
+ metadata:
212
+ maintainer: ''
213
+ development_status: active
214
+ production_status: unstable - testing recommended
205
215
  post_install_message:
206
216
  rdoc_options: []
207
217
  require_paths:
@@ -221,5 +231,6 @@ rubyforge_project:
221
231
  rubygems_version: 2.2.2
222
232
  signing_key:
223
233
  specification_version: 4
224
- summary: Checks for RSpec test completion and status
234
+ summary: Sensu plugins for working with RSpec
225
235
  test_files: []
236
+ has_rdoc:
metadata.gz.sig CHANGED
Binary file