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 :
- I installed java as srijava user
- Now in Inspec I wrote the command to test the Java version (Assume that the
java -version
runs only in that user and not as root). - if I use
su srijava
, then I do not get the output returned back to the root session and the test fails - If I run without
su srijava
then my utility will throw an error that the user is not SriJava
Code 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?