aboutsummaryrefslogtreecommitdiff
path: root/spec/acceptance/tests/destroy_spec.rb
blob: b00e03a95806f52a5a03d891c4a05a422bf58687 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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