X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Fconcat%2Fspec%2Facceptance%2Fformat_spec.rb;fp=3rdparty%2Fmodules%2Fconcat%2Fspec%2Facceptance%2Fformat_spec.rb;h=7bd1994a379837cbfcae6dfe416e3ca549f4f912;hb=30caaa85aed7015ca0d77216bff175eebd917eb7;hp=0000000000000000000000000000000000000000;hpb=6f656bd4265e3dab13b9af2bf96e9044322e9d8f;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/concat/spec/acceptance/format_spec.rb b/3rdparty/modules/concat/spec/acceptance/format_spec.rb new file mode 100644 index 000000000..7bd1994a3 --- /dev/null +++ b/3rdparty/modules/concat/spec/acceptance/format_spec.rb @@ -0,0 +1,214 @@ +require 'spec_helper_acceptance' + +describe 'format of file' do + before(:all) do + @basedir = setup_test_directory + end + + describe 'when run should default to plain' do + let(:pp) do + <<-MANIFEST + concat { '#{@basedir}/file': + } + + concat::fragment { '1': + target => '#{@basedir}/file', + content => '{"one": "foo"}', + } + + concat::fragment { '2': + target => '#{@basedir}/file', + content => '{"one": "bar"}', + } + MANIFEST + end + + it 'idempotent, file matches' do + idempotent_apply(pp) + expect(file("#{@basedir}/file")).to be_file + expect(file("#{@basedir}/file").content).to match '{"one": "foo"}{"one": "bar"}' + end + end + + describe 'when run should output to plain format' do + let(:pp) do + <<-MANIFEST + concat { '#{@basedir}/file': + format => plain, + } + + concat::fragment { '1': + target => '#{@basedir}/file', + content => '{"one": "foo"}', + } + + concat::fragment { '2': + target => '#{@basedir}/file', + content => '{"one": "bar"}', + } + MANIFEST + end + + it 'idempotent, file matches' do + idempotent_apply(pp) + expect(file("#{@basedir}/file")).to be_file + expect(file("#{@basedir}/file").content).to match '{"one": "foo"}{"one": "bar"}' + end + end + + describe 'when run should output to yaml format' do + let(:pp) do + <<-MANIFEST + concat { '#{@basedir}/file': + format => 'yaml', + } + + concat::fragment { '1': + target => '#{@basedir}/file', + content => '{"one": "foo"}', + } + + concat::fragment { '2': + target => '#{@basedir}/file', + content => '{"two": "bar"}', + } + MANIFEST + end + + it 'idempotent, file matches' do + idempotent_apply(pp) + expect(file("#{@basedir}/file")).to be_file + expect(file("#{@basedir}/file").content).to match 'one: foo\Rtwo: bar' + end + end + + describe 'when run should output yaml arrays to yaml format' do + let(:pp) do + <<-MANIFEST + concat { '#{@basedir}/file': + format => 'yaml', + } + + concat::fragment { '1': + target => '#{@basedir}/file', + content => to_yaml([{ 'one.a' => 'foo', 'one.b' => 'bar' }]), + } + + concat::fragment { '2': + target => '#{@basedir}/file', + content => to_yaml([{ 'two.a' => 'dip', 'two.b' => 'doot' }]), + } + MANIFEST + end + + it 'idempotent, file matches' do + idempotent_apply(pp) + expect(file("#{@basedir}/file")).to be_file + expect(file("#{@basedir}/file").content).to match '- one.a: foo\R one.b: bar\R- two.a: dip\R two.b: doot' + end + end + + describe 'when run should output to json format' do + let(:pp) do + <<-MANIFEST + concat { '#{@basedir}/file': + format => 'json', + } + + concat::fragment { '1': + target => '#{@basedir}/file', + content => '{"one": "foo"}', + } + + concat::fragment { '2': + target => '#{@basedir}/file', + content => '{"two": "bar"}', + } + MANIFEST + end + + it 'idempotent, file matches' do + idempotent_apply(pp) + expect(file("#{@basedir}/file")).to be_file + expect(file("#{@basedir}/file").content).to match '{"one":"foo","two":"bar"}' + end + end + + describe 'when run should output to json-array format' do + let(:pp) do + <<-MANIFEST + concat { '#{@basedir}/file': + format => 'json-array', + } + + concat::fragment { '1': + target => '#{@basedir}/file', + content => '{"one": "foo"}', + } + + concat::fragment { '2': + target => '#{@basedir}/file', + content => '{"two": "bar"}', + } + MANIFEST + end + + it 'idempotent, file matches' do + idempotent_apply(pp) + expect(file("#{@basedir}/file")).to be_file + expect(file("#{@basedir}/file").content).to match '[{"one":"foo"},{"two":"bar"}]' + end + end + + describe 'when run should output to json-pretty format' do + let(:pp) do + <<-MANIFEST + concat { '#{@basedir}/file': + format => 'json-pretty', + } + + concat::fragment { '1': + target => '#{@basedir}/file', + content => '{"one": "foo"}', + } + + concat::fragment { '2': + target => '#{@basedir}/file', + content => '{"two": "bar"}', + } + MANIFEST + end + + it 'idempotent, file matches' do + idempotent_apply(pp) + expect(file("#{@basedir}/file")).to be_file + expect(file("#{@basedir}/file").content).to match '{\R "one": "foo",\R "two": "bar"\R}' + end + end + + describe 'when run should output to json-array-pretty format' do + let(:pp) do + <<-MANIFEST + concat { '#{@basedir}/file': + format => 'json-array-pretty', + } + + concat::fragment { '1': + target => '#{@basedir}/file', + content => '{"one": "foo"}', + } + + concat::fragment { '2': + target => '#{@basedir}/file', + content => '{"two": "bar"}', + } + MANIFEST + end + + it 'idempotent, file matches' do + idempotent_apply(pp) + expect(file("#{@basedir}/file")).to be_file + expect(file("#{@basedir}/file").content).to match '[\n {\n "one": "foo"\n },\n {\n "two": "bar"\n }\n]' + end + end +end