Am trying to achieve condition that if the group exists in the server it should pass & if not exists it should skip and should not show as failure
describe.one do
describe 'testgroup' do
expect(bash("ipa group-show testgroup").exit_status).to eq 0
it { should exist }
end
describe 'testgroup' do
expect(bash("ipa group-show testgroup").exit_status).to_not eq 0
it { should_not exist }
end
end
After executing using:
# inspec exec testgroup_test.rb
It throws error output as:
undefined method 'bash' for Rspec::ExampleGroups (No method Error).
Please advice, how to achieve such condition testing in inspec.
To address the error message first before solving the environment specific tests, the correct way of testing a command's result is to use the command resource.
Let's consider a case when I want to pass the test when the command executes successfully, otherwise fail:
Now, let's say we have 2 environments - "dev" and "qa". We can use inputs to conditionally execute the tests.
For an example: We can define an input called
env. In "dev" environment it may not be necessary that this command will succeed. While in "qa" it should succeed.We can run the test by passing the value of
envas input, example: