logstash-devutils 2.2.0-java → 2.4.0-java

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
  SHA256:
3
- metadata.gz: bbd9bcbe08648ad69e9cbf9781acbebfa5168e0c9c8be8a253620b1ec20bb6f4
4
- data.tar.gz: a91b1a94368455897c54bc705f4a647c89919e7964ed568cf909d9c477b2e35b
3
+ metadata.gz: f6acb50f9d6e040af22acda0163ef38f8bce77506f023dd8a58a4ee925d9df3c
4
+ data.tar.gz: 51c47c93c93335ed8cba0e0349dc712808051e77ca69ca8f79617eaa9442731a
5
5
  SHA512:
6
- metadata.gz: e5d3faadbce4f82285d54231a742cc3ebae7f8da46cc575ddd55a3f9ac51488ff5b79af8b52956c7de9672c61080c80a6a5206dfe618f7f76f2b9844cb476ac4
7
- data.tar.gz: 4c7b243ebed7a5747b35315f2c88059aa32f498af5d34f6096ad5df9a6b6f1122b0c5e87649b3e7b97351bd757dffd811302335deaa200a60471d06829368696
6
+ metadata.gz: 8fa7d3f493f223e497c7877bfc9c6a9440a269367a02d7c6f468580f0ac6d4e6156600ba30fc2fcc831a27cef74a6e65cbfa7daebd29623042557b524a3423ff
7
+ data.tar.gz: a6530c6d9bd097ea6f081224a7ff6254e38f3d6abc400f3b4bbaca5cea7b354e4e37b60071755eef6d05bac2afce89601b53b72b4339ba15b97696dceb541cb1
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 2.4.0
2
+ - Feat: shared test (spec) task for all! [#96](https://github.com/elastic/logstash-devutils/pull/96)
3
+
4
+ ## 2.3.0
5
+ - Introduce `be_a_logstash_timestamp_equivalent_to` RSpec matcher to compare LogStash::Timestamp [#99](https://github.com/elastic/logstash-devutils/pull/99)
6
+
7
+ ## 2.2.1
8
+ - Fixed `LogStashHelpers#sample` to work with pipelines whose filters add, clone, and cancel events.
9
+
1
10
  ## 2.2.0
2
11
  - Add `allowed_lag` config for shared input interruptiblity spec
3
12
 
@@ -22,15 +31,15 @@
22
31
  - [BREAKING] changes:
23
32
  * `plugin_input` helper no longer works - simply fails with a not implemented error
24
33
  * `type` and `tags` helpers have no effect - they will print a deprecation warning
25
- * using gem **insist** is discouraged and has to be pulled in manually
34
+ * using gem **insist** is discouraged and has to be pulled in manually
26
35
  (in *plugin.gemspec* `add_development_dependency 'insist'` and `require "insist"`)
27
36
  * shared examples need to be explicitly required, as they are not re-used that much
28
37
  (in spec_helper.rb `require "logstash/devutils/rspec/shared_examples"'`)
29
38
  * `input` helper now yields a Queue-like collection (with `Queue#pop` blocking semantics)
30
- with a default timeout polling mechanism to guard against potential dead-locks
39
+ with a default timeout polling mechanism to guard against potential dead-locks
31
40
 
32
41
  ## 1.3.6
33
- - Revert the removal (e.g. add back) of the log4j spec helper. It is still needed for 5.x builds.
42
+ - Revert the removal (e.g. add back) of the log4j spec helper. It is still needed for 5.x builds.
34
43
 
35
44
  ## 1.3.5
36
45
  - Fix spec helper method `input` generating an invalid `output_func` that returned `nil` instead of an array
@@ -10,7 +10,7 @@ if RUBY_PLATFORM == "java"
10
10
  cmd = Shellwords.join(arguments)
11
11
  Open3.popen3(cmd) do |_i, stdout, stderr, thr|
12
12
  output = [stderr.read, stdout.read].join.strip
13
- raise Error, "`#{cmd}` -> #{output}" if thr.value.exitstatus > 0
13
+ raise Error, output if thr.value.exitstatus > 0
14
14
  return output
15
15
  end
16
16
  end
@@ -0,0 +1,17 @@
1
+ begin
2
+ require 'rspec/core/rake_task'
3
+ RSpec::Core::RakeTask.new(:spec) # default glob: 'spec/**{,/*/**}/*_spec.rb'
4
+ rescue LoadError
5
+ end
6
+
7
+ desc "Run tests including Java tests (if any)"
8
+ task :test => [ 'test:java', 'test:ruby' ]
9
+ namespace :test do
10
+ task :java do
11
+ gradlew = File.join(Dir.pwd, 'gradlew')
12
+ sh "#{gradlew} --no-daemon test" if File.exist?(gradlew)
13
+ end
14
+ task :ruby => :vendor do
15
+ Rake::Task[:spec].invoke
16
+ end
17
+ end
@@ -1,3 +1,4 @@
1
1
  raise "Only JRuby is supported at this time." unless RUBY_PLATFORM == "java"
2
2
  load "logstash/devutils/rake/publish.rake"
3
3
  load "logstash/devutils/rake/vendor.rake"
4
+ load "logstash/devutils/rake/test.rake"
@@ -1,6 +1,7 @@
1
1
  require "logstash/agent"
2
2
  require "logstash/event"
3
3
  require "logstash/test_pipeline"
4
+ require "logstash/outputs/test_sink"
4
5
 
5
6
  require "stud/try"
6
7
  require "rspec/expectations"
@@ -52,11 +53,30 @@ module LogStashHelper
52
53
  deprecated "tags(#{tags.inspect}) - let(:default_tags) are not used"
53
54
  end
54
55
 
55
- def sample(sample_event, &block)
56
+ ##
57
+ # Creates a single-example example group in the current rspec context to validate the results of filter operations.
58
+ # The current group is expected to use `LogStashHelpers#config` to provide a pipeline configuration.
59
+ #
60
+ # The provided block has access to an [Array] `results`, and also sets an unnamed `subject` that is either a
61
+ # single `LogStash::Event` or an `[Array[LogStash::Event]]` containing at least two entries.
62
+ #
63
+ # @param sample_event [String, #to_json]
64
+ # @param validation_source [:output, :queue]
65
+ # @yield creates an example with expectations provided by the block
66
+ # @return [void]
67
+ def sample(sample_event, validation_source: :output, &block)
68
+ validation_sources = [:output, :queue].freeze
69
+ fail(ArgumentError, "Unexpected source `#{validation_source.inspect}`, expected one of #{validation_sources.inspect}") unless validation_sources.include?(validation_source)
70
+
56
71
  name = sample_event.is_a?(String) ? sample_event : LogStash::Json.dump(sample_event)
57
72
  name = name[0..50] + "..." if name.length > 50
58
73
 
59
- describe "\"#{name}\"" do
74
+ describe name.inspect do
75
+ if validation_source == :output
76
+ let(:test_sink) { LogStash::Outputs::TestSink.new("release_on_close" => false, "store_events" => true) }
77
+ before { expect(LogStash::Outputs::TestSink).to receive(:new).and_return(test_sink) }
78
+ end
79
+
60
80
  let(:pipeline) { new_pipeline_from_string(config) }
61
81
  let(:event) do
62
82
  sample_event = [sample_event] unless sample_event.is_a?(Array)
@@ -73,7 +93,11 @@ module LogStashHelper
73
93
  # flush makes sure to empty any buffered events in the filter
74
94
  pipeline.flush_filters(:final => true) { |flushed_event| results << flushed_event }
75
95
 
76
- pipeline.filter_queue_client.processed_events
96
+ case validation_source
97
+ when :queue then pipeline.filter_queue_client.processed_events # legacy?
98
+ when :output then test_sink.event_store.to_a
99
+ else fail NotImplementedError("validation source `#{validation_source}` not implemented.")
100
+ end
77
101
  end
78
102
 
79
103
  # starting at logstash-core 5.3 an initialized pipeline need to be closed
@@ -83,7 +107,7 @@ module LogStashHelper
83
107
 
84
108
  subject { results.length > 1 ? results : results.first }
85
109
 
86
- it("when processed", &block)
110
+ it("processes events as specified", &block)
87
111
  end
88
112
  end # def sample
89
113
 
@@ -38,6 +38,16 @@ else
38
38
  LogStash::Logging::Logger::configure_logging('ERROR')
39
39
  end
40
40
 
41
+ RSpec::Matchers.define :be_a_logstash_timestamp_equivalent_to do |expected|
42
+ # use the Timestamp compare to avoid suffering of precision loss of time format
43
+ expected = LogStash::Timestamp.new(expected) unless expected.kind_of?(LogStash::Timestamp)
44
+ description { "be a LogStash::Timestamp equivalent to #{expected}" }
45
+
46
+ match do |actual|
47
+ actual.kind_of?(LogStash::Timestamp) && actual == expected
48
+ end
49
+ end
50
+
41
51
  RSpec.configure do |config|
42
52
  # for now both include and extend are required because the newly refactored "input" helper method need to be visible in a "it" block
43
53
  # and this is only possible by calling include on LogStashHelper
@@ -57,4 +67,3 @@ RSpec.configure do |config|
57
67
  # --seed 1234
58
68
  config.order = :random
59
69
  end
60
-
@@ -4,7 +4,7 @@ Gem::Specification.new do |spec|
4
4
  files = %x{git ls-files}.split("\n")
5
5
 
6
6
  spec.name = "logstash-devutils"
7
- spec.version = "2.2.0"
7
+ spec.version = "2.4.0"
8
8
  spec.license = "Apache-2.0"
9
9
  spec.authors = ["Elastic"]
10
10
  spec.email = "info@elastic.co"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-devutils
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.4.0
5
5
  platform: java
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-14 00:00:00.000000000 Z
11
+ date: 2022-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -163,6 +163,7 @@ files:
163
163
  - Rakefile
164
164
  - lib/logstash/devutils/rake.rb
165
165
  - lib/logstash/devutils/rake/publish.rake
166
+ - lib/logstash/devutils/rake/test.rake
166
167
  - lib/logstash/devutils/rake/vendor.rake
167
168
  - lib/logstash/devutils/rspec/log4j2.properties
168
169
  - lib/logstash/devutils/rspec/logstash_helpers.rb
@@ -191,8 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
192
  - !ruby/object:Gem::Version
192
193
  version: '0'
193
194
  requirements: []
194
- rubyforge_project:
195
- rubygems_version: 2.7.10
195
+ rubygems_version: 3.1.6
196
196
  signing_key:
197
197
  specification_version: 4
198
198
  summary: An assortment of tooling/libraries to make Logstash plugin development and