From 3781be5316092bf660804c515600629e8caa006a Mon Sep 17 00:00:00 2001 From: Jeffrey Coe Date: Mon, 17 Jun 2019 21:39:38 -0400 Subject: [PATCH 1/4] Add docker transport runner options Signed-off-by: Jeffrey Coe --- lib/kitchen/verifier/inspec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/kitchen/verifier/inspec.rb b/lib/kitchen/verifier/inspec.rb index aa33586..3a3c397 100644 --- a/lib/kitchen/verifier/inspec.rb +++ b/lib/kitchen/verifier/inspec.rb @@ -344,6 +344,20 @@ def runner_options_for_dockercli(config_data) logger.debug "Connect to Container: #{opts['host']}" opts end + + # Returns a configuration Hash that can be passed to a `Inspec::Runner`. + # + # @return [Hash] a configuration hash of string-based keys + # @api private + def runner_options_for_docker(config_data) + opts = { + 'backend' => 'docker', + 'logger' => logger, + 'host' => config_data[:container_id], + } + logger.debug "Connect to Container: #{opts['host']}" + opts + end end end end From 58ad5a0d9db0bffa75336553616433df1ed5ead1 Mon Sep 17 00:00:00 2001 From: Jeffrey Coe Date: Tue, 18 Jun 2019 16:03:43 -0400 Subject: [PATCH 2/4] Rubocop fixes Signed-off-by: Jeffrey Coe --- lib/kitchen/verifier/inspec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/kitchen/verifier/inspec.rb b/lib/kitchen/verifier/inspec.rb index 3a3c397..f75da8c 100644 --- a/lib/kitchen/verifier/inspec.rb +++ b/lib/kitchen/verifier/inspec.rb @@ -351,9 +351,9 @@ def runner_options_for_dockercli(config_data) # @api private def runner_options_for_docker(config_data) opts = { - 'backend' => 'docker', - 'logger' => logger, - 'host' => config_data[:container_id], + "backend" => "docker", + "logger" => logger, + "host" => config_data[:container_id], } logger.debug "Connect to Container: #{opts['host']}" opts From ee1aaa7931defcbffc207466d151bed0b76e2e4f Mon Sep 17 00:00:00 2001 From: Jeffrey Coe Date: Wed, 17 Jun 2020 16:09:16 -0400 Subject: [PATCH 3/4] Alias dockercli runner options method for new docker transport --- lib/kitchen/verifier/inspec.rb | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/lib/kitchen/verifier/inspec.rb b/lib/kitchen/verifier/inspec.rb index f75da8c..389c866 100644 --- a/lib/kitchen/verifier/inspec.rb +++ b/lib/kitchen/verifier/inspec.rb @@ -345,19 +345,8 @@ def runner_options_for_dockercli(config_data) opts end - # Returns a configuration Hash that can be passed to a `Inspec::Runner`. - # - # @return [Hash] a configuration hash of string-based keys - # @api private - def runner_options_for_docker(config_data) - opts = { - "backend" => "docker", - "logger" => logger, - "host" => config_data[:container_id], - } - logger.debug "Connect to Container: #{opts['host']}" - opts - end + # Add alias for docker transport from kitchen-docker gem + alias_method :runner_options_for_docker, :runner_options_for_dockercli end end end From fcf24e46f767409ddb69883a2c3f06500bb1796a Mon Sep 17 00:00:00 2001 From: Jeffrey Coe Date: Wed, 17 Jun 2020 16:09:49 -0400 Subject: [PATCH 4/4] Add integration test for docker transport Signed-off-by: Jeffrey Coe --- Gemfile | 1 + spec/kitchen/verifier/inspec_spec.rb | 34 ++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/Gemfile b/Gemfile index 0a7f585..4a1e9e0 100644 --- a/Gemfile +++ b/Gemfile @@ -20,6 +20,7 @@ end group :integration do gem "berkshelf", ">= 4.3.5" gem "kitchen-dokken" + gem "kitchen-docker", ">= 2.10.0" end group :tools do diff --git a/spec/kitchen/verifier/inspec_spec.rb b/spec/kitchen/verifier/inspec_spec.rb index 4dfd535..974cc7a 100644 --- a/spec/kitchen/verifier/inspec_spec.rb +++ b/spec/kitchen/verifier/inspec_spec.rb @@ -25,6 +25,7 @@ require "kitchen/transport/exec" require "kitchen/transport/ssh" require "kitchen/transport/winrm" +require "kitchen/transport/docker" describe Kitchen::Verifier::Inspec do @@ -664,6 +665,39 @@ end end + context "with a docker transport" do + + let(:transport) do + Kitchen::Transport::Docker.new + end + + let(:runner) do + instance_double("Inspec::Runner") + end + + before do + allow(runner).to receive(:add_target) + allow(runner).to receive(:run).and_return 0 + end + + it "constructs a Inspec::Runner using transport config data and state" do + expect(Inspec::Runner).to receive(:new) + .with( + hash_including( + "backend" => "docker", + :backend_cache => true, + "color" => true, + :controls => nil, + "host" => nil, + "logger" => logger + ) + ) + .and_return(runner) + + verifier.call({}) + end + end + context "with an unsupported transport" do it "#call raises a UserError" do