Skip to content

Commit

Permalink
(voxpupuli#77) Add duplicate factset file test
Browse files Browse the repository at this point in the history
Previously there were many default fact files which are just duplicates.  This
commit adds a test will performs a simple file hash comparison of all default
factset files and fails and displays any duplicate factsets.

This test is initially skipped while the duplicate files are removed in later
commits.
  • Loading branch information
glennsarti committed Mar 26, 2018
1 parent 4287a8c commit 346ccf0
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions spec/facts_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'spec_helper'
require 'digest'

RSpec::Matchers.define :have_a_unique_hash do |expected|
match do |actual|
actual.count == 1
end

failure_message do |actual|
"expected that fact files #{actual.join(', ')} would be unique"
end
end

describe 'Default Facts' do
before(:each) do
ENV['FACTERDB_SKIP_DEFAULTDB'] = nil
FacterDB.instance_variable_set(:@database, nil)
end

describe 'fact files' do
xit 'should 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_hashes[file_hash] ||= []
file_hashes[file_hash] << filepath
end

file_hashes.keys.each do |file_hash|
expect(file_hashes[file_hash]).to have_a_unique_hash
end
end
end
end

0 comments on commit 346ccf0

Please sign in to comment.