From efced5a7a0e751a98cc5f5bdbecdfcbb18b0848d Mon Sep 17 00:00:00 2001 From: Josh Cooper Date: Mon, 9 Jul 2018 23:51:26 -0700 Subject: Convert query based test to rspec --- spec/acceptance/tests/query_all_spec.rb | 51 +++++++++++++++++---------------- 1 file changed, 27 insertions(+), 24 deletions(-) (limited to 'spec/acceptance') diff --git a/spec/acceptance/tests/query_all_spec.rb b/spec/acceptance/tests/query_all_spec.rb index cc92566..1653ab0 100644 --- a/spec/acceptance/tests/query_all_spec.rb +++ b/spec/acceptance/tests/query_all_spec.rb @@ -1,34 +1,37 @@ -test_name 'should query all hosts from hosts file' +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. - -content = '127.0.0.1 test1 test1.local +RSpec.context 'when querying all hosts from a host file' do + agents.each do |agent| + context "on #{agent}" do + let(:backup) { agent.tmpfile('host-query') } + let(:content) do + < /etc/hosts', stdin: content + end - step 'configure the system for testing (including file backups)' - on agent, "cp /etc/hosts #{backup}" - on agent, 'cat > /etc/hosts', stdin: content + after(:each) do + on agent, "cat #{backup} > /etc/hosts && rm -f #{backup}" + end - step 'query all host records using puppet' - on(agent, puppet_resource('host')) do - found = stdout.scan(%r{host \{ '([^']+)'}).flatten.sort - fail_test "the list of returned hosts was wrong: #{found.join(', ')}" unless - found == ['test1', 'test2', 'test3', 'test4'] + it 'returns 4 host records' do + on(agent, puppet_resource('host')) do |result| + found = result.stdout.scan(%r{host \{ '([^']+)'}).flatten.sort + fail_test "the list of returned hosts was wrong: #{found.join(', ')}" unless + found == ['test1', 'test2', 'test3', 'test4'] - count = stdout.scan(%r{ensure\s+=>\s+'present'}).length - fail_test "found #{count} records, wanted 4" unless count == 4 + count = result.stdout.scan(%r{ensure\s+=>\s+'present'}).length + fail_test "found #{count} records, wanted 4" unless count == 4 + end + end + end end - - step 'clean up the system afterwards' - on agent, "cat #{backup} > /etc/hosts && rm -f #{backup}" end -- cgit v1.2.3