Improve debugging of json parse failures in functional tests.

Signed-off-by: Ryan Davis <zenspider@chef.io>
This commit is contained in:
Ryan Davis 2019-10-10 16:40:23 -07:00
parent d7a2e047f4
commit b626c37386
3 changed files with 9 additions and 6 deletions

View file

@ -202,7 +202,7 @@ module FunctionalHelper
run_result.stdout.sub!("\n1 deprecation warning total\n", "")
end
if opts[:json]
if opts[:json] && !run_result.stdout.empty?
begin
payload = JSON.parse(run_result.stdout)

View file

@ -761,6 +761,7 @@ Test Summary: \e[38;5;41m2 successful\e[0m, 0 failures, 0 skipped\n"
let(:json_path) { File.join(config_dir_path, "json-config", "good.json") }
let(:cli_args) { "--config -" }
let(:opts) { { prefix: "cat " + json_path + " | ", json: true, env: env } }
let(:njopts) { opts.merge(json: false) }
# DO NOT use the `let`-defined run_result through here
# If you do, it will execute twice, and cause STDIN to read empty on the second time
@ -772,7 +773,7 @@ Test Summary: \e[38;5;41m2 successful\e[0m, 0 failures, 0 skipped\n"
end
it "detect should exit 0" do
result = run_inspec_process( "detect " + cli_args + " ", opts )
result = run_inspec_process( "detect " + cli_args + " ", njopts )
_(result.stderr).must_be_empty
@ -780,7 +781,7 @@ Test Summary: \e[38;5;41m2 successful\e[0m, 0 failures, 0 skipped\n"
end
it "shell should exit 0" do
result = run_inspec_process( 'shell -c "platform.family" ' + cli_args + " ", opts )
result = run_inspec_process( 'shell -c "platform.family" ' + cli_args + " ", njopts )
_(result.stderr).must_be_empty

View file

@ -9,8 +9,10 @@ require "functional/helper"
module VisibleSpaces
def show_spaces(str)
str.tr!(" ", "S")
str.tr!("\n", "N")
str
.tr(" ", "S")
.tr("\n", "N")
.b
end
end
@ -21,7 +23,7 @@ describe "InSpec UI behavior" do
parallelize_me!
let(:plugin_path) { File.join(mock_path, "plugins", "inspec-test-ui", "lib", "inspec-test-ui") }
let(:run_result) { run_inspec_with_plugin("#{pre_opts} testui #{feature} #{post_opts}", plugin_path: plugin_path) }
let(:run_result) { run_inspec_with_plugin("#{pre_opts} testui #{feature} #{post_opts}", plugin_path: plugin_path, json: false) }
let(:pre_opts) { "" }
let(:post_opts) { "" }