Configurable backend for Chef Infra in Target Mode (#7058)

* Add configurable InSpec backend for Chef Infra

Signed-off-by: Thomas Heinen <thomasheinen@gmail.com>

* Add changing backend for Chef Infra

Signed-off-by: Thomas Heinen <thomasheinen@gmail.com>

* Add test

* Fix typo on test

Signed-off-by: Thomas Heinen <thomasheinen@gmail.com>

* Fix test

Signed-off-by: Thomas Heinen <thomasheinen@gmail.com>

---------

Signed-off-by: Thomas Heinen <thomasheinen@gmail.com>
This commit is contained in:
Thomas Heinen 2024-06-28 08:38:18 +02:00 committed by GitHub
parent 9bca50c428
commit ea7e386028
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 25 additions and 2 deletions

View file

@ -89,7 +89,12 @@ module Inspec
end
def configure_transport
@backend = Inspec::Backend.create(@conf)
backend = Inspec::Backend.create(@conf)
set_backend(backend)
end
def set_backend(new_backend)
@backend = new_backend
@test_collector.backend = @backend
end

View file

@ -105,4 +105,22 @@ describe Inspec::Runner do
_(backend.backend.cache_enabled?(:command)).must_equal false
end
end
end
# =============================================================== #
# Backend Switching
# =============================================================== #
describe "when backend gets switched" do
it "replaces the existing backend with the given one" do
opts = { command_runner: :generic, backend_cache: false }
runner = Inspec::Runner.new(opts)
new_backend_config = Inspec::Config.new(backend_cache: true)
new_backend = Inspec::Backend.create(new_backend_config)
runner.set_backend(new_backend)
active_backend = runner.instance_variable_get(:@backend)
_(active_backend.backend).must_be_same_as(new_backend.backend)
end
end
end