inspec/test/unit/source_readers/inspec_test.rb
eramoto 435ad68698 Sort gotten file list on test (#2812)
When testing on a filesystem used for a long time or built on a small
sized partition, the actual file order may be different from the
expected file order as below:

    1) Failure:
  inspec keyword::inspec.profile.files#test_0002_lists all profile files when calling #files [/work/git/inspec/test/unit/dsl/other_keywords_test.rb:50]:
  --- expected
  +++ actual
  @@ -1 +1 @@
  -["a_sub_dir/sub_items.conf", "items.conf"]
  +["items.conf", "a_sub_dir/sub_items.conf"]

    2) Failure:
  SourceReaders::InspecReader::with a valid profile#test_0005_retrieves all extra files [/work/git/inspec/test/unit/source_readers/inspec_test.rb:39]:
  --- expected
  +++ actual
  @@ -1 +1 @@
  -["files/a_sub_dir/sub_items.conf", "files/items.conf"]
  +["files/items.conf", "files/a_sub_dir/sub_items.conf"]

Signed-off-by: ERAMOTO Masaya <eramoto.masaya@jp.fujitsu.com>
2018-03-14 09:35:43 -04:00

55 lines
1.8 KiB
Ruby

# 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
let(:mock_file) { MockLoader.profile_tgz('complete-profile') }
let(:target) { Inspec::FileProvider.for_path(mock_file) }
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}
_(res.tests.values[0]).must_match(/^control 'test01' do$/)
end
it 'retrieves all libraries' do
_(res.libraries.keys).must_equal %w{libraries/testlib.rb}
_(res.libraries.values[0]).must_match(/^# Library resource$/)
end
it 'retrieves all extra files' do
_(res.data_files.keys.sort).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"
end
end
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
end