diff options
author | Josh Cooper <josh@puppet.com> | 2018-07-09 17:15:39 -0700 |
---|---|---|
committer | Josh Cooper <josh@puppet.com> | 2018-07-09 19:44:47 -0700 |
commit | 2ac89832b7e065df4490d81b3080b2b570a172ad (patch) | |
tree | f9f4f28f30a77c958e8e850acf954336b2301dc9 /spec/acceptance/tests/should_query_all.rb | |
parent | 1c6ae8bfde5175c5d3512f5acb5352fda94a4801 (diff) | |
download | puppet-hosts_core-2ac89832b7e065df4490d81b3080b2b570a172ad.tar.gz puppet-hosts_core-2ac89832b7e065df4490d81b3080b2b570a172ad.tar.bz2 |
Initial host import from puppet#ee7cf4d28077be7d1bdbbe934ea012d41d33deff
Diffstat (limited to 'spec/acceptance/tests/should_query_all.rb')
-rw-r--r-- | spec/acceptance/tests/should_query_all.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/spec/acceptance/tests/should_query_all.rb b/spec/acceptance/tests/should_query_all.rb new file mode 100644 index 0000000..e60756d --- /dev/null +++ b/spec/acceptance/tests/should_query_all.rb @@ -0,0 +1,34 @@ +test_name "should query all hosts from hosts file" + +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 = %q{127.0.0.1 test1 test1.local +127.0.0.2 test2 test2.local +127.0.0.3 test3 test3.local +127.0.0.4 test4 test4.local +} + +agents.each do |agent| + backup = agent.tmpfile('host-query-all') + + step "configure the system for testing (including file backups)" + on agent, "cp /etc/hosts #{backup}" + on agent, "cat > /etc/hosts", :stdin => content + + step "query all host records using puppet" + on(agent, puppet_resource('host')) do + found = stdout.scan(/host \{ '([^']+)'/).flatten.sort + fail_test "the list of returned hosts was wrong: #{found.join(', ')}" unless + found == %w{test1 test2 test3 test4} + + count = stdout.scan(/ensure\s+=>\s+'present'/).length + fail_test "found #{count} records, wanted 4" unless count == 4 + end + + step "clean up the system afterwards" + on agent, "cat #{backup} > /etc/hosts && rm -f #{backup}" +end |