From a080a3d68662c0d19ece9e0b7019d8820ed79842 Mon Sep 17 00:00:00 2001 From: Josh Cooper Date: Mon, 9 Jul 2018 23:26:12 -0700 Subject: Convert create based tests to rspec Consolidate tests relating to creating host entries. --- spec/acceptance/tests/create_aliases_spec.rb | 24 -------- spec/acceptance/tests/create_spec.rb | 65 ++++++++++++++++------ spec/acceptance/tests/not_create_existing_spec.rb | 24 -------- ...icket_4131_should_not_create_without_ip_spec.rb | 31 ----------- 4 files changed, 49 insertions(+), 95 deletions(-) delete mode 100644 spec/acceptance/tests/create_aliases_spec.rb delete mode 100644 spec/acceptance/tests/not_create_existing_spec.rb delete mode 100644 spec/acceptance/tests/ticket_4131_should_not_create_without_ip_spec.rb (limited to 'spec/acceptance') diff --git a/spec/acceptance/tests/create_aliases_spec.rb b/spec/acceptance/tests/create_aliases_spec.rb deleted file mode 100644 index a76263a..0000000 --- a/spec/acceptance/tests/create_aliases_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -test_name 'host should create aliases' - -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| - target = agent.tmpfile('host-create-aliases') - - step 'clean up the system for testing' - on agent, "rm -f #{target}" - - step 'create the record' - on(agent, puppet_resource('host', 'test', 'ensure=present', - 'ip=127.0.0.7', "target=#{target}", 'host_aliases=alias')) - - step 'verify that the aliases were added' - on(agent, "cat #{target} ; rm -f #{target}") do - fail_test 'alias was missing' unless - stdout =~ %r{^127\.0\.0\.7[[:space:]]+test[[:space:]]alias} - end -end diff --git a/spec/acceptance/tests/create_spec.rb b/spec/acceptance/tests/create_spec.rb index 3ce34e8..40267fd 100644 --- a/spec/acceptance/tests/create_spec.rb +++ b/spec/acceptance/tests/create_spec.rb @@ -1,23 +1,56 @@ -test_name 'host should create' +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 creating host files' do + agents.each do |agent| + context "on #{agent}" do + let(:target) { agent.tmpfile('host-create') } -agents.each do |agent| - target = agent.tmpfile('host-create') + after(:each) do + on(agent, "test #{target} && rm -f #{target}") + end - step 'clean up for the test' - on agent, "rm -f #{target}" + it 'creates a host record' do + on(agent, puppet_resource('host', 'test', 'ensure=present', + 'ip=127.0.0.1', "target=#{target}")) + on(agent, "cat #{target}") do |result| + fail_test 'record was not present' if result.stdout !~ %r{^127\.0\.0\.1[[:space:]]+test} + end + end - step 'create the host record' - on(agent, puppet_resource('host', 'test', 'ensure=present', - 'ip=127.0.0.1', "target=#{target}")) + it 'creates host aliases' do + on(agent, puppet_resource('host', 'test', 'ensure=present', + 'ip=127.0.0.7', "target=#{target}", 'host_aliases=alias')) - step 'verify that the record was created' - on(agent, "cat #{target} ; rm -f #{target}") do - fail_test 'record was not present' unless stdout =~ %r{^127\.0\.0\.1[[:space:]]+test} + on(agent, "cat #{target}") do |result| + fail_test 'alias was missing' unless + result.stdout =~ %r{^127\.0\.0\.7[[:space:]]+test[[:space:]]alias} + end + end + + it "doesn't create the entry if it already exists" do + on agent, "printf '127.0.0.2 test alias\n' > #{target}" + + step 'tell puppet to ensure the host exists' + on(agent, puppet_resource('host', 'test', "target=#{target}", + 'ensure=present', 'ip=127.0.0.2', 'host_aliases=alias')) do |result| + fail_test 'darn, we created the host record' if + result.stdout.include? '/Host[test1]/ensure: created' + end + end + + it 'requires an ipaddress' do + skip_test if agent['locale'] == 'ja' + + on(agent, puppet_resource('host', 'test', "target=#{target}", + 'host_aliases=alias')) do |result| + fail_test "puppet didn't complain about the missing attribute" unless + result.stderr.include? 'ip is a required attribute for hosts' + end + + on(agent, "cat #{target}") do |result| + fail_test 'the host was apparently added to the file' if result.stdout.include? 'test' + end + end + end end end diff --git a/spec/acceptance/tests/not_create_existing_spec.rb b/spec/acceptance/tests/not_create_existing_spec.rb deleted file mode 100644 index 31686bc..0000000 --- a/spec/acceptance/tests/not_create_existing_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -test_name 'should not create host if it exists' - -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-create-existing') - - step 'set up the system for the test' - on agent, "printf '127.0.0.2 test alias\n' > #{file}" - - step 'tell puppet to ensure the host exists' - on(agent, puppet_resource('host', 'test', "target=#{file}", - 'ensure=present', 'ip=127.0.0.2', 'host_aliases=alias')) do - fail_test 'darn, we created the host record' if - stdout.include? '/Host[test1]/ensure: created' - end - - step 'clean up after we created things' - on agent, "rm -f #{file}" -end diff --git a/spec/acceptance/tests/ticket_4131_should_not_create_without_ip_spec.rb b/spec/acceptance/tests/ticket_4131_should_not_create_without_ip_spec.rb deleted file mode 100644 index a26faee..0000000 --- a/spec/acceptance/tests/ticket_4131_should_not_create_without_ip_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -test_name '#4131: should not create host without IP attribute' - -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('4131-require-ip') - - step 'configure the target system for the test' - on agent, "rm -rf #{file} ; touch #{file}" - - step 'try to create the host, which should fail' - # REVISIT: This step should properly need to handle the non-zero exit code, - # and #5668 has been filed to record that. When it is fixed this test will - # start to fail, and this comment will tell you why. --daniel 2010-12-24 - on(agent, puppet_resource('host', 'test', "target=#{file}", - 'host_aliases=alias')) do - unless agent['locale'] == 'ja' - fail_test "puppet didn't complain about the missing attribute" unless - stderr.include? 'ip is a required attribute for hosts' - end - end - - step 'verify that the host was not added to the file' - on(agent, "cat #{file} ; rm -f #{file}") do - fail_test 'the host was apparently added to the file' if stdout.include? 'test' - end -end -- cgit v1.2.3