2016-02-21 12:26:31 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
# author: Dominik Richter
|
|
|
|
# author: Christoph Hartmann
|
|
|
|
|
|
|
|
require 'helper'
|
|
|
|
|
|
|
|
describe SourceReaders::InspecReader do
|
|
|
|
let(:reader) { SourceReaders::InspecReader }
|
|
|
|
|
|
|
|
it 'registers with the source readers registry' do
|
|
|
|
reg = Inspec::SourceReader.registry
|
|
|
|
_(reg['inspec']).must_equal reader
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with a valid profile' do
|
2016-09-07 11:10:35 +00:00
|
|
|
let(:mock_file) { MockLoader.profile_tgz('complete-profile') }
|
2016-09-08 09:11:44 +00:00
|
|
|
let(:target) { Inspec::FileProvider.for_path(mock_file) }
|
2016-02-21 12:26:31 +00:00
|
|
|
let(:res) { Inspec::SourceReader.resolve(target) }
|
|
|
|
|
|
|
|
it 'resolves the target to inspec' do
|
|
|
|
_(res).must_be_kind_of reader
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'retrieves metadata' do
|
|
|
|
_(res.metadata.params[:name]).must_equal 'complete'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'retrieves all files' do
|
|
|
|
_(res.tests.keys).must_equal %w{controls/filesystem_spec.rb}
|
2016-09-07 11:10:35 +00:00
|
|
|
_(res.tests.values[0]).must_match(/^control 'test01' do$/)
|
2016-02-21 12:26:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'retrieves all libraries' do
|
|
|
|
_(res.libraries.keys).must_equal %w{libraries/testlib.rb}
|
2016-09-07 11:10:35 +00:00
|
|
|
_(res.libraries.values[0]).must_match(/^# Library resource$/)
|
2016-02-21 12:26:31 +00:00
|
|
|
end
|
2017-04-26 01:07:39 +00:00
|
|
|
|
|
|
|
it 'retrieves all extra files' do
|
2017-07-11 19:33:55 +00:00
|
|
|
_(res.data_files.keys).must_equal %w{files/a_sub_dir/sub_items.conf files/items.conf}
|
|
|
|
_(res.data_files['files/items.conf']).must_equal "one\ntwo\nthree\n"
|
|
|
|
_(res.data_files['files/a_sub_dir/sub_items.conf']).must_equal "[section]\nkey = value\n"
|
2017-04-26 01:07:39 +00:00
|
|
|
end
|
2016-02-21 12:26:31 +00:00
|
|
|
end
|
2017-03-08 20:22:24 +00:00
|
|
|
|
|
|
|
describe 'with an invalid inspec.yml' do
|
|
|
|
let(:mock_file) { MockLoader.profile_tgz('profile-with-bad-metadata') }
|
|
|
|
let(:target) { Inspec::FileProvider.for_path(mock_file) }
|
|
|
|
let(:res) { Inspec::SourceReader.resolve(target) }
|
|
|
|
|
|
|
|
it 'raises an exception' do
|
|
|
|
err = proc { _(res.metadata) }.must_raise RuntimeError
|
|
|
|
err.message.must_match(/Unable to parse inspec\.yml: line \d+/)
|
|
|
|
end
|
|
|
|
end
|
2016-02-21 12:26:31 +00:00
|
|
|
end
|