Update stdlib and concat to 6.1.0 both
[mirror/dsa-puppet.git] / 3rdparty / modules / concat / spec / acceptance / fragment_source_spec.rb
1 require 'spec_helper_acceptance'
2
3 case os[:family]
4 when 'aix'
5   username = 'root'
6   groupname = 'system'
7 when 'darwin'
8   username = 'root'
9   groupname = 'wheel'
10 when 'windows'
11   username = 'Administrator'
12   groupname = 'Administrators'
13 else
14   username = 'root'
15   groupname = 'root'
16 end
17
18 describe 'concat::fragment source' do
19   before(:all) do
20     @basedir = setup_test_directory
21   end
22
23   describe 'when run should read file fragments from local system' do
24     let(:pp) do
25       <<-MANIFEST
26         file { '#{@basedir}/file1':
27           content => "file1 contents\n"
28         }
29         file { '#{@basedir}/file2':
30           content => "file2 contents\n"
31         }
32         concat { '#{@basedir}/foo': }
33
34         concat::fragment { '1':
35           target  => '#{@basedir}/foo',
36           source  => '#{@basedir}/file1',
37           require => File['#{@basedir}/file1'],
38         }
39         concat::fragment { '2':
40           target  => '#{@basedir}/foo',
41           content => 'string1 contents',
42         }
43         concat::fragment { '3':
44           target  => '#{@basedir}/foo',
45           source  => '#{@basedir}/file2',
46           require => File['#{@basedir}/file2'],
47         }
48       MANIFEST
49     end
50
51     it 'idempotent, file matches' do
52       idempotent_apply(pp)
53       expect(file("#{@basedir}/foo")).to be_file
54       expect(file("#{@basedir}/foo").content).to match 'file1 contents'
55       expect(file("#{@basedir}/foo").content).to match 'file2 contents'
56     end
57   end
58
59   describe 'when run should create files containing first match only.' do
60     let(:pp) do
61       <<-MANIFEST
62         file { '#{@basedir}/file1':
63           content => "file1 contents\n"
64         }
65         file { '#{@basedir}/file2':
66           content => "file2 contents\n"
67         }
68         concat { '#{@basedir}/result_file1':
69           owner   => '#{username}',
70           group   => '#{groupname}',
71           mode    => '0644',
72         }
73         concat { '#{@basedir}/result_file2':
74           owner   => '#{username}',
75           group   => '#{groupname}',
76           mode    => '0644',
77         }
78         concat { '#{@basedir}/result_file3':
79           owner   => '#{username}',
80           group   => '#{groupname}',
81           mode    => '0644',
82         }
83
84         concat::fragment { '1':
85           target  => '#{@basedir}/result_file1',
86           source  => [ '#{@basedir}/file1', '#{@basedir}/file2' ],
87           require => [ File['#{@basedir}/file1'], File['#{@basedir}/file2'] ],
88           order   => '01',
89         }
90         concat::fragment { '2':
91           target  => '#{@basedir}/result_file2',
92           source  => [ '#{@basedir}/file2', '#{@basedir}/file1' ],
93           require => [ File['#{@basedir}/file1'], File['#{@basedir}/file2'] ],
94           order   => '01',
95         }
96         concat::fragment { '3':
97           target  => '#{@basedir}/result_file3',
98           source  => [ '#{@basedir}/file1', '#{@basedir}/file2' ],
99           require => [ File['#{@basedir}/file1'], File['#{@basedir}/file2'] ],
100           order   => '01',
101         }
102       MANIFEST
103     end
104
105     it 'idempotent, files match' do
106       idempotent_apply(pp)
107       expect(file("#{@basedir}/result_file1")).to be_file
108       expect(file("#{@basedir}/result_file1").content).to match 'file1 contents'
109       expect(file("#{@basedir}/result_file1").content).not_to match 'file2 contents'
110
111       expect(file("#{@basedir}/result_file2")).to be_file
112       expect(file("#{@basedir}/result_file2").content).to match 'file2 contents'
113       expect(file("#{@basedir}/result_file2").content).not_to match 'file1 contents'
114
115       expect(file("#{@basedir}/result_file3")).to be_file
116       expect(file("#{@basedir}/result_file3").content).to match 'file1 contents'
117       expect(file("#{@basedir}/result_file3").content).not_to match 'file2 contents'
118     end
119   end
120
121   describe 'when run should fail if no match on source.' do
122     let(:pp) do
123       <<-MANIFEST
124         concat { '#{@basedir}/fail_no_source':
125           owner   => '#{username}',
126           group   => '#{groupname}',
127           mode    => '0644',
128         }
129
130         concat::fragment { '1':
131           target  => '#{@basedir}/fail_no_source',
132           source => [ '#{@basedir}/nofilehere', '#{@basedir}/nothereeither' ],
133           order   => '01',
134         }
135       MANIFEST
136     end
137
138     it 'applies the manifest with resource failures' do
139       expect(apply_manifest(pp, expect_failures: true).stderr).to match(%r{Failed to generate additional resources using 'eval_generate'})
140       expect(file("#{@basedir}/fail_no_source")).not_to be_directory
141     end
142   end
143 end