Update stdlib and concat to 6.1.0 both
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / acceptance / file_line_spec.rb
1 require 'spec_helper_acceptance'
2
3 test_file = (os[:family] == 'windows') ? 'C:\Users\Administrator\file_line_test.txt' : '/tmp/file_line_test.txt'
4
5 describe 'file_line type' do
6   before(:each) do
7     pp_test_file = <<-MANIFEST
8       file { '#{test_file}':
9         ensure  => present,
10         content => 'a wild test file has appeared!',
11       }
12     MANIFEST
13     apply_manifest(pp_test_file)
14   end
15
16   context 'ensure line' do
17     let(:pp) do
18       <<-MANIFEST
19         file_line { 'test_ensure':
20           path => '#{test_file}',
21           line => 'test file uses attack!',
22         }
23       MANIFEST
24     end
25
26     it 'applies manifest, adds line' do
27       idempotent_apply(pp)
28       expect(file(test_file)).to be_file
29       expect(file(test_file).content).to match(%r{test file uses attack!})
30     end
31   end
32
33   context 'matches and replaces line' do
34     let(:pp) do
35       <<-MANIFEST
36         file_line { 'test_match':
37           path  => '#{test_file}',
38           line  => 'a tame test file has appeared!',
39           match => '^a wild',
40         }
41       MANIFEST
42     end
43
44     it 'applies manifest, replaces line' do
45       idempotent_apply(pp)
46       expect(file(test_file)).to be_file
47       expect(file(test_file).content).to match(%r{a tame test file has appeared!})
48     end
49   end
50
51   context 'remove line' do
52     context 'using match' do
53       let(:pp) do
54         <<-MANIFEST
55           file_line { 'test_absent_match':
56             ensure            => absent,
57             path              => '#{test_file}',
58             match             => '^a wild',
59             match_for_absence => true,
60           }
61         MANIFEST
62       end
63
64       it 'applies manifest, removes line' do
65         idempotent_apply(pp)
66         expect(file(test_file)).to be_file
67         expect(file(test_file).content).to be_empty
68       end
69     end
70
71     context 'using line' do
72       let(:pp) do
73         <<-MANIFEST
74           file_line { 'test_absent_line':
75             ensure => absent,
76             path   => '#{test_file}',
77             line   => 'a wild test file has appeared!',
78           }
79         MANIFEST
80       end
81
82       it 'applies manifest, removes line' do
83         idempotent_apply(pp)
84         expect(file(test_file)).to be_file
85         expect(file(test_file).content).to be_empty
86       end
87     end
88   end
89 end