inspec/test/unit/source_readers/flat_test.rb

64 lines
1.6 KiB
Ruby
Raw Normal View History

require "helper"
require "inspec/source_reader"
require "source_readers/flat" # TODO: break circular
2016-02-21 17:03:48 +00:00
describe SourceReaders::Flat do
let(:reader) { SourceReaders::Flat }
it "registers with the source readers registry" do
2016-02-21 17:03:48 +00:00
reg = Inspec::SourceReader.registry
_(reg["flat"]).must_equal reader
2016-02-21 17:03:48 +00:00
end
describe "with a flat file" do
let(:target) { Inspec::FileProvider.for_path(__FILE__) }
let(:res) { Inspec::SourceReader.resolve(target.relative_provider) }
2016-02-21 17:03:48 +00:00
it "resolves the target" do
2016-02-21 17:03:48 +00:00
_(res).must_be_kind_of reader
end
it "has no metadata" do
2016-02-21 17:03:48 +00:00
_(res.metadata.params).must_equal({})
end
it "retrieves all files" do
2016-02-21 17:03:48 +00:00
_(res.tests.keys).must_equal [File.basename(__FILE__)]
_(res.tests.values[0]).must_equal File.read(__FILE__)
end
it "has no libraries" do
2016-02-21 17:03:48 +00:00
_(res.libraries).must_be_empty
end
it "has no files" do
_(res.data_files).must_be_empty
end
2016-02-21 17:03:48 +00:00
end
describe "with a flat folder" do
let(:target) { Inspec::FileProvider.for_path(File.dirname(__FILE__)) }
let(:res) { Inspec::SourceReader.resolve(target.relative_provider) }
2016-02-21 17:03:48 +00:00
it "resolves the target" do
2016-02-21 17:03:48 +00:00
_(res).must_be_kind_of reader
end
it "has no metadata" do
2016-02-21 17:03:48 +00:00
_(res.metadata.params).must_equal({})
end
it "retrieves all files" do
2016-02-21 17:03:48 +00:00
dir = File.dirname(__FILE__)
full_files = Dir[File.join(dir, "**")]
files = full_files.map { |x| x.sub(dir + "/", "") }
2016-02-21 17:03:48 +00:00
_(res.tests.keys).must_equal files
_(res.tests.values[0]).must_equal File.read(full_files[0])
end
it "has no libraries" do
2016-02-21 17:03:48 +00:00
_(res.libraries).must_be_empty
end
end
end