inspec/test/unit/runner_test.rb
Vasundhara Jagdale 699d73993c
Licensing - Integrates Software Entitlement (#13)
* CFINSPEC-24:Integrate License Software Entitlment.

Signed-off-by: Vasu1105 <vasundhara.jagdale@chef.io>

* CFINSPEC-506 license execution check

Signed-off-by: Vasu1105 <vasundhara.jagdale@chef.io>

* Software entitlement call changes and handling of error

Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>

* Error handling from chef licensing error to standard error

Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>

* Updated Gemfile to pick the chef licensing changes from git url

Signed-off-by: Vasu1105 <vasundhara.jagdale@chef.io>

* Trying with https url

Signed-off-by: Vasu1105 <vasundhara.jagdale@chef.io>

* Revert "Trying with https url"

This reverts commit 33f1f4c0ecacf9ba2826e25e55b41219903ea736.

* Adds the license not entitled exit code

Signed-off-by: Vasu1105 <vasundhara.jagdale@chef.io>

* Updates the require statement

Signed-off-by: Vasu1105 <vasundhara.jagdale@chef.io>

* Fix typo

Signed-off-by: Vasu1105 <vasundhara.jagdale@chef.io>

* Set the licensing configure for entitlement id failure

Signed-off-by: Vasu1105 <vasundhara.jagdale@chef.io>

* Use ChefLicensing::Error instead of standard error

Signed-off-by: Vasu1105 <vasundhara.jagdale@chef.io>

* REFACTOR Move out licensing cong=fig to its own file and make unconditional

Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>

* FIX TESTS - Add reference to licensing config for places where we call runner explicitly.

Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>

* Update inputs_test to use license configuration from utils

Signed-off-by: Vasu1105 <vasundhara.jagdale@chef.io>

---------

Signed-off-by: Vasu1105 <vasundhara.jagdale@chef.io>
Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
Co-authored-by: Nikita Mathur <nikita.mathur@chef.io>
Co-authored-by: Clinton Wolfe <clintoncwolfe@gmail.com>
2023-03-27 10:26:35 -04:00

108 lines
3.5 KiB
Ruby

# copyright: 2017, Chef Software Inc.
require "helper"
require "inspec/secrets"
require "inspec/runner"
require "inspec/fetcher/mock"
require "inspec/utils/licensing_config"
describe Inspec::Runner do
let(:runner) { Inspec::Runner.new({ command_runner: :generic, reporter: [] }) }
it "bug #4524" do
file = <<-RUBY
describe "a thing" do
before(:all) { os }
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
subject! { os }
its("family") { should_not eq 42 }
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
# =============================================================== #
# Reporter Options
# =============================================================== #
describe "confirm reporter defaults to cli" do
it "defaults to cli when format and reporter not set" do
opts = { command_runner: :generic, backend_cache: true }
runner = Inspec::Runner.new(opts)
config = runner.instance_variable_get(:"@conf")
expected = { "cli" => { "stdout" => true } }
_(config["reporter"]).must_equal expected
end
it "does not default when format is set" do
opts = { command_runner: :generic, backend_cache: true, "reporter" => ["json"] }
runner = Inspec::Runner.new(opts)
config = runner.instance_variable_get(:"@conf")
expected = { "json" => { "stdout" => true } }
_(config["reporter"]).must_equal expected
end
it "deletes format if set to a rspec format" do
opts = { command_runner: :generic, backend_cache: true, "reporter" => ["progress"] }
runner = Inspec::Runner.new(opts)
config = runner.instance_variable_get(:"@conf")
_(config["reporter"]).must_equal({})
end
end
# =============================================================== #
# Exit Codes
# =============================================================== #
describe "testing runner.run exit codes" do
it "returns proper exit code when no profile is added" do
WebMock.allow_net_connect!
_(runner.run).must_equal 0
end
end
# =============================================================== #
# Backend Caching
# =============================================================== #
describe "when backend caching is enabled" do
it "returns a backend with caching" do
opts = { command_runner: :generic, backend_cache: true }
runner = Inspec::Runner.new(opts)
backend = runner.instance_variable_get(:@backend)
_(backend.backend.cache_enabled?(:command)).must_equal true
end
end
describe "when backend caching is disabled" do
it "returns a backend without caching" do
opts = { command_runner: :generic, backend_cache: false }
runner = Inspec::Runner.new(opts)
backend = runner.instance_variable_get(:@backend)
_(backend.backend.cache_enabled?(:command)).must_equal false
end
it "returns a backend without caching as default" do
backend = runner.instance_variable_get(:@backend)
_(backend.backend.cache_enabled?(:command)).must_equal false
end
end
end