1 require 'spec_helper_acceptance'
11 username = 'Administrator'
12 groupname = 'Administrators'
18 describe 'concat::fragment source' do
20 @basedir = setup_test_directory
23 describe 'when run should read file fragments from local system' do
26 file { '#{@basedir}/file1':
27 content => "file1 contents\n"
29 file { '#{@basedir}/file2':
30 content => "file2 contents\n"
32 concat { '#{@basedir}/foo': }
34 concat::fragment { '1':
35 target => '#{@basedir}/foo',
36 source => '#{@basedir}/file1',
37 require => File['#{@basedir}/file1'],
39 concat::fragment { '2':
40 target => '#{@basedir}/foo',
41 content => 'string1 contents',
43 concat::fragment { '3':
44 target => '#{@basedir}/foo',
45 source => '#{@basedir}/file2',
46 require => File['#{@basedir}/file2'],
51 it 'idempotent, file matches' do
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'
59 describe 'when run should create files containing first match only.' do
62 file { '#{@basedir}/file1':
63 content => "file1 contents\n"
65 file { '#{@basedir}/file2':
66 content => "file2 contents\n"
68 concat { '#{@basedir}/result_file1':
69 owner => '#{username}',
70 group => '#{groupname}',
73 concat { '#{@basedir}/result_file2':
74 owner => '#{username}',
75 group => '#{groupname}',
78 concat { '#{@basedir}/result_file3':
79 owner => '#{username}',
80 group => '#{groupname}',
84 concat::fragment { '1':
85 target => '#{@basedir}/result_file1',
86 source => [ '#{@basedir}/file1', '#{@basedir}/file2' ],
87 require => [ File['#{@basedir}/file1'], File['#{@basedir}/file2'] ],
90 concat::fragment { '2':
91 target => '#{@basedir}/result_file2',
92 source => [ '#{@basedir}/file2', '#{@basedir}/file1' ],
93 require => [ File['#{@basedir}/file1'], File['#{@basedir}/file2'] ],
96 concat::fragment { '3':
97 target => '#{@basedir}/result_file3',
98 source => [ '#{@basedir}/file1', '#{@basedir}/file2' ],
99 require => [ File['#{@basedir}/file1'], File['#{@basedir}/file2'] ],
105 it 'idempotent, files match' do
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'
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'
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'
121 describe 'when run should fail if no match on source.' do
124 concat { '#{@basedir}/fail_no_source':
125 owner => '#{username}',
126 group => '#{groupname}',
130 concat::fragment { '1':
131 target => '#{@basedir}/fail_no_source',
132 source => [ '#{@basedir}/nofilehere', '#{@basedir}/nothereeither' ],
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