diff options
author | Josh Cooper <josh@puppet.com> | 2018-07-09 23:45:32 -0700 |
---|---|---|
committer | Josh Cooper <josh@puppet.com> | 2018-07-10 11:03:14 -0700 |
commit | 6a71be247473f8561d3e2dc655fba7d3bb686381 (patch) | |
tree | 1685e0983aa45dac33e6b3fae5ea2c52d4ebf520 | |
parent | 4272dcd3fb87886e9a8c5e1f03fc8d2c38bc60b6 (diff) | |
download | puppet-hosts_core-6a71be247473f8561d3e2dc655fba7d3bb686381.tar.gz puppet-hosts_core-6a71be247473f8561d3e2dc655fba7d3bb686381.tar.bz2 |
Convert modify based tests to rspec
Consolidate tests relating to modifying host entries.
-rw-r--r-- | spec/acceptance/tests/modify_alias_spec.rb | 27 | ||||
-rw-r--r-- | spec/acceptance/tests/modify_ip_spec.rb | 27 | ||||
-rw-r--r-- | spec/acceptance/tests/modify_spec.rb | 35 |
3 files changed, 35 insertions, 54 deletions
diff --git a/spec/acceptance/tests/modify_alias_spec.rb b/spec/acceptance/tests/modify_alias_spec.rb deleted file mode 100644 index f2171f0..0000000 --- a/spec/acceptance/tests/modify_alias_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -test_name 'should be able to modify a host alias' - -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-modify-alias') - - step 'set up files for the test' - on agent, "printf '127.0.0.8 test alias\n' > #{file}" - - step 'modify the resource' - on(agent, puppet_resource('host', 'test', "target=#{file}", - 'ensure=present', 'ip=127.0.0.8', 'host_aliases=banzai')) - - step 'verify that the content was updated' - on(agent, "cat #{file}; rm -f #{file}") do - fail_test 'the alias was not updated' unless - stdout =~ %r{^127\.0\.0\.8[[:space:]]+test[[:space:]]+banzai[[:space:]]*$} - end - - step 'clean up after the test' - on agent, "rm -f #{file}" -end diff --git a/spec/acceptance/tests/modify_ip_spec.rb b/spec/acceptance/tests/modify_ip_spec.rb deleted file mode 100644 index 22019b7..0000000 --- a/spec/acceptance/tests/modify_ip_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -test_name 'should be able to modify a host address' - -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-modify-ip') - - step 'set up files for the test' - on agent, "printf '127.0.0.9 test alias\n' > #{file}" - - step 'modify the resource' - on(agent, puppet_resource('host', 'test', "target=#{file}", - 'ensure=present', 'ip=127.0.0.10', 'host_aliases=alias')) - - step 'verify that the content was updated' - on(agent, "cat #{file}; rm -f #{file}") do - fail_test 'the address was not updated' unless - stdout =~ %r{^127\.0\.0\.10[[:space:]]+test[[:space:]]+alias[[:space:]]*$} - end - - step 'clean up after the test' - on agent, "rm -f #{file}" -end diff --git a/spec/acceptance/tests/modify_spec.rb b/spec/acceptance/tests/modify_spec.rb new file mode 100644 index 0000000..6498ee0 --- /dev/null +++ b/spec/acceptance/tests/modify_spec.rb @@ -0,0 +1,35 @@ +require 'spec_helper_acceptance' + +RSpec.context 'when modifying host files' do + agents.each do |agent| + context "on #{agent}" do + let(:target) { agent.tmpfile('host-modify') } + + after(:each) do + on(agent, "test #{target} && rm -f #{target}") + end + + it 'modifies a host address' do + on agent, "printf '127.0.0.9 test alias\n' > #{target}" + on(agent, puppet_resource('host', 'test', "target=#{target}", + 'ensure=present', 'ip=127.0.0.10', 'host_aliases=alias')) + + on(agent, "cat #{target}") do |result| + fail_test 'the address was not updated' unless + result.stdout =~ %r{^127\.0\.0\.10[[:space:]]+test[[:space:]]+alias[[:space:]]*$} + end + end + + it 'modifies a host alias' do + on agent, "printf '127.0.0.8 test alias\n' > #{target}" + on(agent, puppet_resource('host', 'test', "target=#{target}", + 'ensure=present', 'ip=127.0.0.8', 'host_aliases=banzai')) + + on(agent, "cat #{target}") do |result| + fail_test 'the alias was not updated' unless + result.stdout =~ %r{^127\.0\.0\.8[[:space:]]+test[[:space:]]+banzai[[:space:]]*$} + end + end + end + end +end |