Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow transports which are subclasses of the core ones. #32

Merged
merged 3 commits into from
Jan 14, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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