2017-05-05 13:04:02 +00:00
|
|
|
# copyright: 2017, Chef Software Inc.
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/secrets"
|
|
|
|
require "inspec/runner"
|
2019-11-22 14:57:28 +00:00
|
|
|
require "inspec/fetcher/mock"
|
2017-05-05 13:04:02 +00:00
|
|
|
|
|
|
|
describe Inspec::Runner do
|
2019-10-31 08:55:32 +00:00
|
|
|
let(:runner) { Inspec::Runner.new({ command_runner: :generic, reporter: [] }) }
|
2019-02-26 02:05:18 +00:00
|
|
|
|
2019-10-31 09:04:04 +00:00
|
|
|
it "bug #4524" do
|
|
|
|
file = <<-RUBY
|
|
|
|
describe "a thing" do
|
2019-10-31 22:20:58 +00:00
|
|
|
before(:all) { os }
|
2019-10-31 09:04:04 +00:00
|
|
|
it("should pass") {}
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
runner.add_target("bug4524.rb" => file)
|
|
|
|
runner.load
|
|
|
|
|
|
|
|
result = RSpec::Core::Runner.new(nil).run_specs(runner.test_collector.tests)
|
|
|
|
|
|
|
|
_(result).must_equal 0
|
|
|
|
end
|
|
|
|
|
|
|
|
it "bug #4587" do
|
|
|
|
file = <<-RUBY
|
|
|
|
describe "a thing" do
|
2019-10-31 22:20:58 +00:00
|
|
|
subject! { os }
|
|
|
|
its("family") { should_not eq 42 }
|
2019-10-31 09:04:04 +00:00
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
runner.add_target("bug4587.rb" => file)
|
|
|
|
runner.load
|
|
|
|
|
|
|
|
result = RSpec::Core::Runner.new(nil).run_specs(runner.test_collector.tests)
|
|
|
|
|
|
|
|
_(result).must_equal 0
|
|
|
|
end
|
|
|
|
|
2019-02-26 02:05:18 +00:00
|
|
|
# =============================================================== #
|
|
|
|
# Reporter Options
|
|
|
|
# =============================================================== #
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "confirm reporter defaults to cli" do
|
|
|
|
it "defaults to cli when format and reporter not set" do
|
2019-02-26 02:05:18 +00:00
|
|
|
opts = { command_runner: :generic, backend_cache: true }
|
|
|
|
runner = Inspec::Runner.new(opts)
|
|
|
|
config = runner.instance_variable_get(:"@conf")
|
2019-06-11 22:24:35 +00:00
|
|
|
expected = { "cli" => { "stdout" => true } }
|
2019-09-30 22:31:55 +00:00
|
|
|
_(config["reporter"]).must_equal expected
|
2018-10-24 19:08:07 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "does not default when format is set" do
|
|
|
|
opts = { command_runner: :generic, backend_cache: true, "reporter" => ["json"] }
|
2019-02-26 02:05:18 +00:00
|
|
|
runner = Inspec::Runner.new(opts)
|
|
|
|
config = runner.instance_variable_get(:"@conf")
|
2019-06-11 22:24:35 +00:00
|
|
|
expected = { "json" => { "stdout" => true } }
|
2019-09-30 22:31:55 +00:00
|
|
|
_(config["reporter"]).must_equal expected
|
2017-12-04 21:40:14 +00:00
|
|
|
end
|
|
|
|
|
2021-08-30 23:49:46 +00:00
|
|
|
it "deletes format if set to a rspec format" do
|
2019-06-11 22:24:35 +00:00
|
|
|
opts = { command_runner: :generic, backend_cache: true, "reporter" => ["progress"] }
|
2019-02-26 02:05:18 +00:00
|
|
|
runner = Inspec::Runner.new(opts)
|
|
|
|
config = runner.instance_variable_get(:"@conf")
|
2019-09-30 22:31:55 +00:00
|
|
|
_(config["reporter"]).must_equal({})
|
2017-05-05 13:04:02 +00:00
|
|
|
end
|
2019-02-26 02:05:18 +00:00
|
|
|
end
|
2017-05-05 13:04:02 +00:00
|
|
|
|
2019-02-26 02:05:18 +00:00
|
|
|
# =============================================================== #
|
|
|
|
# Exit Codes
|
|
|
|
# =============================================================== #
|
2017-05-05 13:04:02 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "testing runner.run exit codes" do
|
|
|
|
it "returns proper exit code when no profile is added" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(runner.run).must_equal 0
|
2017-05-05 13:04:02 +00:00
|
|
|
end
|
2019-02-26 02:05:18 +00:00
|
|
|
end
|
2017-05-05 13:04:02 +00:00
|
|
|
|
2019-02-26 02:05:18 +00:00
|
|
|
# =============================================================== #
|
|
|
|
# Backend Caching
|
|
|
|
# =============================================================== #
|
2017-05-05 13:04:02 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "when backend caching is enabled" do
|
|
|
|
it "returns a backend with caching" do
|
2019-02-26 02:05:18 +00:00
|
|
|
opts = { command_runner: :generic, backend_cache: true }
|
|
|
|
runner = Inspec::Runner.new(opts)
|
|
|
|
backend = runner.instance_variable_get(:@backend)
|
2019-09-30 22:31:55 +00:00
|
|
|
_(backend.backend.cache_enabled?(:command)).must_equal true
|
2017-05-05 13:04:02 +00:00
|
|
|
end
|
2019-02-26 02:05:18 +00:00
|
|
|
end
|
2017-05-05 13:04:02 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "when backend caching is disabled" do
|
|
|
|
it "returns a backend without caching" do
|
2019-02-26 02:05:18 +00:00
|
|
|
opts = { command_runner: :generic, backend_cache: false }
|
|
|
|
runner = Inspec::Runner.new(opts)
|
|
|
|
backend = runner.instance_variable_get(:@backend)
|
2019-09-30 22:31:55 +00:00
|
|
|
_(backend.backend.cache_enabled?(:command)).must_equal false
|
2017-05-05 13:04:02 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "returns a backend without caching as default" do
|
2019-02-26 02:05:18 +00:00
|
|
|
backend = runner.instance_variable_get(:@backend)
|
2019-09-30 22:31:55 +00:00
|
|
|
_(backend.backend.cache_enabled?(:command)).must_equal false
|
2017-05-05 13:04:02 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|