diff --git a/lib/fluent/test/driver/filter.rb b/lib/fluent/test/driver/filter.rb index 8f9ef831c7..f1ac18bc6e 100644 --- a/lib/fluent/test/driver/filter.rb +++ b/lib/fluent/test/driver/filter.rb @@ -25,9 +25,31 @@ module Driver class Filter < Base include EventFeeder + attr_reader :filtered + def initialize(klass, opts: {}, &block) super raise ArgumentError, "plugin is not an instance of Fluent::Plugin::Filter" unless @instance.is_a? Fluent::Plugin::Filter + @filtered = [] + end + + def filtered_records + @filtered.map {|_time, record| record } + end + + def instance_hook_after_started + super + filter_hook = ->(time, record) { @filtered << [time, record] } + m = Module.new do + define_method(:filter_stream) do |tag, es| + new_es = super(tag, es) + new_es.each do |time, record| + filter_hook.call(time, record) + end + new_es + end + end + @instance.singleton_class.prepend(m) end end end