From 4272dcd3fb87886e9a8c5e1f03fc8d2c38bc60b6 Mon Sep 17 00:00:00 2001 From: Josh Cooper Date: Mon, 9 Jul 2018 23:37:16 -0700 Subject: Convert destroy based tests to rspec Consolidate tests relating to destroying host entries. --- spec/acceptance/tests/destroy_spec.rb | 49 +++++++++++++--------- ..._should_not_destroy_data_when_malformed_spec.rb | 31 -------------- 2 files changed, 29 insertions(+), 51 deletions(-) delete mode 100644 spec/acceptance/tests/pup_2289_should_not_destroy_data_when_malformed_spec.rb 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 diff --git a/spec/acceptance/tests/pup_2289_should_not_destroy_data_when_malformed_spec.rb b/spec/acceptance/tests/pup_2289_should_not_destroy_data_when_malformed_spec.rb deleted file mode 100644 index 95cf6ed..0000000 --- a/spec/acceptance/tests/pup_2289_should_not_destroy_data_when_malformed_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -test_name 'should not delete data when existing content is malformed' - -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. - -agents.each do |agent| - file = agent.tmpfile('host-not-delete-data') - - teardown do - on(agent, "rm -f #{file}", acceptable_exit_codes: (0..255)) - end - - step '(setup) populate test file with host information' - on(agent, "printf '127.0.0.2 existing alias\n' > #{file}") - - step '(setup) populate test file with a malformed line' - on(agent, "printf '==\n' >> #{file}") - - step 'tell puppet to add another host entry' - on(agent, puppet_resource('host', 'test', "target=#{file}", - 'ensure=present', 'ip=127.0.0.3', 'host_aliases=foo')) - - step 'verify that the initial host entry was not deleted' - on(agent, "cat #{file}") do |res| - fail_test 'existing host data was deleted' unless - res.stdout.include? 'existing' - end -end -- cgit v1.2.3