spec/facts_spec.rb in facterdb-1.21.0 vs spec/facts_spec.rb in facterdb-1.22.0

- old
+ new

@@ -12,11 +12,11 @@ end end RSpec::Matchers.define :be_valid_json do match do |actual| - content = File.open(actual, 'rb') { |file| file.read } + content = File.binread(actual) valid = false begin obj = JSON.parse(content) valid = true rescue JSON::ParserError => e @@ -39,21 +39,21 @@ "expected that fact file #{filepath} with facter version #{actual} had a facter version that matched #{expected_facter_version}" end end describe 'Default Facts' do - before(:each) do + before do ENV['FACTERDB_SKIP_DEFAULTDB'] = nil FacterDB.instance_variable_set(:@database, nil) end describe 'fact files' do - it 'should not contain duplicate fact sets' do + it 'does not contain duplicate fact sets' do # Gather all of the default files and hash the content file_hashes = {} FacterDB.default_fact_files.each do |filepath| - file_hash = Digest::SHA256.hexdigest( File.open(filepath, 'rb') { |file| file.read } ) + file_hash = Digest::SHA256.hexdigest(File.binread(filepath)) file_hashes[file_hash] ||= [] file_hashes[file_hash] << filepath end file_hashes.keys.each do |file_hash| @@ -65,11 +65,11 @@ project_dir = Pathname.new(__dir__).parent FacterDB.default_fact_files.each do |filepath| relative_path = Pathname.new(filepath).relative_path_from(project_dir).to_s describe relative_path do subject(:content) do - JSON.parse(File.open(filepath, 'rb') { |file| file.read }) + JSON.parse(File.binread(filepath)) end it 'contains a valid JSON document' do expect(filepath).to be_valid_json end @@ -86,36 +86,42 @@ expect(content['networking']['hostname']).to eq('foo') expect(content['networking']['domain']).to eq('example.com') expect(content['networking']['fqdn']).to eq('foo.example.com') end end + it 'contains the legacy ipaddress fact' do expect(content['ipaddress']).to not_be_nil.and not_be_empty end + it 'contains no facts from puppetlabs/stdlib' do expect(content['root_home']).to be_nil expect(content['service_provider']).to be_nil expect(content['puppet_vardir']).to be_nil expect(content['puppet_environmentpath']).to be_nil expect(content['puppet_server']).to be_nil expect(content['pe_version']).to be_nil expect(content['package_provider']).to be_nil end + it 'contains no facts from puppet/systemd' do expect(content['systemd']).to be_nil expect(content['systemd_version']).to be_nil expect(content['systemd_internal_services']).to be_nil end + it 'contains a legacy hostname, domain and fqdn fact' do expect(content['hostname']).to eq('foo') expect(content['fqdn']).to eq('foo.example.com') expect(content['domain']).to eq('example.com') end + it 'contains the legacy osfamily fact' do - expect(content['osfamily']).to_not be_nil + expect(content['osfamily']).not_to be_nil end + it 'contains the legacy operatingsystem fact' do - expect(content['operatingsystem']).to_not be_nil + expect(content['operatingsystem']).not_to be_nil end end end end