diff options
author | Josh Cooper <josh@puppet.com> | 2018-07-09 23:37:16 -0700 |
---|---|---|
committer | Josh Cooper <josh@puppet.com> | 2018-07-10 11:03:14 -0700 |
commit | 4272dcd3fb87886e9a8c5e1f03fc8d2c38bc60b6 (patch) | |
tree | 65730b2f05c72e17a9c71a49262ef6b744121209 /spec/acceptance/tests/destroy_spec.rb | |
parent | a080a3d68662c0d19ece9e0b7019d8820ed79842 (diff) | |
download | puppet-hosts_core-4272dcd3fb87886e9a8c5e1f03fc8d2c38bc60b6.tar.gz puppet-hosts_core-4272dcd3fb87886e9a8c5e1f03fc8d2c38bc60b6.tar.bz2 |
Convert destroy based tests to rspec
Consolidate tests relating to destroying host entries.
Diffstat (limited to 'spec/acceptance/tests/destroy_spec.rb')
-rw-r--r-- | spec/acceptance/tests/destroy_spec.rb | 49 |
1 files changed, 29 insertions, 20 deletions
diff --git a/spec/acceptance/tests/destroy_spec.rb b/spec/acceptance/tests/destroy_spec.rb index f55c24b..b00e03a 100644 --- a/spec/acceptance/tests/destroy_spec.rb +++ b/spec/acceptance/tests/destroy_spec.rb @@ -1,27 +1,36 @@ -test_name 'should be able to remove a host record' +require 'spec_helper_acceptance' -tag 'audit:low', - 'audit:refactor', # Use block style `test_name` - 'audit:acceptance' # Could be done at the integration (or unit) layer though -# actual changing of resources could irreparably damage a -# host running this, or require special permissions. +RSpec.context 'when managing host files' do + agents.each do |agent| + context "on #{agent}" do + let(:target) { agent.tmpfile('host-destroy') } -agents.each do |agent| - file = agent.tmpfile('host-destroy') - line = '127.0.0.7 test1' + after(:each) do + on(agent, "test #{target} && rm -f #{target}") + end - step 'set up files for the test' - on agent, "printf '#{line}\n' > #{file}" + it 'deletes a host record' do + line = '127.0.0.7 test1' - step 'delete the resource from the file' - on(agent, puppet_resource('host', 'test1', "target=#{file}", - 'ensure=absent', 'ip=127.0.0.7')) + on agent, "printf '#{line}\n' > #{target}" + on(agent, puppet_resource('host', 'test1', "target=#{target}", + 'ensure=absent', 'ip=127.0.0.7')) + on(agent, "cat #{target}") do |result| + fail_test 'the content was still present' if result.stdout.include? line + end + end - step 'verify that the content was removed' - on(agent, "cat #{file}; rm -f #{file}") do - fail_test 'the content was still present' if stdout.include? line - end + it 'does not purge valid host records if file contains malformed content' do + on(agent, "printf '127.0.0.2 existing alias\n' > #{target}") + on(agent, "printf '==\n' >> #{target}") + + on(agent, puppet_resource('host', 'test', "target=#{target}", + 'ensure=present', 'ip=127.0.0.3', 'host_aliases=foo')) - step 'clean up after the test' - on agent, "rm -f #{file}" + on(agent, "cat #{target}") do |result| + fail_test 'existing host data was deleted' unless result.stdout.include? 'existing' + end + end + end + end end |