Skip to content

Commit

Permalink
Merge pull request #32 from coderanger/transports
Browse files Browse the repository at this point in the history
Allow transports which are subclasses of the core ones.
  • Loading branch information
chris-rock committed Jan 14, 2016
2 parents 7b48d5e + 9d80f5f commit 3756ee7
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions lib/kitchen/verifier/inspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

require 'kitchen/transport/ssh'
require 'kitchen/transport/winrm'
require 'kitchen/verifier/inspec_version'
require 'kitchen/verifier/base'

Expand All @@ -33,25 +35,9 @@ class Inspec < Kitchen::Verifier::Base

# (see Base#call)
def call(state)
transport_data = instance.transport.diagnose.merge(state)

runner_options = case (name = instance.transport.name.downcase)
when 'ssh'
runner_options_for_ssh(transport_data)
when 'winrm'
runner_options_for_winrm(transport_data)
else
fail(
Kitchen::UserError,
"Verifier #{name}",
" does not support the #{name} Transport",
)
end
runner_options['format'] = config[:format] unless config[:format].nil?

tests = helper_files + local_suite_files

runner = ::Inspec::Runner.new(runner_options)
runner = ::Inspec::Runner.new(runner_options(instance.transport, state))
runner.add_tests(tests)
debug("Running specs from: #{tests.inspect}")
exit_code = runner.run
Expand Down Expand Up @@ -100,6 +86,23 @@ def local_suite_files
end
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(transport, state = {})
transport_data = transport.diagnose.merge(state)
if transport.is_a?(Kitchen::Transport::Ssh)
runner_options_for_ssh(transport_data)
elsif transport.is_a?(Kitchen::Transport::Winrm)
runner_options_for_winrm(transport_data)
else
fail Kitchen::UserError, "Verifier #{name} does not support the #{transport.name} Transport"
end.tap do |runner_options|
runner_options['format'] = config[:format] unless config[:format].nil?
end
end

# Returns a configuration Hash that can be passed to a `Inspec::Runner`.
#
# @return [Hash] a configuration hash of string-based keys
Expand Down

0 comments on commit 3756ee7

Please sign in to comment.