Inspec test multiple entities
Asked Answered
E

2

5

I am writing inspec tests for my chef recipes where there are 5 files which needs to tested for their mode. All of them should have the same mode 0755.

describe file('/dev') do
 its('mode') { should cmp '00755' }
end

This is the sytax I am using. But this tests only 1 file(/dev). Is is possible to test multiple files using a single test block?

Episcopalian answered 9/5, 2017 at 6:11 Comment(0)
V
8

you can use ruby code to test multiple entities

dirs = ["/lib","/bin","/dev"]
dirs.each do |path|
    describe file(path) do
        its('type') { should eq :directory }
        it { should be_directory }
    end
end
Vassalage answered 14/3, 2019 at 16:3 Comment(0)
H
1

It isn't exactly 'single test block', but you could iterate over file list:

%w(/dev /tmp).each do |path|
  describe file(path)
    its(:mode) { should cmp '00755' }
  end
end
Horsemint answered 9/5, 2017 at 6:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.