Update stdlib and concat to 6.1.0 both
[mirror/dsa-puppet.git] / 3rdparty / modules / concat / spec / acceptance / format_spec.rb
1 require 'spec_helper_acceptance'
2
3 describe 'format of file' do
4   before(:all) do
5     @basedir = setup_test_directory
6   end
7
8   describe 'when run should default to plain' do
9     let(:pp) do
10       <<-MANIFEST
11         concat { '#{@basedir}/file':
12         }
13
14         concat::fragment { '1':
15           target  => '#{@basedir}/file',
16           content => '{"one": "foo"}',
17         }
18
19         concat::fragment { '2':
20           target  => '#{@basedir}/file',
21           content => '{"one": "bar"}',
22         }
23       MANIFEST
24     end
25
26     it 'idempotent, file matches' do
27       idempotent_apply(pp)
28       expect(file("#{@basedir}/file")).to be_file
29       expect(file("#{@basedir}/file").content).to match '{"one": "foo"}{"one": "bar"}'
30     end
31   end
32
33   describe 'when run should output to plain format' do
34     let(:pp) do
35       <<-MANIFEST
36         concat { '#{@basedir}/file':
37           format => plain,
38         }
39
40         concat::fragment { '1':
41           target  => '#{@basedir}/file',
42           content => '{"one": "foo"}',
43         }
44
45         concat::fragment { '2':
46           target  => '#{@basedir}/file',
47           content => '{"one": "bar"}',
48         }
49       MANIFEST
50     end
51
52     it 'idempotent, file matches' do
53       idempotent_apply(pp)
54       expect(file("#{@basedir}/file")).to be_file
55       expect(file("#{@basedir}/file").content).to match '{"one": "foo"}{"one": "bar"}'
56     end
57   end
58
59   describe 'when run should output to yaml format' do
60     let(:pp) do
61       <<-MANIFEST
62         concat { '#{@basedir}/file':
63           format => 'yaml',
64         }
65
66         concat::fragment { '1':
67           target  => '#{@basedir}/file',
68           content => '{"one": "foo"}',
69         }
70
71         concat::fragment { '2':
72           target  => '#{@basedir}/file',
73           content => '{"two": "bar"}',
74         }
75       MANIFEST
76     end
77
78     it 'idempotent, file matches' do
79       idempotent_apply(pp)
80       expect(file("#{@basedir}/file")).to be_file
81       expect(file("#{@basedir}/file").content).to match 'one: foo\Rtwo: bar'
82     end
83   end
84
85   describe 'when run should output yaml arrays to yaml format' do
86     let(:pp) do
87       <<-MANIFEST
88         concat { '#{@basedir}/file':
89           format => 'yaml',
90         }
91
92         concat::fragment { '1':
93           target  => '#{@basedir}/file',
94           content => to_yaml([{ 'one.a' => 'foo', 'one.b' => 'bar' }]),
95         }
96
97         concat::fragment { '2':
98           target  => '#{@basedir}/file',
99           content => to_yaml([{ 'two.a' => 'dip', 'two.b' => 'doot' }]),
100         }
101       MANIFEST
102     end
103
104     it 'idempotent, file matches' do
105       idempotent_apply(pp)
106       expect(file("#{@basedir}/file")).to be_file
107       expect(file("#{@basedir}/file").content).to match '- one.a: foo\R  one.b: bar\R- two.a: dip\R  two.b: doot'
108     end
109   end
110
111   describe 'when run should output to json format' do
112     let(:pp) do
113       <<-MANIFEST
114         concat { '#{@basedir}/file':
115           format => 'json',
116         }
117
118         concat::fragment { '1':
119           target  => '#{@basedir}/file',
120           content => '{"one": "foo"}',
121         }
122
123         concat::fragment { '2':
124           target  => '#{@basedir}/file',
125           content => '{"two": "bar"}',
126         }
127       MANIFEST
128     end
129
130     it 'idempotent, file matches' do
131       idempotent_apply(pp)
132       expect(file("#{@basedir}/file")).to be_file
133       expect(file("#{@basedir}/file").content).to match '{"one":"foo","two":"bar"}'
134     end
135   end
136
137   describe 'when run should output to json-array format' do
138     let(:pp) do
139       <<-MANIFEST
140         concat { '#{@basedir}/file':
141           format => 'json-array',
142         }
143
144         concat::fragment { '1':
145           target  => '#{@basedir}/file',
146           content => '{"one": "foo"}',
147         }
148
149         concat::fragment { '2':
150           target  => '#{@basedir}/file',
151           content => '{"two": "bar"}',
152         }
153       MANIFEST
154     end
155
156     it 'idempotent, file matches' do
157       idempotent_apply(pp)
158       expect(file("#{@basedir}/file")).to be_file
159       expect(file("#{@basedir}/file").content).to match '[{"one":"foo"},{"two":"bar"}]'
160     end
161   end
162
163   describe 'when run should output to json-pretty format' do
164     let(:pp) do
165       <<-MANIFEST
166         concat { '#{@basedir}/file':
167           format => 'json-pretty',
168         }
169
170         concat::fragment { '1':
171           target  => '#{@basedir}/file',
172           content => '{"one": "foo"}',
173         }
174
175         concat::fragment { '2':
176           target  => '#{@basedir}/file',
177           content => '{"two": "bar"}',
178         }
179       MANIFEST
180     end
181
182     it 'idempotent, file matches' do
183       idempotent_apply(pp)
184       expect(file("#{@basedir}/file")).to be_file
185       expect(file("#{@basedir}/file").content).to match '{\R  "one": "foo",\R  "two": "bar"\R}'
186     end
187   end
188
189   describe 'when run should output to json-array-pretty format' do
190     let(:pp) do
191       <<-MANIFEST
192         concat { '#{@basedir}/file':
193           format => 'json-array-pretty',
194         }
195
196         concat::fragment { '1':
197           target  => '#{@basedir}/file',
198           content => '{"one": "foo"}',
199         }
200
201         concat::fragment { '2':
202           target  => '#{@basedir}/file',
203           content => '{"two": "bar"}',
204         }
205       MANIFEST
206     end
207
208     it 'idempotent, file matches' do
209       idempotent_apply(pp)
210       expect(file("#{@basedir}/file")).to be_file
211       expect(file("#{@basedir}/file").content).to match '[\n  {\n    "one": "foo"\n  },\n  {\n    "two": "bar"\n  }\n]'
212     end
213   end
214 end