diff --git a/spec/acceptance/backup_spec.rb b/spec/acceptance/backup_spec.rb index bd30c6c..1989f44 100644 --- a/spec/acceptance/backup_spec.rb +++ b/spec/acceptance/backup_spec.rb @@ -1,97 +1,115 @@ require 'spec_helper_acceptance' describe 'concat backup parameter' do basedir = default.tmpdir('concat') context '=> puppet' do + before(:all) do + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + file { '#{basedir}/file': + content => "old contents\n", + } + EOS + apply_manifest(pp) + end pp = <<-EOS - file { '#{basedir}/file': - content => "old contents\n", - } concat { '#{basedir}/file': - backup => 'puppet', - require => File['#{basedir}/file'], + backup => 'puppet', } concat::fragment { 'new file': target => '#{basedir}/file', content => 'new contents', - require => File['#{basedir}/file'], } EOS it 'applies the manifest twice with "Filebucketed" stdout and no stderr' do apply_manifest(pp, :catch_failures => true) do |r| expect(r.stdout).to match(/Filebucketed #{basedir}\/file to puppet with sum 0140c31db86293a1a1e080ce9b91305f/) # sum is for file contents of 'old contents' end apply_manifest(pp, :catch_changes => true) end describe file("#{basedir}/file") do it { should be_file } it { should contain 'new contents' } end end context '=> .backup' do + before(:all) do + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + file { '#{basedir}/file': + content => "old contents\n", + } + EOS + apply_manifest(pp) + end pp = <<-EOS - file { '#{basedir}/file': - content => "old contents\n", - } concat { '#{basedir}/file': - backup => '.backup', - require => File['#{basedir}/file'], + backup => '.backup', } concat::fragment { 'new file': target => '#{basedir}/file', content => 'new contents', - require => File['#{basedir}/file'], } EOS # XXX Puppet doesn't mention anything about filebucketing with a given # extension like .backup it 'applies the manifest twice no stderr' do apply_manifest(pp, :catch_failures => true) apply_manifest(pp, :catch_changes => true) 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 + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + file { '#{basedir}/file': + content => "old contents\n", + } + EOS + apply_manifest(pp) + end pp = <<-EOS - file { '#{basedir}/file': - content => "old contents\n", - } concat { '#{basedir}/file': backup => '.backup', - require => File['#{basedir}/file'], } concat::fragment { 'new file': target => '#{basedir}/file', content => 'new contents', - require => File['#{basedir}/file'], } EOS it 'applies the manifest twice with no "Filebucketed" stdout and no stderr' do apply_manifest(pp, :catch_failures => true) do |r| expect(r.stdout).to_not match(/Filebucketed/) end apply_manifest(pp, :catch_changes => true) 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 44a9a23..31c1647 100644 --- a/spec/acceptance/concat_spec.rb +++ b/spec/acceptance/concat_spec.rb @@ -1,185 +1,210 @@ require 'spec_helper_acceptance' case fact('osfamily') when 'AIX' username = 'root' groupname = 'system' when 'Darwin' username = 'root' groupname = 'wheel' when 'windows' username = 'Administrator' groupname = 'Administrators' else username = 'root' groupname = 'root' end describe 'basic concat test' do basedir = default.tmpdir('concat') + safe_basedir = basedir.gsub('/','_') shared_examples 'successfully_applied' do |pp| it 'applies the manifest twice with no stderr' do apply_manifest(pp, :catch_failures => true) apply_manifest(pp, :catch_changes => true) end describe file("#{default['puppetvardir']}/concat") do it { should be_directory } it { should be_owned_by username } it { should be_grouped_into groupname } it("should be mode", :unless => (fact('osfamily') == 'AIX')) { should be_mode 755 } end - describe file("#{default['puppetvardir']}/concat/bin") do + describe file("#{default['puppetvardir']}/concat/bin") do it { should be_directory } it { should be_owned_by username } it { should be_grouped_into groupname } it("should be mode", :unless => (fact('osfamily') == 'AIX')) { should be_mode 755 } end describe file("#{default['puppetvardir']}/concat/bin/concatfragments.sh") do it { should be_file } it { should be_owned_by username } #it { should be_grouped_into groupname } it("should be mode", :unless => (fact('osfamily') == 'AIX')) { should be_mode 755 } end - describe file("#{default['puppetvardir']}/concat/_tmp_concat_file") do + describe file("#{default['puppetvardir']}/concat/#{safe_basedir}_file") do it { should be_directory } it { should be_owned_by username } it { should be_grouped_into groupname } it("should be mode", :unless => (fact('osfamily') == 'AIX')) { should be_mode 750 } end - describe file("#{default['puppetvardir']}/concat/_tmp_concat_file/fragments") do + describe file("#{default['puppetvardir']}/concat/#{safe_basedir}_file/fragments") do it { should be_directory } it { should be_owned_by username } it { should be_grouped_into groupname } it("should be mode", :unless => (fact('osfamily') == 'AIX')) { should be_mode 750 } end - describe file("#{default['puppetvardir']}/concat/_tmp_concat_file/fragments.concat") do + describe file("#{default['puppetvardir']}/concat/#{safe_basedir}_file/fragments.concat") do it { should be_file } it { should be_owned_by username } it { should be_grouped_into groupname } it("should be mode", :unless => (fact('osfamily') == 'AIX')) { should be_mode 640 } end - describe file("#{default['puppetvardir']}/concat/_tmp_concat_file/fragments.concat.out") do + describe file("#{default['puppetvardir']}/concat/#{safe_basedir}_file/fragments.concat.out") do it { should be_file } it { should be_owned_by username } it { should be_grouped_into groupname } it("should be mode", :unless => (fact('osfamily') == 'AIX')) { should be_mode 640 } end end context 'owner/group root' do + before(:all) do + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + EOS + apply_manifest(pp) + end pp = <<-EOS 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 + describe file("#{basedir}/file") do it { should be_file } it { should be_owned_by username } it { should be_grouped_into groupname } it("should be mode", :unless => (fact('osfamily') == 'AIX')) { should be_mode 644 } it { should contain '1' } it { should contain '2' } end - describe file("#{default['puppetvardir']}/concat/_tmp_concat_file/fragments/01_1") do + describe file("#{default['puppetvardir']}/concat/#{safe_basedir}_file/fragments/01_1") do it { should be_file } it { should be_owned_by username } it { should be_grouped_into groupname } it("should be mode", :unless => (fact('osfamily') == 'AIX')) { should be_mode 640 } end - describe file("#{default['puppetvardir']}/concat/_tmp_concat_file/fragments/02_2") do + describe file("#{default['puppetvardir']}/concat/#{safe_basedir}_file/fragments/02_2") do it { should be_file } it { should be_owned_by username } it { should be_grouped_into groupname } it("should be mode", :unless => (fact('osfamily') == 'AIX')) { should be_mode 640 } end end context 'ensure' do context 'works when set to present with path set' do + before(:all) do + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + EOS + apply_manifest(pp) + end pp=" concat { 'file': ensure => present, path => '#{basedir}/file', mode => '0644', } concat::fragment { '1': target => 'file', content => '1', order => '01', } " it_behaves_like 'successfully_applied', pp - describe file('#{basedir}/file') do + describe file("#{basedir}/file") do it { should be_file } it("should be mode", :unless => (fact('osfamily') == 'AIX')) { should be_mode 644 } it { should contain '1' } end end context 'works when set to absent with path set' do + before(:all) do + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + EOS + apply_manifest(pp) + end pp=" concat { 'file': ensure => absent, path => '#{basedir}/file', mode => '0644', } concat::fragment { '1': target => 'file', content => '1', order => '01', } " it 'applies the manifest twice with no stderr' do apply_manifest(pp, :catch_failures => true) apply_manifest(pp, :catch_changes => true) end - describe file('#{basedir}/file') do + describe file("#{basedir}/file") do it { should_not be_file } end end end end diff --git a/spec/acceptance/empty_spec.rb b/spec/acceptance/empty_spec.rb index 27175ab..dc57cb7 100644 --- a/spec/acceptance/empty_spec.rb +++ b/spec/acceptance/empty_spec.rb @@ -1,24 +1,23 @@ require 'spec_helper_acceptance' describe 'concat force empty parameter' 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 apply_manifest(pp, :catch_failures => true) apply_manifest(pp, :catch_changes => true) end describe file("#{basedir}/file") do it { should be_file } it { should_not contain '1\n2' } end end end diff --git a/spec/acceptance/newline_spec.rb b/spec/acceptance/newline_spec.rb index 95a32af..5554962 100644 --- a/spec/acceptance/newline_spec.rb +++ b/spec/acceptance/newline_spec.rb @@ -1,57 +1,65 @@ require 'spec_helper_acceptance' describe 'concat ensure_newline parameter' do basedir = default.tmpdir('concat') context '=> false' do + before(:all) do + pp = <<-EOS + file { '#{basedir}': + ensure => directory + } + EOS + + apply_manifest(pp) + end 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 apply_manifest(pp, :catch_failures => true) apply_manifest(pp, :catch_changes => true) end describe file("#{basedir}/file") do it { should be_file } it { should contain '12' } end end context '=> true' do pp = <<-EOS 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 apply_manifest(pp, :catch_failures => true) apply_manifest(pp, :catch_changes => true) end - describe file('#{basedir}/file') do + 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 a3c80b6..fd7b05b 100644 --- a/spec/acceptance/order_spec.rb +++ b/spec/acceptance/order_spec.rb @@ -1,144 +1,143 @@ require 'spec_helper_acceptance' describe 'concat order' do basedir = default.tmpdir('concat') 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 apply_manifest(pp, :catch_failures => true) apply_manifest(pp, :catch_changes => true) 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')) { should contain "string10\nstring1\nsring2" } end end context '=> numeric' do pp = <<-EOS 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 apply_manifest(pp, :catch_failures => true) apply_manifest(pp, :catch_changes => true) 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')) { should contain "string1\nstring2\nsring10" } end end end # concat order describe 'concat::fragment order' do basedir = default.tmpdir('concat') context '=> reverse order' do pp = <<-EOS 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 apply_manifest(pp, :catch_failures => true) apply_manifest(pp, :catch_changes => true) 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')) { should contain "string3\nstring2\nsring1" } end end context '=> normal order' do pp = <<-EOS 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 apply_manifest(pp, :catch_failures => true) apply_manifest(pp, :catch_changes => true) 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')) { 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 88e3524..c200cb2 100644 --- a/spec/acceptance/replace_spec.rb +++ b/spec/acceptance/replace_spec.rb @@ -1,230 +1,256 @@ require 'spec_helper_acceptance' describe 'replacement of' do basedir = default.tmpdir('concat') context 'file' do context 'should not succeed' do + before(:all) do + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + file { '#{basedir}/file': + content => "file exists\n" + } + EOS + apply_manifest(pp) + end pp = <<-EOS - file { '#{basedir}/file': - content => "file exists\n" - } concat { '#{basedir}/file': replace => false, - require => File['#{basedir}/file'], } concat::fragment { '1': target => '#{basedir}/file', content => '1', - require => File['#{basedir}/file'], } concat::fragment { '2': target => '#{basedir}/file', content => '2', - require => File['#{basedir}/file'], } EOS it 'applies the manifest twice with no stderr' do apply_manifest(pp, :catch_failures => true) apply_manifest(pp, :catch_changes => true) 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 + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + file { '#{basedir}/file': + content => "file exists\n" + } + EOS + apply_manifest(pp) + end pp = <<-EOS - file { '#{basedir}/file': - content => "file exists\n" - } concat { '#{basedir}/file': replace => true, - require => File['#{basedir}/file'], } concat::fragment { '1': target => '#{basedir}/file', content => '1', - require => File['#{basedir}/file'], } concat::fragment { '2': target => '#{basedir}/file', content => '2', - require => File['#{basedir}/file'], } EOS it 'applies the manifest twice with no stderr' do apply_manifest(pp, :catch_failures => true) apply_manifest(pp, :catch_changes => true) 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 + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + file { '#{basedir}/file': + ensure => link, + target => '#{basedir}/dangling', + } + EOS + apply_manifest(pp) + end pp = <<-EOS - file { '#{basedir}/file': - content => "file exists\n" - } - file { '{basedir}/dangling': - ensure => link, - target => File['#{basedir}/file'], - } concat { '#{basedir}/file': replace => false, - require => File['{basedir}/dangling'], } concat::fragment { '1': target => '#{basedir}/file', content => '1', - require => File['{basedir}/dangling'], } concat::fragment { '2': target => '#{basedir}/file', content => '2', - require => File['{basedir}/dangling'], } EOS it 'applies the manifest twice with no stderr' do apply_manifest(pp, :catch_failures => true) apply_manifest(pp, :catch_changes => true) end # XXX specinfra doesn't support be_linked_to on AIX describe file("#{basedir}/file"), :unless => (fact("osfamily") == "AIX") 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 + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + file { '#{basedir}/file': + ensure => link, + target => '#{basedir}/dangling', + } + EOS + apply_manifest(pp) + end + pp = <<-EOS - file { '#{basedir}/file': - content => "file exists\n" - } - file { '{basedir}/dangling': - ensure => link, - target => File['#{basedir}/file'], - } concat { '#{basedir}/file': replace => true, - require => File['{basedir}/dangling'], } concat::fragment { '1': target => '#{basedir}/file', content => '1', - require => File['{basedir}/dangling'], } concat::fragment { '2': target => '#{basedir}/file', content => '2', - require => File['{basedir}/dangling'], } EOS it 'applies the manifest twice with no stderr' do apply_manifest(pp, :catch_failures => true) apply_manifest(pp, :catch_changes => true) 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 + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + file { '#{basedir}/file': + ensure => directory, + } + EOS + apply_manifest(pp) + end pp = <<-EOS 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 pp = <<-EOS 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 apply_manifest(pp, :catch_failures => true) apply_manifest(pp, :catch_changes => true) end describe file("#{basedir}/file") do it { should be_file } it { should contain '1' } end end end # directory end