make plugin#inspect show number config parameters

Fixes #3564
This commit is contained in:
Joao Duarte 2015-07-07 10:12:38 +01:00 committed by Jordan Sissel
parent 0306d3808a
commit d7bfd25dab
2 changed files with 20 additions and 4 deletions

View file

@ -111,10 +111,10 @@ class LogStash::Plugin
public
def inspect
if !@config.nil?
description = @config \
.select { |k,v| !v.nil? && (v.respond_to?(:empty?) && !v.empty?) } \
.collect { |k,v| "#{k}=>#{v.inspect}" }
if !@params.nil?
description = @params
.reject { |k, v| v.nil? || (v.respond_to?(:empty?) && v.empty?) }
.collect { |k, v| "#{k}=>#{v.inspect}" }
return "<#{self.class.name} #{description.join(", ")}>"
else
return "<#{self.class.name} --->"

View file

@ -29,6 +29,22 @@ describe LogStash::Plugin do
expect(LogStash::Plugin.lookup("filter", "lady_gaga")).to eq(LogStash::Filters::LadyGaga)
end
describe "#inspect" do
class LogStash::Filters::MyTestFilter < LogStash::Filters::Base
config_name "param1"
config :num, :validate => :number, :default => 20
config :str, :validate => :string, :default => "test"
end
subject { LogStash::Filters::MyTestFilter.new("num" => 1, "str" => "hello") }
it "should print the class of the filter" do
expect(subject.inspect).to match(/^<LogStash::Filters::MyTestFilter/)
end
it "should list config options and values" do
expect(subject.inspect).to match(/num=>1, str=>"hello"/)
end
end
context "when validating the plugin version" do
let(:plugin_name) { 'logstash-filter-stromae' }
subject do