serverspec-logstash-formatter 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 489779c688221277fbb1376bd29798d4e79ee255
4
+ data.tar.gz: 1214d3966acbcca01861b67f3dcf5a0afd99cc9f
5
+ SHA512:
6
+ metadata.gz: f021d98a8f94ca51df47c3647b136012dc82e9ee60656794b59dc92491a30d13c6b23b9fe5d64868913462cbf14166607ed5d496d1cb30af5f1cdb3c26fe2608
7
+ data.tar.gz: 603ce5d7ed7cc4b073e2623aeefbbb8d6df844b54ce1f022a6320aa53b1163be14a71e834732875c6071583bb624200f69c406d058b52027439f42475a52ed6c
checksums.yaml.gz.sig ADDED
Binary file
data.tar.gz.sig ADDED
@@ -0,0 +1,2 @@
1
+ -
2
+ ~���V���#.�3X#��y�X�x7���K��,ʰU��)W�� �"'sm�0�h�J�o�3�T3����r�����-63or��a����<��E�%Lr �[g�_�t]���]��w��<��a��"A%��N�c��]�%��{ 1&yj�b>���� MkT�Ķ�8;3���aЍ ��C� �8}��i,���7��.2l�F{��G`R�-�D�����k}.U>�d�n�@��@�?�49a�x�֙ч��Oˆ
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 TheFork
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # Serverspec logstash formatter
2
+
3
+ A logstash formatter for [serverspec](http://serverspec.org)
4
+
5
+ Installation
6
+ --------------------------------------------------------------------------------
7
+
8
+ First:
9
+
10
+ ```ruby
11
+ gem install serverspec-logstash-formatter
12
+ ```
13
+
14
+ or in your Gemfile
15
+
16
+ ```ruby
17
+ gem 'serverspec-logstash-formatter
18
+ ```
19
+
20
+ Then, when running rspec:
21
+
22
+ ```
23
+ rspec --format logstash
24
+ ```
25
+
26
+ Or, if you want to use the logstash formatter as your default formatter, simply put the options in your `.rspec` file:
27
+
28
+ --format logstash
@@ -0,0 +1,59 @@
1
+ require 'rspec/core'
2
+ require 'rspec/core/formatters/json_formatter'
3
+
4
+
5
+ class ServerspecLogstashFormatter < RSpec::Core::Formatters::BaseFormatter
6
+ RSpec::Core::Formatters.register self, :message, :stop, :close
7
+
8
+ attr_reader :output_hash
9
+
10
+ def initialize(output)
11
+ super
12
+ @output_hash = {
13
+ :version => RSpec::Core::Version::STRING
14
+ }
15
+ end
16
+
17
+ def message(notification)
18
+ (@output_hash[:messages] ||= []) << notification.message
19
+ end
20
+
21
+ def stop(notification)
22
+ @output_hash = notification.examples.map do |example|
23
+ format_example(example).tap do |hash|
24
+ e = example.exception
25
+ if e
26
+ hash[:exception] = {
27
+ :class => e.class.name,
28
+ :message => e.message,
29
+ :backtrace => e.backtrace,
30
+ }
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ def close(_notification)
37
+ @output_hash.each do | entry |
38
+ output.write entry.to_json
39
+ output.write "\n"
40
+ end
41
+ output.close if IO === output && output != $stdout
42
+ end
43
+
44
+ private
45
+
46
+ def format_example(example)
47
+ {
48
+ :description => example.description,
49
+ :full_description => example.full_description,
50
+ :status => example.execution_result.status.to_s,
51
+ :file_path => example.metadata[:file_path],
52
+ :started_at => example.execution_result.started_at,
53
+ :hostname => ENV.fetch('TARGET_HOST'),
54
+ :line_number => example.metadata[:line_number],
55
+ :run_time => example.execution_result.run_time,
56
+ :pending_message => example.execution_result.pending_message,
57
+ }
58
+ end
59
+ end
@@ -0,0 +1,49 @@
1
+ require 'logstash_formatter'
2
+ require 'json'
3
+ require 'rspec/core/reporter'
4
+
5
+ RSpec.describe LogstashFormatter do
6
+ include FormatterSupport
7
+
8
+ it "can be loaded via `--format logstash`" do
9
+ output = run_example_specs_with_formatter("logstash", :normalize_output => false, :seed => 42)
10
+ #NOT EMPTY ?
11
+ parsed = JSON.parse(output)
12
+ expect(parsed.keys).to include("examples", "summary", "summary_line", "seed")
13
+ end
14
+
15
+ it "outputs expected json" do
16
+ its = []
17
+ group = RSpec.describe("one apiece") do
18
+ its.push it("succeeds") { expect(1).to eq 1 }
19
+ end
20
+ succeeding_line = __LINE__ - 4
21
+ failing_line = __LINE__ - 4
22
+ pending_line = __LINE__ - 4
23
+
24
+ now = Time.now
25
+ allow(Time).to receive(:now).and_return(now)
26
+ reporter.report(2) do |r|
27
+ group.run(r)
28
+ end
29
+
30
+ # grab the actual backtrace -- kind of a cheat
31
+ this_file = relative_path(__FILE__)
32
+
33
+ expected = {
34
+ :id => its[0].id,
35
+ :description => "succeeds",
36
+ :full_description => "one apiece succeeds",
37
+ :status => "passed",
38
+ :file_path => this_file,
39
+ :line_number => succeeding_line,
40
+ :hostname => "R2D2",
41
+ :started_at => "2017",
42
+ :run_time => formatter.output_hash[:run_time],
43
+ :pending_message => nil,
44
+ }
45
+ expect(formatter.output_hash).to eq expected
46
+ expect(formatter_output.string).to eq expected.to_json
47
+ end
48
+ end
49
+
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: serverspec-logstash-formatter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jean-Sébastien Hedde
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDijCCAnKgAwIBAgIBATANBgkqhkiG9w0BAQUFADBFMRAwDgYDVQQDDAdqc2hl
14
+ ZGRlMRwwGgYKCZImiZPyLGQBGRYMbGFmb3VyY2hldHRlMRMwEQYKCZImiZPyLGQB
15
+ GRYDY29tMB4XDTE3MDgwOTE2NTEwOFoXDTE4MDgwOTE2NTEwOFowRTEQMA4GA1UE
16
+ AwwHanNoZWRkZTEcMBoGCgmSJomT8ixkARkWDGxhZm91cmNoZXR0ZTETMBEGCgmS
17
+ JomT8ixkARkWA2NvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMFK
18
+ j4bs5jmGR2O6axdkjvn21LU8Mv6T/IY+XvRx0LMULJVj0ZHJ/eI/nuASbqEQJPIn
19
+ PAZgG/X51PKRjJhm3iKh2qhIi8Xl+ybupJPHYWwaRqaGM/ZipZD810txGl1T1eG7
20
+ volvqIPgxEHc9yOt7l+rur44vT3217qgaUxJ4fBxN9L2ZyiYMb/iqkKjuR6dzPM3
21
+ 240akH1tDki26njHtzjejXoqr6L+PaoYgy54SgHr8yK4VW4snfX8VE1wHRGksvnu
22
+ oohA/rekXNRFt5M2c426ifbRV5/WOxGsSpsXgGQyg45BVd8FZWlcBDIvmrxrE+T/
23
+ MfmDfT7N6v9Sx5ii3tECAwEAAaOBhDCBgTAJBgNVHRMEAjAAMAsGA1UdDwQEAwIE
24
+ sDAdBgNVHQ4EFgQUq/uzA3cIlP/suY1cFwScEx1e+uwwIwYDVR0RBBwwGoEYanNo
25
+ ZWRkZUBsYWZvdXJjaGV0dGUuY29tMCMGA1UdEgQcMBqBGGpzaGVkZGVAbGFmb3Vy
26
+ Y2hldHRlLmNvbTANBgkqhkiG9w0BAQUFAAOCAQEAuOvHKN2llW4azZyXiP8T5a81
27
+ ybprQZgPHA+PkQOi5oAG44cgmGqpKYcjeXUzeyiPOyDNJxX19F1JtZAGjA74iTDl
28
+ KW9SDatLa+UYjGhyj0aP3/eDxxStV0NS+jBj6NoXms+5U1nprjhgSGFwr3vNpTtE
29
+ R8osWHwMr4xiGe45b3XkrwINTX6YQN6+QWnsgM8wJorNKWLX/01SK5K6xUozf9er
30
+ Q+iCHgYjldQgLTscfsfIFl6S2R2y6wA+ORsy1EGN9nDO2kJRoeHrGW3wi+keC62B
31
+ 4I9h+oMqqz1gvVkSb1WMI7rtYQDyo6GDIxz4j4c3x3HESfEv0ursDwgoi+dWzA==
32
+ -----END CERTIFICATE-----
33
+ date: 2017-08-10 00:00:00.000000000 Z
34
+ dependencies:
35
+ - !ruby/object:Gem::Dependency
36
+ name: rspec-core
37
+ requirement: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '3.0'
42
+ type: :runtime
43
+ prerelease: false
44
+ version_requirements: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '3.0'
49
+ - !ruby/object:Gem::Dependency
50
+ name: rspec
51
+ requirement: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '3.0'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '3.0'
63
+ description: A logstash formatter for serverspec
64
+ email: '["jshedde@lafourchette.com"]'
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - LICENSE
70
+ - README.md
71
+ - lib/serverspec_logstash_formatter.rb
72
+ - spec/logstash_spec.rb
73
+ homepage: https://github.com/lafourchette/serverspec-logstash-formatter
74
+ licenses:
75
+ - MIT
76
+ metadata:
77
+ allowed_push_host: https://rubygems.org
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.5.2
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: A logstash formatter for serverspec
98
+ test_files:
99
+ - spec/logstash_spec.rb
metadata.gz.sig ADDED
Binary file