aboutsummaryrefslogtreecommitdiff
path: root/spec/acceptance/tests
diff options
context:
space:
mode:
authorJosh Cooper <josh@puppet.com>2018-07-13 09:38:02 -0700
committerGitHub <noreply@github.com>2018-07-13 09:38:02 -0700
commitbd20d920a19e9b011dfd027a802985cea46ae04f (patch)
treef882cd2b7c31ae08cd242882b0f7f1d1ed89cbbd /spec/acceptance/tests
parent9d96ddecea6367abee1aa77859848b0c158fca80 (diff)
parentc957642d70f4b778736a9b49cf1ef9702e42c4f1 (diff)
downloadpuppet-hosts_core-bd20d920a19e9b011dfd027a802985cea46ae04f.tar.gz
puppet-hosts_core-bd20d920a19e9b011dfd027a802985cea46ae04f.tar.bz2
Merge pull request #1 from puppetlabs/extraction
Initial host module extraction
Diffstat (limited to 'spec/acceptance/tests')
-rw-r--r--spec/acceptance/tests/create_spec.rb56
-rw-r--r--spec/acceptance/tests/destroy_spec.rb36
-rw-r--r--spec/acceptance/tests/modify_spec.rb35
-rw-r--r--spec/acceptance/tests/query_all_spec.rb37
4 files changed, 164 insertions, 0 deletions
diff --git a/spec/acceptance/tests/create_spec.rb b/spec/acceptance/tests/create_spec.rb
new file mode 100644
index 0000000..40267fd
--- /dev/null
+++ b/spec/acceptance/tests/create_spec.rb
@@ -0,0 +1,56 @@
+require 'spec_helper_acceptance'
+
+RSpec.context 'when creating host files' do
+ agents.each do |agent|
+ context "on #{agent}" do
+ let(:target) { agent.tmpfile('host-create') }
+
+ after(:each) do
+ on(agent, "test #{target} && rm -f #{target}")
+ end
+
+ 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
+
+ it 'creates host aliases' do
+ on(agent, puppet_resource('host', 'test', 'ensure=present',
+ 'ip=127.0.0.7', "target=#{target}", 'host_aliases=alias'))
+
+ 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/destroy_spec.rb b/spec/acceptance/tests/destroy_spec.rb
new file mode 100644
index 0000000..b00e03a
--- /dev/null
+++ b/spec/acceptance/tests/destroy_spec.rb
@@ -0,0 +1,36 @@
+require 'spec_helper_acceptance'
+
+RSpec.context 'when managing host files' do
+ agents.each do |agent|
+ context "on #{agent}" do
+ let(:target) { agent.tmpfile('host-destroy') }
+
+ after(:each) do
+ on(agent, "test #{target} && rm -f #{target}")
+ end
+
+ it 'deletes a host record' do
+ line = '127.0.0.7 test1'
+
+ 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
+
+ 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'))
+
+ 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/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
diff --git a/spec/acceptance/tests/query_all_spec.rb b/spec/acceptance/tests/query_all_spec.rb
new file mode 100644
index 0000000..1653ab0
--- /dev/null
+++ b/spec/acceptance/tests/query_all_spec.rb
@@ -0,0 +1,37 @@
+require 'spec_helper_acceptance'
+
+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
+ <<END
+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
+END
+ end
+
+ before(:each) do
+ on(agent, "cp /etc/hosts #{backup}")
+ on agent, 'cat > /etc/hosts', stdin: content
+ end
+
+ after(:each) do
+ on agent, "cat #{backup} > /etc/hosts && rm -f #{backup}"
+ end
+
+ 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 = result.stdout.scan(%r{ensure\s+=>\s+'present'}).length
+ fail_test "found #{count} records, wanted 4" unless count == 4
+ end
+ end
+ end
+ end
+end