2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/utils/find_files"
|
|
|
|
require "inspec/resources/command"
|
2015-12-04 09:44:52 +00:00
|
|
|
|
|
|
|
describe FindFiles do
|
2019-05-31 21:59:06 +00:00
|
|
|
let(:helper) do
|
2015-12-04 09:44:52 +00:00
|
|
|
class FindFilesTest
|
|
|
|
include FindFiles
|
|
|
|
def inspec
|
2019-01-28 04:32:54 +00:00
|
|
|
Inspec::Backend.create(Inspec::Config.mock)
|
2015-12-04 09:44:52 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
FindFilesTest.new
|
|
|
|
end
|
|
|
|
|
2018-05-03 13:53:20 +00:00
|
|
|
let(:inspec) { mock }
|
|
|
|
let(:result) { mock }
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "#find_files" do
|
|
|
|
it "returns an empty array when no files are found" do
|
2018-05-03 13:53:20 +00:00
|
|
|
helper.expects(:warn)
|
2019-09-30 22:31:55 +00:00
|
|
|
_(helper.find_files("/no/such/mock", type: "file", depth: 1)).must_equal([])
|
2018-05-03 13:53:20 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "#find_files_or_warn" do
|
2018-05-03 13:53:20 +00:00
|
|
|
before do
|
|
|
|
helper.expects(:inspec).returns(inspec)
|
|
|
|
result.stubs(:exit_status).returns(0)
|
2019-06-11 22:24:35 +00:00
|
|
|
result.stubs(:stdout).returns("mock")
|
2018-05-03 13:53:20 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "constructs the correct command" do
|
2018-05-03 13:53:20 +00:00
|
|
|
inspec.expects(:command).with("sh -c 'find /a/b/'").returns(result)
|
2019-06-11 22:24:35 +00:00
|
|
|
helper.find_files("/a/b/")
|
2018-05-03 13:53:20 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "builds the correct command when a single quote is used" do
|
2018-05-03 13:53:20 +00:00
|
|
|
inspec.expects(:command).with('sh -c "find /a/\'b/"').returns(result)
|
|
|
|
helper.find_files("/a/'b/")
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "constructs the correct command when a double quote is in the path" do
|
2018-05-03 13:53:20 +00:00
|
|
|
inspec.expects(:command).with("sh -c 'find /a/\"b/'").returns(result)
|
|
|
|
helper.find_files('/a/"b/')
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "builds the correct command when an escaped single quote is used" do
|
2018-05-03 13:53:20 +00:00
|
|
|
inspec.expects(:command).with('sh -c "find /a/\\\'b/"').returns(result)
|
|
|
|
helper.find_files('/a/\\\'b/')
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "builds the correct command when an escaped double quote is used" do
|
2018-05-03 13:53:20 +00:00
|
|
|
inspec.expects(:command).with("sh -c 'find /a/\\\"b/'").returns(result)
|
|
|
|
helper.find_files('/a/\"b/')
|
2015-12-04 09:44:52 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|