aboutsummaryrefslogtreecommitdiff
path: root/spec/acceptance
diff options
context:
space:
mode:
authorJosh Cooper <josh@puppet.com>2018-07-09 23:37:16 -0700
committerJosh Cooper <josh@puppet.com>2018-07-10 11:03:14 -0700
commit4272dcd3fb87886e9a8c5e1f03fc8d2c38bc60b6 (patch)
tree65730b2f05c72e17a9c71a49262ef6b744121209 /spec/acceptance
parenta080a3d68662c0d19ece9e0b7019d8820ed79842 (diff)
downloadpuppet-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')
-rw-r--r--spec/acceptance/tests/destroy_spec.rb49
-rw-r--r--spec/acceptance/tests/pup_2289_should_not_destroy_data_when_malformed_spec.rb31
2 files changed, 29 insertions, 51 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
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