Fix variable name. Add test.

Signed-off-by: Makoto Nozaki <makoto.nozaki@twosigma.com>
This commit is contained in:
Makoto Nozaki 2016-12-15 08:00:56 -05:00
parent 034130cc96
commit 42cffeea61
3 changed files with 10 additions and 2 deletions

View file

@ -44,13 +44,13 @@ module Inspec::Resources
# check if file is available # check if file is available
if !@file.file? if !@file.file?
skip_resource "Can't find file \"#{@conf_path}\"" skip_resource "Can't find file \"#{@path}\""
return @params = {} return @params = {}
end end
# check if file is readable # check if file is readable
if @file_content.empty? && @file.size > 0 if @file_content.empty? && @file.size > 0
skip_resource "Can't read file \"#{@conf_path}\"" skip_resource "Can't read file \"#{@path}\""
return @params = {} return @params = {}
end end
end end

View file

@ -114,6 +114,7 @@ class MockLoader
'kitchen.yml' => mockfile.call('kitchen.yml'), 'kitchen.yml' => mockfile.call('kitchen.yml'),
'example.csv' => mockfile.call('example.csv'), 'example.csv' => mockfile.call('example.csv'),
'policyfile.lock.json' => mockfile.call('policyfile.lock.json'), 'policyfile.lock.json' => mockfile.call('policyfile.lock.json'),
'nonexistent.json' => mockfile.call('nonexistent.json'),
'/sys/class/net/br0/bridge' => mockdir.call(true), '/sys/class/net/br0/bridge' => mockdir.call(true),
'rootwrap.conf' => mockfile.call('rootwrap.conf'), 'rootwrap.conf' => mockfile.call('rootwrap.conf'),
'/etc/apache2/apache2.conf' => mockfile.call('apache2.conf'), '/etc/apache2/apache2.conf' => mockfile.call('apache2.conf'),

View file

@ -33,4 +33,11 @@ describe 'Inspec::Resources::JSON' do
_(resource.send(:'x.y.z')).must_be_nil _(resource.send(:'x.y.z')).must_be_nil
end end
end end
describe 'when loading a nonexistent file' do
let (:resource) { load_resource('json', 'nonexistent.json') }
it 'produces an error' do
_(resource.resource_skipped).must_equal 'Can\'t find file "nonexistent.json"'
end
end
end end