I'm quite new to InSpec and would like to learn from your experience.
There are some approaches to verifying if a file or its property is empty.
Approach 1 - using file resource to and read its content. Use eq matcher to check the output ''
describe file('file_path') do
its(:contents) { should eq ' ' }
end
Approach 2 - - using file resource to and read its content, but check null
describe file('file_path') do
its(:contents) { should be nil }
end
Approach 3 (uncommon) - use command resource to execute the cat command
describe command('cat /etc/file_path') do
its(:stdout) { should eq ' ' }
end
Approach 4 - use should be_empty
describe file('file_path') do
its(:contents) { should be_empty }
end
If there is any more approach, please feel free to suggest.
Is there a performance impact if using uncommon approach?