1 require 'spec_helper_acceptance'
11 username = 'Administrator'
12 groupname = 'Administrators'
18 describe 'concat::fragment source' do
19 basedir = default.tmpdir('concat')
20 context 'should read file fragments from local system' do
22 file { '#{basedir}/file1':
23 content => "file1 contents\n"
25 file { '#{basedir}/file2':
26 content => "file2 contents\n"
28 concat { '#{basedir}/foo': }
30 concat::fragment { '1':
31 target => '#{basedir}/foo',
32 source => '#{basedir}/file1',
33 require => File['#{basedir}/file1'],
35 concat::fragment { '2':
36 target => '#{basedir}/foo',
37 content => 'string1 contents',
39 concat::fragment { '3':
40 target => '#{basedir}/foo',
41 source => '#{basedir}/file2',
42 require => File['#{basedir}/file2'],
46 it 'applies the manifest twice with no stderr' do
47 apply_manifest(pp, :catch_failures => true)
48 apply_manifest(pp, :catch_changes => true)
51 describe file("#{basedir}/foo") do
54 should match 'file1 contents'
55 should match 'string1 contents'
56 should match 'file2 contents'
59 end # should read file fragments from local system
61 context 'should create files containing first match only.' do
63 file { '#{basedir}/file1':
64 content => "file1 contents\n"
66 file { '#{basedir}/file2':
67 content => "file2 contents\n"
69 concat { '#{basedir}/result_file1':
70 owner => '#{username}',
71 group => '#{groupname}',
74 concat { '#{basedir}/result_file2':
75 owner => '#{username}',
76 group => '#{groupname}',
79 concat { '#{basedir}/result_file3':
80 owner => '#{username}',
81 group => '#{groupname}',
85 concat::fragment { '1':
86 target => '#{basedir}/result_file1',
87 source => [ '#{basedir}/file1', '#{basedir}/file2' ],
88 require => [ File['#{basedir}/file1'], File['#{basedir}/file2'] ],
91 concat::fragment { '2':
92 target => '#{basedir}/result_file2',
93 source => [ '#{basedir}/file2', '#{basedir}/file1' ],
94 require => [ File['#{basedir}/file1'], File['#{basedir}/file2'] ],
97 concat::fragment { '3':
98 target => '#{basedir}/result_file3',
99 source => [ '#{basedir}/file1', '#{basedir}/file2' ],
100 require => [ File['#{basedir}/file1'], File['#{basedir}/file2'] ],
105 it 'applies the manifest twice with no stderr' do
106 apply_manifest(pp, :catch_failures => true)
107 apply_manifest(pp, :catch_changes => true)
109 describe file("#{basedir}/result_file1") do
110 it { should be_file }
112 should match 'file1 contents'
113 should_not match 'file2 contents'
116 describe file("#{basedir}/result_file2") do
117 it { should be_file }
119 should match 'file2 contents'
120 should_not match 'file1 contents'
123 describe file("#{basedir}/result_file3") do
124 it { should be_file }
126 should match 'file1 contents'
127 should_not match 'file2 contents'
132 context 'should fail if no match on source.' do
134 concat { '#{basedir}/fail_no_source':
135 owner => '#{username}',
136 group => '#{groupname}',
140 concat::fragment { '1':
141 target => '#{basedir}/fail_no_source',
142 source => [ '#{basedir}/nofilehere', '#{basedir}/nothereeither' ],
147 it 'applies the manifest with resource failures' do
148 expect(apply_manifest(pp, :catch_failures => true).stderr).to match(/Failed to generate additional resources using 'eval_generate'/)
150 describe file("#{basedir}/fail_no_source") do
151 #FIXME: Serverspec::Type::File doesn't support exists? for some reason. so... hack.
152 it { should_not be_directory }