0

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?

EagleDev
  • 1,754
  • 2
  • 11
  • 31
  • 1
    I'm voting to close this question as off-topic because this isn't a question. It's a mini-tutorial. – james.garriss Oct 01 '18 at 17:13
  • This is a deep-dive technical question to understand the best approach to minimize performance impact. Not sure why you think it is mini-tutorial. – EagleDev Oct 01 '18 at 17:14

1 Answers1

1

Why not its(:size) { should eq 0 }? That avoids the need to actually transfer the contents.

coderanger
  • 52,400
  • 4
  • 52
  • 75