Skip to content

Commit

Permalink
add test to parse the inspec_tests properly
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-rock committed Feb 28, 2016
1 parent 3c69d8a commit e60b7ca
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 6 deletions.
14 changes: 10 additions & 4 deletions lib/kitchen/verifier/inspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ class Inspec < Kitchen::Verifier::Base

# (see Base#call)
def call(state)
p config[:inspec_tests]
# get local tests and get run list of profiles
tests = (local_suite_files + config[:inspec_tests]).compact
tests = collect_tests

opts = runner_options(instance.transport, state)
runner = ::Inspec::Runner.new(opts)
Expand All @@ -95,7 +93,7 @@ def load_needed_dependencies!
# - test/integration
# - test/integration/inspec (prefered if used with other test environments)
#
# @return [Array<String>] array of suite files
# @return [Array<String>] array of suite directories
# @api private
def local_suite_files
base = File.join(config[:test_base_path], config[:suite_name])
Expand All @@ -115,6 +113,14 @@ def local_suite_files
[base]
end

# Returns an array of test profiles
# @return [Array<String>] array of suite directories or remote urls
# @api private
def collect_tests
# get local tests and get run list of profiles
(local_suite_files + config[:inspec_tests]).compact
end

# Returns a configuration Hash that can be passed to a `Inspec::Runner`.
#
# @return [Hash] a configuration hash of string-based keys
Expand Down
51 changes: 49 additions & 2 deletions spec/kitchen/verifier/inspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
verifier.call(port: 123)
end

it 'find test path for runner' do
it 'find test directory for runner' do
# create_test_files
allow(Inspec::Runner).to receive(:new).and_return(runner)
expect(runner).to receive(:add_target).with(
Expand All @@ -174,7 +174,7 @@
verifier.call({})
end

it 'find test path for runner if legacy' do
it 'find test directory for runner if legacy' do
create_legacy_test_directories
allow(Inspec::Runner).to receive(:new).and_return(runner)
expect(runner).to receive(:add_target).with(
Expand All @@ -194,6 +194,53 @@
end
end

context 'with an remote profile' do

let(:transport) do
Kitchen::Transport::Ssh.new({})
end

let(:runner) do
instance_double('Inspec::Runner')
end

let(:suite) do
instance_double('Kitchen::Suite', { name: 'local' })
end

let(:instance) do
instance_double(
'Kitchen::Instance',
name: 'coolbeans',
logger: logger,
platform: platform,
suite: suite,
transport: transport,
to_str: 'instance',
)
end

let(:config) {
{
inspec_tests: ['https://github.com/nathenharvey/tmp_compliance_profile'],
}
}

before do
allow(runner).to receive(:add_target)
allow(runner).to receive(:run).and_return 0
end

it 'find test directory and remote profile' do
allow(Inspec::Runner).to receive(:new).and_return(runner)
expect(runner).to receive(:add_target).with(
File.join(config[:test_base_path], 'local'), anything)
expect(runner).to receive(:add_target).with(
'https://github.com/nathenharvey/tmp_compliance_profile', anything)
verifier.call({})
end
end

context 'with an winrm transport' do

let(:transport_config) do
Expand Down

0 comments on commit e60b7ca

Please sign in to comment.