diff --git a/manifests/setup.pp b/manifests/setup.pp index 55d7197..5a985f6 100644 --- a/manifests/setup.pp +++ b/manifests/setup.pp @@ -1,59 +1,67 @@ # === Class: concat::setup # # Sets up the concat system. # # [$concatdir] # is where the fragments live and is set on the fact concat_basedir. # Since puppet should always manage files in $concatdir and they should # not be deleted ever, /tmp is not an option. # # [$puppetversion] # should be either 24 or 25 to enable a 24 compatible # mode, in 24 mode you might see phantom notifies this is a side effect # of the method we use to clear the fragments directory. # # The regular expression below will try to figure out your puppet version # but this code will only work in 0.24.8 and newer. # # It also copies out the concatfragments.sh file to ${concatdir}/bin # class concat::setup { + case $::osfamily { + 'windows': { + fail("Unsupported osfamily: ${osfamily}") + } + default: { + # Should work otherwise + } + } $id = $::id $root_group = $id ? { root => 0, default => $id } if $::concat_basedir { $concatdir = $::concat_basedir } else { fail ("\$concat_basedir not defined. Try running again with pluginsync=true on the [master] and/or [main] section of your node's '/etc/puppet/puppet.conf'.") } $majorversion = regsubst($::puppetversion, '^[0-9]+[.]([0-9]+)[.][0-9]+$', '\1') $fragments_source = $majorversion ? { 24 => 'puppet:///concat/concatfragments.sh', default => 'puppet:///modules/concat/concatfragments.sh' } file{"${concatdir}/bin/concatfragments.sh": owner => $id, group => $root_group, mode => '0755', source => $fragments_source; [ $concatdir, "${concatdir}/bin" ]: ensure => directory, owner => $id, group => $root_group, mode => '0750'; ## Old versions of this module used a different path. '/usr/local/bin/concatfragments.sh': ensure => absent; } # Ensure we run setup first. Class['concat::setup'] -> Concat::Fragment<| |> } diff --git a/spec/acceptance/backup_spec.rb b/spec/acceptance/backup_spec.rb index 764bdbb..c09c178 100644 --- a/spec/acceptance/backup_spec.rb +++ b/spec/acceptance/backup_spec.rb @@ -1,105 +1,105 @@ require 'spec_helper_acceptance' -describe 'concat backup parameter' do +describe 'concat backup parameter', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do basedir = default.tmpdir('concat') context '=> puppet' do before :all do shell("rm -rf #{basedir}") shell("mkdir -p #{basedir}") shell("echo 'old contents' > #{basedir}/file") end pp = <<-EOS include concat::setup concat { '#{basedir}/file': backup => 'puppet', } concat::fragment { 'new file': target => '#{basedir}/file', content => 'new contents', } EOS it 'applies the manifest twice with "Filebucketed" stdout and no stderr' do apply_manifest(pp, :catch_failures => true) do |r| expect(r.stderr).to eq("") expect(r.stdout).to match(/Filebucketed #{basedir}\/file to puppet with sum 0140c31db86293a1a1e080ce9b91305f/) # sum is for file contents of 'old contents' end expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") end describe file("#{basedir}/file") do it { should be_file } it { should contain 'new contents' } end end context '=> .backup' do before :all do shell("rm -rf #{basedir}") shell("mkdir -p #{basedir}") shell("echo 'old contents' > #{basedir}/file") end pp = <<-EOS include concat::setup concat { '#{basedir}/file': backup => '.backup', } concat::fragment { 'new file': target => '#{basedir}/file', content => 'new contents', } EOS # XXX Puppet doesn't mention anything about filebucketing with a given # extension like .backup it 'applies the manifest twice no stderr' do expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") end describe file("#{basedir}/file") do it { should be_file } it { should contain 'new contents' } end describe file("#{basedir}/file.backup") do it { should be_file } it { should contain 'old contents' } end end # XXX The backup parameter uses validate_string() and thus can't be the # boolean false value, but the string 'false' has the same effect in Puppet 3 context "=> 'false'" do before :all do shell("rm -rf #{basedir}") shell("mkdir -p #{basedir}") shell("echo 'old contents' > #{basedir}/file") end pp = <<-EOS include concat::setup concat { '#{basedir}/file': backup => '.backup', } concat::fragment { 'new file': target => '#{basedir}/file', content => 'new contents', } EOS it 'applies the manifest twice with no "Filebucketed" stdout and no stderr' do apply_manifest(pp, :catch_failures => true) do |r| expect(r.stderr).to eq("") expect(r.stdout).to_not match(/Filebucketed/) end expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") end describe file("#{basedir}/file") do it { should be_file } it { should contain 'new contents' } end end end diff --git a/spec/acceptance/concat_spec.rb b/spec/acceptance/concat_spec.rb index ab6788e..b4f7352 100644 --- a/spec/acceptance/concat_spec.rb +++ b/spec/acceptance/concat_spec.rb @@ -1,79 +1,79 @@ require 'spec_helper_acceptance' case fact('osfamily') when 'AIX' username = 'root' groupname = 'system' when 'windows' username = 'Administrator' groupname = 'Administrators' else username = 'root' groupname = 'root' end -describe 'basic concat test' do +describe 'basic concat test', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do basedir = default.tmpdir('concat') shared_examples 'successfully_applied' do |pp| it 'applies the manifest twice with no stderr' do expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") end end context 'owner/group' do pp = <<-EOS include concat::setup concat { '#{basedir}/file': owner => '#{username}', group => '#{groupname}', mode => '0644', } concat::fragment { '1': target => '#{basedir}/file', content => '1', order => '01', } concat::fragment { '2': target => '#{basedir}/file', content => '2', order => '02', } EOS it_behaves_like 'successfully_applied', pp describe file("#{basedir}/file") do it { should be_file } it { should be_owned_by username } it { should be_grouped_into groupname } # XXX file be_mode isn't supported on AIX - it("should be mode 644", :unless => fact('osfamily') == "AIX") { + it("should be mode 644", :unless => (fact('osfamily') == "AIX" or UNSUPPORTED_PLATFORMS.include?(fact('osfamily')))) { should be_mode 644 } it { should contain '1' } it { should contain '2' } end describe file("#{default.puppet['vardir']}/concat/#{basedir.gsub('/','_')}_file/fragments/01_1") do it { should be_file } it { should be_owned_by username } it { should be_grouped_into groupname } # XXX file be_mode isn't supported on AIX - it("should be mode 644", :unless => fact('osfamily') == "AIX") { + it("should be mode 644", :unless => (fact('osfamily') == "AIX" or UNSUPPORTED_PLATFORMS.include?(fact('osfamily')))) { should be_mode 644 } end describe file("#{default.puppet['vardir']}/concat/#{basedir.gsub('/','_')}_file/fragments/02_2") do it { should be_file } it { should be_owned_by username } it { should be_grouped_into groupname } # XXX file be_mode isn't supported on AIX - it("should be mode 644", :unless => fact('osfamily') == "AIX") { + it("should be mode 644", :unless => (fact('osfamily') == "AIX" or UNSUPPORTED_PLATFORMS.include?(fact('osfamily')))) { should be_mode 644 } end end end diff --git a/spec/acceptance/empty_spec.rb b/spec/acceptance/empty_spec.rb index ad24415..8eb0a96 100644 --- a/spec/acceptance/empty_spec.rb +++ b/spec/acceptance/empty_spec.rb @@ -1,24 +1,24 @@ require 'spec_helper_acceptance' -describe 'concat force empty parameter' do +describe 'concat force empty parameter', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do basedir = default.tmpdir('concat') context 'should run successfully' do pp = <<-EOS include concat::setup concat { '#{basedir}/file': mode => '0644', force => true, } EOS it 'applies the manifest twice with no stderr' do expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") end describe file("#{basedir}/file") do it { should be_file } it { should_not contain '1\n2' } end end end diff --git a/spec/acceptance/fragment_source_spec.rb b/spec/acceptance/fragment_source_spec.rb index d2f0c7b..3f6eb49 100644 --- a/spec/acceptance/fragment_source_spec.rb +++ b/spec/acceptance/fragment_source_spec.rb @@ -1,150 +1,150 @@ require 'spec_helper_acceptance' case fact('osfamily') when 'AIX' username = 'root' groupname = 'system' when 'windows' username = 'Administrator' groupname = 'Administrators' else username = 'root' groupname = 'root' end -describe 'concat::fragment source' do +describe 'concat::fragment source', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do basedir = default.tmpdir('concat') context 'should read file fragments from local system' do before(:all) do shell("/bin/echo 'file1 contents' > #{basedir}/file1") shell("/bin/echo 'file2 contents' > #{basedir}/file2") end pp = <<-EOS include concat::setup concat { '#{basedir}/foo': } concat::fragment { '1': target => '#{basedir}/foo', source => '#{basedir}/file1', } concat::fragment { '2': target => '#{basedir}/foo', content => 'string1 contents', } concat::fragment { '3': target => '#{basedir}/foo', source => '#{basedir}/file2', } EOS it 'applies the manifest twice with no stderr' do expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") end describe file("#{basedir}/foo") do it { should be_file } it { should contain 'file1 contents' } it { should contain 'string1 contents' } it { should contain 'file2 contents' } end end # should read file fragments from local system context 'should create files containing first match only.' do before(:all) do shell("rm -rf #{basedir} #{default.puppet['vardir']}/concat") shell("mkdir -p #{basedir}") shell("echo 'file1 contents' > #{basedir}/file1") shell("echo 'file2 contents' > #{basedir}/file2") end pp = <<-EOS include concat::setup concat { '#{basedir}/result_file1': owner => '#{username}', group => '#{groupname}', mode => '0644', } concat { '#{basedir}/result_file2': owner => '#{username}', group => '#{groupname}', mode => '0644', } concat { '#{basedir}/result_file3': owner => '#{username}', group => '#{groupname}', mode => '0644', } concat::fragment { '1': target => '#{basedir}/result_file1', source => [ '#{basedir}/file1', '#{basedir}/file2' ], order => '01', } concat::fragment { '2': target => '#{basedir}/result_file2', source => [ '#{basedir}/file2', '#{basedir}/file1' ], order => '01', } concat::fragment { '3': target => '#{basedir}/result_file3', source => [ '#{basedir}/file1', '#{basedir}/file2' ], order => '01', } EOS it 'applies the manifest twice with no stderr' do expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") end describe file("#{basedir}/result_file1") do it { should be_file } it { should contain 'file1 contents' } it { should_not contain 'file2 contents' } end describe file("#{basedir}/result_file2") do it { should be_file } it { should contain 'file2 contents' } it { should_not contain 'file1 contents' } end describe file("#{basedir}/result_file3") do it { should be_file } it { should contain 'file1 contents' } it { should_not contain 'file2 contents' } end end context 'should fail if no match on source.' do before(:all) do shell("rm -rf #{basedir} #{default.puppet['vardir']}/concat") shell("mkdir -p #{basedir}") shell("rm -rf #{basedir}/fail_no_source #{basedir}/nofilehere #{basedir}/nothereeither") end pp = <<-EOS include concat::setup concat { '#{basedir}/fail_no_source': owner => '#{username}', group => '#{groupname}', mode => '0644', } concat::fragment { '1': target => '#{basedir}/fail_no_source', source => [ '#{basedir}/nofilehere', '#{basedir}/nothereeither' ], order => '01', } EOS it 'applies the manifest with resource failures' do apply_manifest(pp, :expect_failures => true) end describe file("#{basedir}/fail_no_source") do #FIXME: Serverspec::Type::File doesn't support exists? for some reason. so... hack. it { should_not be_file } it { should_not be_directory } end end end diff --git a/spec/acceptance/newline_spec.rb b/spec/acceptance/newline_spec.rb index a511e3f..fb3f17d 100644 --- a/spec/acceptance/newline_spec.rb +++ b/spec/acceptance/newline_spec.rb @@ -1,60 +1,60 @@ require 'spec_helper_acceptance' -describe 'concat ensure_newline parameter' do +describe 'concat ensure_newline parameter', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do basedir = default.tmpdir('concat') context '=> false' do pp = <<-EOS include concat::setup concat { '#{basedir}/file': ensure_newline => false, } concat::fragment { '1': target => '#{basedir}/file', content => '1', } concat::fragment { '2': target => '#{basedir}/file', content => '2', } EOS it 'applies the manifest twice with no stderr' do expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") end describe file("#{basedir}/file") do it { should be_file } it { should contain '12' } end end #context '=> true' do # pp = <<-EOS # include concat::setup # concat { '#{basedir}/file': # ensure_newline => true, # } # concat::fragment { '1': # target => '#{basedir}/file', # content => '1', # } # concat::fragment { '2': # target => '#{basedir}/file', # content => '2', # } # EOS # it 'applies the manifest twice with no stderr' do # expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") # expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") # #XXX ensure_newline => true causes changes on every run because the files # #are modified in place. # end # describe file("#{basedir}/file") do # it { should be_file } # it { should contain "1\n2\n" } # end #end end diff --git a/spec/acceptance/order_spec.rb b/spec/acceptance/order_spec.rb index 32f85d5..1c79ab4 100644 --- a/spec/acceptance/order_spec.rb +++ b/spec/acceptance/order_spec.rb @@ -1,155 +1,155 @@ require 'spec_helper_acceptance' -describe 'concat order' do +describe 'concat order', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do basedir = default.tmpdir('concat') before(:all) do shell("rm -rf #{basedir} #{default.puppet['vardir']}/concat") shell("mkdir -p #{basedir}") end context '=> alpha' do pp = <<-EOS include concat::setup concat { '#{basedir}/foo': order => 'alpha' } concat::fragment { '1': target => '#{basedir}/foo', content => 'string1', } concat::fragment { '2': target => '#{basedir}/foo', content => 'string2', } concat::fragment { '10': target => '#{basedir}/foo', content => 'string10', } EOS it 'applies the manifest twice with no stderr' do expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") end describe file("#{basedir}/foo") do it { should be_file } #XXX Solaris 10 doesn't support multi-line grep - it("should contain string10\nstring1\nsring2", :unless => fact('osfamily') == 'Solaris') { + it("should contain string10\nstring1\nsring2", :unless => (fact('osfamily') == 'Solaris' or UNSUPPORTED_PLATFORMS.include?(fact('osfamily')))) { should contain "string10\nstring1\nsring2" } end end context '=> numeric' do pp = <<-EOS include concat::setup concat { '#{basedir}/foo': order => 'numeric' } concat::fragment { '1': target => '#{basedir}/foo', content => 'string1', } concat::fragment { '2': target => '#{basedir}/foo', content => 'string2', } concat::fragment { '10': target => '#{basedir}/foo', content => 'string10', } EOS it 'applies the manifest twice with no stderr' do expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") end describe file("#{basedir}/foo") do it { should be_file } #XXX Solaris 10 doesn't support multi-line grep - it("should contain string1\nstring2\nsring10", :unless => fact('osfamily') == 'Solaris') { + it("should contain string1\nstring2\nsring10", :unless => (fact('osfamily') == 'Solaris' or UNSUPPORTED_PLATFORMS.include?(fact('osfamily')))) { should contain "string1\nstring2\nsring10" } end end end # concat order -describe 'concat::fragment order' do +describe 'concat::fragment order', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do basedir = default.tmpdir('concat') before(:all) do shell("rm -rf #{basedir} #{default.puppet['vardir']}/concat") shell("mkdir -p #{basedir}") end context '=> reverse order' do pp = <<-EOS include concat::setup concat { '#{basedir}/foo': } concat::fragment { '1': target => '#{basedir}/foo', content => 'string1', order => '15', } concat::fragment { '2': target => '#{basedir}/foo', content => 'string2', # default order 10 } concat::fragment { '3': target => '#{basedir}/foo', content => 'string3', order => '1', } EOS it 'applies the manifest twice with no stderr' do expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") end describe file("#{basedir}/foo") do it { should be_file } #XXX Solaris 10 doesn't support multi-line grep - it("should contain string3\nstring2\nsring1", :unless => fact('osfamily') == 'Solaris') { + it("should contain string3\nstring2\nsring1", :unless => (fact('osfamily') == 'Solaris' or UNSUPPORTED_PLATFORMS.include?(fact('osfamily')))) { should contain "string3\nstring2\nsring1" } end end context '=> normal order' do pp = <<-EOS include concat::setup concat { '#{basedir}/foo': } concat::fragment { '1': target => '#{basedir}/foo', content => 'string1', order => '01', } concat::fragment { '2': target => '#{basedir}/foo', content => 'string2', order => '02' } concat::fragment { '3': target => '#{basedir}/foo', content => 'string3', order => '03', } EOS it 'applies the manifest twice with no stderr' do expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") end describe file("#{basedir}/foo") do it { should be_file } #XXX Solaris 10 doesn't support multi-line grep - it("should contain string1\nstring2\nsring3", :unless => fact('osfamily') == 'Solaris') { + it("should contain string1\nstring2\nsring3", :unless => (fact('osfamily') == 'Solaris' or UNSUPPORTED_PLATFORMS.include?(fact('osfamily')))) { should contain "string1\nstring2\nsring3" } end end end # concat::fragment order diff --git a/spec/acceptance/replace_spec.rb b/spec/acceptance/replace_spec.rb index dfc05fe..e84140f 100644 --- a/spec/acceptance/replace_spec.rb +++ b/spec/acceptance/replace_spec.rb @@ -1,249 +1,249 @@ require 'spec_helper_acceptance' -describe 'replacement of' do +describe 'replacement of', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do basedir = default.tmpdir('concat') context 'file' do context 'should not succeed' do before(:all) do shell("mkdir -p #{basedir}") shell("echo 'file exists' > #{basedir}/file") end after(:all) do shell("rm -rf #{basedir} #{default.puppet['vardir']}/concat") end pp = <<-EOS include concat::setup concat { '#{basedir}/file': replace => false, } concat::fragment { '1': target => '#{basedir}/file', content => '1', } concat::fragment { '2': target => '#{basedir}/file', content => '2', } EOS it 'applies the manifest twice with no stderr' do expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") end describe file("#{basedir}/file") do it { should be_file } it { should contain 'file exists' } it { should_not contain '1' } it { should_not contain '2' } end end context 'should succeed' do before(:all) do shell("mkdir -p #{basedir}") shell("echo 'file exists' > #{basedir}/file") end after(:all) do shell("rm -rf #{basedir} #{default.puppet['vardir']}/concat") end pp = <<-EOS include concat::setup concat { '#{basedir}/file': replace => true, } concat::fragment { '1': target => '#{basedir}/file', content => '1', } concat::fragment { '2': target => '#{basedir}/file', content => '2', } EOS it 'applies the manifest twice with no stderr' do expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") end describe file("#{basedir}/file") do it { should be_file } it { should_not contain 'file exists' } it { should contain '1' } it { should contain '2' } end end end # file context 'symlink' do context 'should not succeed' do # XXX the core puppet file type will replace a symlink with a plain file # when using ensure => present and source => ... but it will not when using # ensure => present and content => ...; this is somewhat confusing behavior before(:all) do shell("mkdir -p #{basedir}") shell("ln -s #{basedir}/dangling #{basedir}/file") end after(:all) do shell("rm -rf #{basedir} #{default.puppet['vardir']}/concat") end pp = <<-EOS include concat::setup concat { '#{basedir}/file': replace => false, } concat::fragment { '1': target => '#{basedir}/file', content => '1', } concat::fragment { '2': target => '#{basedir}/file', content => '2', } EOS it 'applies the manifest twice with no stderr' do expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") end # XXX specinfra doesn't support be_linked_to on AIX - describe file("#{basedir}/file"), :unless => fact("osfamily") == "AIX" do + describe file("#{basedir}/file"), :unless => (fact("osfamily") == "AIX" or UNSUPPORTED_PLATFORMS.include?(fact('osfamily'))) do it { should be_linked_to "#{basedir}/dangling" } end describe file("#{basedir}/dangling") do # XXX serverspec does not have a matcher for 'exists' it { should_not be_file } it { should_not be_directory } end end context 'should succeed' do # XXX the core puppet file type will replace a symlink with a plain file # when using ensure => present and source => ... but it will not when using # ensure => present and content => ...; this is somewhat confusing behavior before(:all) do shell("mkdir -p #{basedir}") shell("ln -s #{basedir}/dangling #{basedir}/file") end after(:all) do shell("rm -rf #{basedir} #{default.puppet['vardir']}/concat") end pp = <<-EOS include concat::setup concat { '#{basedir}/file': replace => true, } concat::fragment { '1': target => '#{basedir}/file', content => '1', } concat::fragment { '2': target => '#{basedir}/file', content => '2', } EOS it 'applies the manifest twice with no stderr' do expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") end describe file("#{basedir}/file") do it { should be_file } it { should contain '1' } it { should contain '2' } end end end # symlink context 'directory' do context 'should not succeed' do before(:all) do shell("mkdir -p #{basedir}/file") end after(:all) do shell("rm -rf #{basedir} #{default.puppet['vardir']}/concat") end pp = <<-EOS include concat::setup concat { '#{basedir}/file': } concat::fragment { '1': target => '#{basedir}/file', content => '1', } concat::fragment { '2': target => '#{basedir}/file', content => '2', } EOS it 'applies the manifest twice with stderr for changing to file' do expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/change from directory to file failed/) expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/change from directory to file failed/) end describe file("#{basedir}/file") do it { should be_directory } end end # XXX concat's force param currently enables the creation of empty files # when there are no fragments, and the replace param will only replace # files and symlinks, not directories. The semantics either need to be # changed, extended, or a new param introduced to control directory # replacement. context 'should succeed', :pending => 'not yet implemented' do before(:all) do shell("mkdir -p #{basedir}/file") end after(:all) do shell("rm -rf #{basedir} #{default.puppet['vardir']}/concat") end pp = <<-EOS include concat::setup concat { '#{basedir}/file': force => true, } concat::fragment { '1': target => '#{basedir}/file', content => '1', } concat::fragment { '2': target => '#{basedir}/file', content => '2', } EOS it 'applies the manifest twice with no stderr' do expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") end describe file("#{basedir}/file") do it { should be_file } it { should contain '1' } end end end # directory end diff --git a/spec/acceptance/symbolic_name_spec.rb b/spec/acceptance/symbolic_name_spec.rb index 384a821..57a9e95 100644 --- a/spec/acceptance/symbolic_name_spec.rb +++ b/spec/acceptance/symbolic_name_spec.rb @@ -1,34 +1,34 @@ require 'spec_helper_acceptance' -describe 'symbolic name' do +describe 'symbolic name', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do basedir = default.tmpdir('concat') pp = <<-EOS include concat::setup concat { 'not_abs_path': path => '#{basedir}/file', } concat::fragment { '1': target => 'not_abs_path', content => '1', order => '01', } concat::fragment { '2': target => 'not_abs_path', content => '2', order => '02', } EOS it 'applies the manifest twice with no stderr' do expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") end describe file("#{basedir}/file") do it { should be_file } it { should contain '1' } it { should contain '2' } end end diff --git a/spec/acceptance/unsupported_spec.rb b/spec/acceptance/unsupported_spec.rb new file mode 100644 index 0000000..9df7d88 --- /dev/null +++ b/spec/acceptance/unsupported_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper_acceptance' + +describe 'unsupported distributions and OSes', :if => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do + basedir = default.tmpdir('concat') + it 'should fail' do + pp = <<-EOS + include concat::setup + concat { '#{basedir}/file': + backup => 'puppet', + } + concat::fragment { 'new file': + target => '#{basedir}/file', + content => 'new contents', + } + EOS + expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/unsupported/i) + end +end diff --git a/spec/acceptance/warn_spec.rb b/spec/acceptance/warn_spec.rb index 68758fe..b036884 100644 --- a/spec/acceptance/warn_spec.rb +++ b/spec/acceptance/warn_spec.rb @@ -1,101 +1,101 @@ require 'spec_helper_acceptance' -describe 'concat warn =>' do +describe 'concat warn =>', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do basedir = default.tmpdir('concat') context 'true should enable default warning message' do pp = <<-EOS include concat::setup concat { '#{basedir}/file': warn => true, } concat::fragment { '1': target => '#{basedir}/file', content => '1', order => '01', } concat::fragment { '2': target => '#{basedir}/file', content => '2', order => '02', } EOS it 'applies the manifest twice with no stderr' do expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") end describe file("#{basedir}/file") do it { should be_file } it { should contain '# This file is managed by Puppet. DO NOT EDIT.' } it { should contain '1' } it { should contain '2' } end end context 'false should not enable default warning message' do pp = <<-EOS include concat::setup concat { '#{basedir}/file': warn => false, } concat::fragment { '1': target => '#{basedir}/file', content => '1', order => '01', } concat::fragment { '2': target => '#{basedir}/file', content => '2', order => '02', } EOS it 'applies the manifest twice with no stderr' do expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") end describe file("#{basedir}/file") do it { should be_file } it { should_not contain '# This file is managed by Puppet. DO NOT EDIT.' } it { should contain '1' } it { should contain '2' } end end context '# foo should overide default warning message' do pp = <<-EOS include concat::setup concat { '#{basedir}/file': warn => '# foo', } concat::fragment { '1': target => '#{basedir}/file', content => '1', order => '01', } concat::fragment { '2': target => '#{basedir}/file', content => '2', order => '02', } EOS it 'applies the manifest twice with no stderr' do expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") end describe file("#{basedir}/file") do it { should be_file } it { should contain '# foo' } it { should contain '1' } it { should contain '2' } end end end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 35dacd1..c75a7fb 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -1,44 +1,46 @@ require 'beaker-rspec/spec_helper' require 'beaker-rspec/helpers/serverspec' unless ENV['RS_PROVISION'] == 'no' hosts.each do |host| if host['platform'] =~ /debian/ on host, 'echo \'export PATH=/var/lib/gems/1.8/bin/:${PATH}\' >> ~/.bashrc' end if host.is_pe? install_pe else # Install Puppet install_package host, 'rubygems' on host, 'gem install puppet --no-ri --no-rdoc' on host, "mkdir -p #{host['distmoduledir']}" end end end +UNSUPPORTED_PLATFORMS = ['windows'] + RSpec.configure do |c| # Project root proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) # Readable test descriptions c.formatter = :documentation # Configure all nodes in nodeset c.before :suite do # Install module and dependencies puppet_module_install(:source => proj_root, :module_name => 'concat') hosts.each do |host| on host, puppet('module','install','puppetlabs-stdlib'), { :acceptable_exit_codes => [0,1] } end end c.before(:all) do shell('mkdir -p /tmp/concat') end c.after(:all) do shell("rm -rf /tmp/concat #{default.puppet['vardir']}/concat") end c.treat_symbols_as_metadata_keys_with_true_values = true end