fix --config-test and add a couple of tests

fixes #4933

Fixes #4946
This commit is contained in:
Joao Duarte 2016-03-31 08:39:28 +01:00 committed by João Duarte
parent 54ab10dfb0
commit 3b55273262
3 changed files with 24 additions and 3 deletions

View file

@ -56,6 +56,7 @@ module LogStash; class Pipeline
begin
# There should be a better way to test this
self.new(config_str, settings)
true
rescue => e
e.message
end

View file

@ -166,9 +166,9 @@ class LogStash::Runner < Clamp::Command
end
if config_test?
config_loader = LogStash::Config::Loader.new(@logger, config_test?)
config_loader = LogStash::Config::Loader.new(@logger)
config_str = config_loader.format_config(config_path, config_string)
config_error = LogStash::Pipeline.config_valid?(config_str)
config_error = LogStash::Pipeline.validate_config(config_str)
if config_error == true
@logger.terminal "Configuration OK"
return 0
@ -213,7 +213,7 @@ class LogStash::Runner < Clamp::Command
show_short_help
return 1
rescue => e
@logger.fatal I18n.t("oops", :error => e, :backtrace => e.backtrace)
@logger.fatal(I18n.t("oops"), :error => e, :backtrace => e.backtrace)
return 1
ensure
Stud::untrap("INT", sigint_id) unless sigint_id.nil?

View file

@ -95,6 +95,26 @@ describe LogStash::Runner do
end
end
context "--config-test" do
subject { LogStash::Runner.new("") }
let(:args) { ["-t", "-e", pipeline_string] }
context "with a good configuration" do
let(:pipeline_string) { "input { } filter { } output { }" }
it "should exit successfuly" do
expect(channel).to receive(:terminal)
expect(subject.run(args)).to eq(0)
end
end
context "with a bad configuration" do
let(:pipeline_string) { "rlwekjhrewlqrkjh" }
it "should fail by returning a bad exit code" do
expect(channel).to receive(:fatal)
expect(subject.run(args)).to eq(1)
end
end
end
describe "pipeline settings" do
let(:pipeline_string) { "input { stdin {} } output { stdout {} }" }
let(:main_pipeline_settings) { { :pipeline_id => "main" } }