mirror of
https://github.com/inspec/inspec
synced 2024-11-26 22:50:36 +00:00
fix tests and lint
This commit is contained in:
parent
d44af5dcc7
commit
33b2876d7c
8 changed files with 21 additions and 16 deletions
|
@ -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 || ''
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue