2015-09-21 07:51:00 +00:00
|
|
|
# encoding: utf-8
|
2015-10-06 16:55:44 +00:00
|
|
|
# author: Christoph Hartmann
|
|
|
|
# author: Dominik Richter
|
2015-09-21 07:51:00 +00:00
|
|
|
|
|
|
|
require 'helper'
|
2015-10-26 03:04:18 +00:00
|
|
|
require 'inspec/resource'
|
2015-09-21 07:51:00 +00:00
|
|
|
|
2015-10-26 03:04:18 +00:00
|
|
|
describe 'Inspec::Resources::JSON' do
|
2015-10-27 14:37:01 +00:00
|
|
|
describe 'when loading a valid json' do
|
|
|
|
let (:resource) { load_resource('json', 'policyfile.lock.json') }
|
|
|
|
|
|
|
|
it 'gets params as a hashmap' do
|
|
|
|
_(resource.params).must_be_kind_of Hash
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'retrieves nil if a param is missing' do
|
|
|
|
_(resource.params['missing']).must_be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'retrieves params by name' do
|
|
|
|
_(resource.send('name')).must_equal 'demo'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'retrieves an array by name' do
|
|
|
|
_(resource.send('run_list')).must_equal %w{a b}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'doesnt resolve dot-notation names' do
|
|
|
|
_(resource.send('x.y.z')).must_be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'doesnt resolve symbol-notation names' do
|
|
|
|
_(resource.send(:'x.y.z')).must_be_nil
|
|
|
|
end
|
2015-09-21 07:51:00 +00:00
|
|
|
end
|
2016-12-15 13:00:56 +00:00
|
|
|
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
|
2015-09-21 07:51:00 +00:00
|
|
|
end
|