fix tests and lint

This commit is contained in:
Dominik Richter 2016-02-22 05:35:47 +01:00
parent d44af5dcc7
commit 33b2876d7c
8 changed files with 21 additions and 16 deletions

View file

@ -214,7 +214,7 @@ module Inspec
def load_params
params = @source_reader.metadata.params
params[:name] = @profile_id
params[:name] = @profile_id unless @profile_id.nil?
params[:rules] = rules = {}
prefix = @source_reader.target.prefix || ''

View file

@ -8,6 +8,7 @@ require 'forwardable'
require 'uri'
require 'inspec/backend'
require 'inspec/profile_context'
require 'inspec/profile'
require 'inspec/metadata'
# spec requirements
@ -60,6 +61,12 @@ module Inspec
end
end
def add_target(target, options = {})
profile = Inspec::Profile.for_target(target, options)
fail "Could not resolve #{target} to valid input." if profile.nil?
add_profile(profile)
end
def create_context
Inspec::ProfileContext.new(@profile_id, @backend)
end

View file

@ -48,11 +48,7 @@ module Inspec
o[:logger].level = get_log_level(o.log_level)
runner = Inspec::Runner.new(o)
targets.map { |t|
profile = Inspec::Profile.for_target(t, opts)
fail "Could not resolve #{t} to valid input." if profile.nil?
runner.add_profile(profile)
}
targets.each { |target| runner.add_target(target, opts) }
exit runner.run
rescue RuntimeError => e
puts e.message

View file

@ -42,7 +42,7 @@ class DockerTester
puts "--> run test on docker #{container.id}"
opts = { 'target' => "docker://#{container.id}" }
runner = Inspec::Runner.new(opts)
runner.add_tests(@tests)
@tests.each { |test| runner.add_target(test, opts) }
runner.tests.map { |g| g.run(report) }
end
end

View file

@ -21,7 +21,8 @@ describe Fetchers::Tar do
end
it 'must contain all files' do
_(res.files).must_equal ["inspec.yml", "libraries", "libraries/testlib.rb", "controls", "controls/filesystem_spec.rb"]
_(res.files.sort).must_equal %w{inspec.yml libraries libraries/testlib.rb
controls controls/filesystem_spec.rb}.sort
end
it 'must not read if the file isnt included' do

View file

@ -94,8 +94,8 @@ describe Fetchers::Url do
end
it 'must contain all files' do
_(res.files).must_equal %w{inspec.yml libraries libraries/testlib.rb
controls controls/filesystem_spec.rb}
_(res.files.sort).must_equal %w{inspec.yml libraries libraries/testlib.rb
controls controls/filesystem_spec.rb}.sort
end
it 'must not read if the file isnt included' do
@ -123,8 +123,8 @@ describe Fetchers::Url do
end
it 'must contain all files' do
_(res.files).must_equal %w{inspec.yml libraries libraries/testlib.rb
controls controls/filesystem_spec.rb}
_(res.files.sort).must_equal %w{inspec.yml libraries libraries/testlib.rb
controls controls/filesystem_spec.rb}.sort
end
it 'must not read if the file isnt included' do

View file

@ -21,7 +21,8 @@ describe Fetchers::Zip do
end
it 'must contain all files' do
_(res.files).must_equal ["inspec.yml", "libraries", "libraries/testlib.rb", "controls", "controls/filesystem_spec.rb"]
_(res.files.sort).must_equal %w{inspec.yml libraries libraries/testlib.rb
controls controls/filesystem_spec.rb}.sort
end
it 'must not read if the file isnt included' do

View file

@ -183,7 +183,7 @@ describe Inspec::Profile do
logger.expect :info, nil, ["Checking profile in #{home}/mock/profiles/#{profile_id}"]
logger.expect :info, nil, ['Metadata OK.']
logger.expect :info, nil, ['Found 1 controls.']
logger.expect :info, nil, ["Verify all controls in #{home}/mock/profiles/#{profile_id}/controls/filesystem_spec.rb"]
logger.expect :info, nil, ["Verify all controls in controls/filesystem_spec.rb"]
logger.expect :info, nil, ['Control definitions OK.']
result = MockLoader.load_profile(profile_id, {logger: logger}).check
@ -209,7 +209,7 @@ describe Inspec::Profile do
logger.expect :info, nil, ["Checking profile in #{home}/mock/profiles/#{profile_id}"]
logger.expect :info, nil, ['Metadata OK.']
logger.expect :info, nil, ['Found 1 controls.']
logger.expect :info, nil, ["Verify all controls in #{home}/mock/profiles/#{profile_id}/controls/filesystem_spec.rb"]
logger.expect :info, nil, ["Verify all controls in controls/filesystem_spec.rb"]
logger.expect :info, nil, ['Control definitions OK.']
result = MockLoader.load_profile(profile_id, {logger: logger}).check
@ -235,7 +235,7 @@ describe Inspec::Profile do
logger.expect :info, nil, ["Checking profile in #{home}/mock/profiles/#{profile_id}"]
logger.expect :info, nil, ['Metadata OK.']
logger.expect :info, nil, ['Found 1 controls.']
logger.expect :info, nil, ["Verify all controls in #{home}/mock/profiles/#{profile_id}/controls/filesystem_spec.rb"]
logger.expect :info, nil, ["Verify all controls in controls/filesystem_spec.rb"]
logger.expect :info, nil, ['Control definitions OK.']
result = MockLoader.load_profile(profile_id, {logger: logger}).check