2017-12-06 21:22:11 +00:00
|
|
|
# copyright: 2017, Chef Software Inc.
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "thor"
|
2017-12-06 21:22:11 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "BaseCLI" do
|
2017-12-06 21:22:11 +00:00
|
|
|
let(:cli) { Inspec::BaseCLI.new }
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "formats the platfrom information" do
|
|
|
|
it "verify platform formatting" do
|
|
|
|
hash = { name: "test-os", families: "aws, cloud", release: "aws-sdk-v1" }
|
2018-02-20 12:37:23 +00:00
|
|
|
expect = <<EOF
|
|
|
|
Name: \e[1m\e[35mtest-os\e[0m
|
|
|
|
Families: \e[1m\e[35maws, cloud\e[0m
|
|
|
|
Release: \e[1m\e[35maws-sdk-v1\e[0m
|
|
|
|
EOF
|
2019-01-28 01:07:32 +00:00
|
|
|
_(Inspec::BaseCLI.format_platform_info(params: hash, indent: 2, color: 35)).must_equal expect
|
2018-02-09 16:46:09 +00:00
|
|
|
end
|
2017-12-06 21:22:11 +00:00
|
|
|
end
|
2018-02-08 09:06:58 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "configure_logger" do
|
2019-05-18 00:41:19 +00:00
|
|
|
after do
|
|
|
|
Inspec::Log.init
|
|
|
|
Inspec::Log.level = :fatal
|
|
|
|
end
|
|
|
|
|
2018-02-09 14:14:40 +00:00
|
|
|
let(:options) do
|
|
|
|
o = {
|
2019-06-11 22:24:35 +00:00
|
|
|
"log_location" => $stderr,
|
|
|
|
"log_level" => "debug",
|
|
|
|
"reporter" => {
|
|
|
|
"json" => {
|
|
|
|
"stdout" => true,
|
2018-02-09 16:19:52 +00:00
|
|
|
},
|
|
|
|
},
|
2018-02-09 14:14:40 +00:00
|
|
|
}
|
|
|
|
Thor::CoreExt::HashWithIndifferentAccess.new(o)
|
|
|
|
end
|
2019-05-18 00:43:58 +00:00
|
|
|
|
2018-02-09 16:19:52 +00:00
|
|
|
let(:format) do
|
|
|
|
device = options[:logger].instance_variable_get(:"@logdev")
|
|
|
|
device.instance_variable_get(:"@dev")
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "sets to stderr for log_location" do
|
2018-02-09 16:19:52 +00:00
|
|
|
cli.send(:configure_logger, options)
|
2019-09-30 22:31:55 +00:00
|
|
|
_(format).must_equal $stderr
|
2018-02-09 16:19:52 +00:00
|
|
|
end
|
2018-02-09 14:14:40 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "sets to stderr for json" do
|
|
|
|
options.delete("log_location")
|
|
|
|
options.delete("log_level")
|
2018-02-09 16:19:52 +00:00
|
|
|
cli.send(:configure_logger, options)
|
2019-09-30 22:31:55 +00:00
|
|
|
_(format).must_equal $stderr
|
2018-02-09 16:19:52 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "sets defaults to stdout for everything else" do
|
|
|
|
options.delete("log_location")
|
|
|
|
options.delete("log_level")
|
|
|
|
options.delete("reporter")
|
2018-02-09 16:19:52 +00:00
|
|
|
|
2018-02-09 14:14:40 +00:00
|
|
|
cli.send(:configure_logger, options)
|
2019-09-30 22:31:55 +00:00
|
|
|
_(format).must_equal $stdout
|
2018-02-09 14:14:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "suppress_log_output?" do
|
|
|
|
it "suppresses json" do
|
|
|
|
opts = { "reporter" => { "json" => { "stdout" => true } } }
|
2019-09-30 22:31:55 +00:00
|
|
|
_(cli.send(:suppress_log_output?, opts)).must_equal true
|
2018-02-08 09:06:58 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "do not suppresses json-min when going to file" do
|
|
|
|
opts = { "reporter" => { "json-min" => { "file" => "/tmp/json" } } }
|
2019-09-30 22:31:55 +00:00
|
|
|
_(cli.send(:suppress_log_output?, opts)).must_equal false
|
2018-02-08 09:06:58 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "suppresses json-rspec" do
|
|
|
|
opts = { "reporter" => { "json-rspec" => { "stdout" => true } } }
|
2019-09-30 22:31:55 +00:00
|
|
|
_(cli.send(:suppress_log_output?, opts)).must_equal true
|
2018-02-08 09:06:58 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "suppresses json-automate" do
|
|
|
|
opts = { "reporter" => { "json-automate" => { "stdout" => true } } }
|
2019-09-30 22:31:55 +00:00
|
|
|
_(cli.send(:suppress_log_output?, opts)).must_equal true
|
2018-08-23 17:43:48 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "suppresses junit" do
|
|
|
|
opts = { "reporter" => { "junit" => { "stdout" => true } } }
|
2019-09-30 22:31:55 +00:00
|
|
|
_(cli.send(:suppress_log_output?, opts)).must_equal true
|
2018-02-08 09:06:58 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "do not suppresses cli" do
|
|
|
|
opts = { "reporter" => { "cli" => nil } }
|
2019-09-30 22:31:55 +00:00
|
|
|
_(cli.send(:suppress_log_output?, opts)).must_equal false
|
2018-02-08 09:06:58 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "do not suppresses cli" do
|
|
|
|
opts = { "reporter" => { "cli" => nil, "json" => { "file" => "/tmp/json" } } }
|
2019-09-30 22:31:55 +00:00
|
|
|
_(cli.send(:suppress_log_output?, opts)).must_equal false
|
2018-02-08 09:06:58 +00:00
|
|
|
end
|
|
|
|
end
|
2017-12-06 21:22:11 +00:00
|
|
|
end
|