Is it possible to use one resource inside other resource in Chef InSpec?
Example:
describe command('su srijava') do
describe file ('/app/java/latest') do
it{ should exist }
end
end
It throws an error like:
`method_missing': undefined method `file' for RSpec::ExampleGroups::CommandSuSriava:Class (NoMethodError)
Actually what I want to do is that I need to run a utility that is installed in other user and I have to check the output returned from that session and verify it. Example :
java -version
runs only in that user and not as root).su srijava
, then I do not get the output returned back to
the root session and the test failssu srijava
then my utility will throw an error that
the user is not SriJavaCode with su
:
describe command('su srijava ; cd /app/java; ./java --version') do
its('stdout') { should match('1.7') }
end
Code without su
:
describe command('cd /app/java; ./java --version') do
its('stdout') { should match('1.7') }
end
How can I do that?
As Noah pointed out, nested describe blocks are not supported yet. I also think you do not need those.
result = command('runcommand').stdout
filename = result + '/path'
describe file (filename) do
it{ should exist }
end
On the other hand, you could use the bash
resource to run multiple commands. command
uses the default shell of the user, bash
enforces it. This enables you to:
describe bash('su srijava ; cd /app/java; ./java --version') do
its('stdout') { should match('1.7') }
end