2015-12-04 09:44:52 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
# author: Stephan Renatus
|
|
|
|
|
|
|
|
require 'helper'
|
|
|
|
|
|
|
|
describe FindFiles do
|
2018-05-03 13:53:20 +00:00
|
|
|
let (:helper) do
|
2015-12-04 09:44:52 +00:00
|
|
|
class FindFilesTest
|
|
|
|
include FindFiles
|
|
|
|
def inspec
|
|
|
|
Inspec::Backend.create(backend: :mock)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
FindFilesTest.new
|
|
|
|
end
|
|
|
|
|
2018-05-03 13:53:20 +00:00
|
|
|
let(:inspec) { mock }
|
|
|
|
let(:result) { mock }
|
|
|
|
|
2015-12-04 09:44:52 +00:00
|
|
|
describe '#find_files' do
|
2018-05-03 13:53:20 +00:00
|
|
|
it 'returns an empty array when no files are found' do
|
|
|
|
helper.expects(:warn)
|
|
|
|
helper.find_files('/no/such/mock', type: 'file', depth: 1).must_equal([])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#find_files_or_warn' do
|
|
|
|
before do
|
|
|
|
helper.expects(:inspec).returns(inspec)
|
|
|
|
result.stubs(:exit_status).returns(0)
|
|
|
|
result.stubs(:stdout).returns('mock')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'constructs the correct command' do
|
|
|
|
inspec.expects(:command).with("sh -c 'find /a/b/'").returns(result)
|
|
|
|
helper.find_files('/a/b/')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'builds the correct command when a single quote is used' do
|
|
|
|
inspec.expects(:command).with('sh -c "find /a/\'b/"').returns(result)
|
|
|
|
helper.find_files("/a/'b/")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'constructs the correct command when a double quote is in the path' do
|
|
|
|
inspec.expects(:command).with("sh -c 'find /a/\"b/'").returns(result)
|
|
|
|
helper.find_files('/a/"b/')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'builds the correct command when an escaped single quote is used' do
|
|
|
|
inspec.expects(:command).with('sh -c "find /a/\\\'b/"').returns(result)
|
|
|
|
helper.find_files('/a/\\\'b/')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'builds the correct command when an escaped double quote is used' do
|
|
|
|
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
|