diff --git a/spec/acceptance/concat_spec.rb b/spec/acceptance/concat_spec.rb index 7cec1a5a0..7a6d95cfd 100644 --- a/spec/acceptance/concat_spec.rb +++ b/spec/acceptance/concat_spec.rb @@ -1,37 +1,37 @@ require 'spec_helper_acceptance' case fact('osfamily') -when 'AIX' - username = 'root' - groupname = 'system' - scriptname = 'concatfragments.sh' - vardir = default['puppetvardir'] -when 'Darwin' - username = 'root' - groupname = 'wheel' - scriptname = 'concatfragments.sh' - vardir = default['puppetvardir'] -when 'windows' - username = 'Administrator' - groupname = 'Administrators' - scriptname = 'concatfragments.rb' - result = on default, "echo #{default['puppetvardir']}" - vardir = result.raw_output.chomp -when 'Solaris' - username = 'root' - groupname = 'root' - scriptname = 'concatfragments.rb' - vardir = default['puppetvardir'] -else - username = 'root' - groupname = 'root' - scriptname = 'concatfragments.sh' - vardir = default['puppetvardir'] + when 'AIX' + username = 'root' + groupname = 'system' + scriptname = 'concatfragments.sh' + vardir = default['puppetvardir'] + when 'Darwin' + username = 'root' + groupname = 'wheel' + scriptname = 'concatfragments.sh' + vardir = default['puppetvardir'] + when 'windows' + username = 'Administrator' + groupname = 'Administrators' + scriptname = 'concatfragments.rb' + result = on default, "echo #{default['puppetvardir']}" + vardir = result.raw_output.chomp + when 'Solaris' + username = 'root' + groupname = 'root' + scriptname = 'concatfragments.rb' + vardir = default['puppetvardir'] + else + username = 'root' + groupname = 'root' + scriptname = 'concatfragments.sh' + vardir = default['puppetvardir'] end describe 'basic concat test' do basedir = default.tmpdir('concat') - safe_basedir = basedir.gsub(/[\/:]/,'_') + safe_basedir = basedir.gsub(/[\/:]/, '_') shared_examples 'successfully_applied' do |pp| it 'applies the manifest twice with no stderr' do @@ -46,7 +46,7 @@ should be_mode 755 } end - describe file("#{vardir}/concat/bin") do + describe file("#{vardir}/concat/bin") do it { should be_directory } it { should be_owned_by username } it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) { @@ -128,8 +128,10 @@ it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) { should be_mode 644 } - it { should contain '1' } - it { should contain '2' } + its(:content) { + should match '1' + should match '2' + } end describe file("#{vardir}/concat/#{safe_basedir}_file/fragments/01_1") do it { should be_file } @@ -177,7 +179,7 @@ it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) { should be_mode 644 } - it { should contain '1' } + its(:content) { should match '1' } end end context 'works when set to absent with path set' do diff --git a/spec/acceptance/deprecation_warnings_spec.rb b/spec/acceptance/deprecation_warnings_spec.rb index dc2f234d0..11133ea9f 100644 --- a/spec/acceptance/deprecation_warnings_spec.rb +++ b/spec/acceptance/deprecation_warnings_spec.rb @@ -3,7 +3,7 @@ describe 'deprecation warnings' do basedir = default.tmpdir('concat') - shared_examples 'has_warning'do |pp, w| + shared_examples 'has_warning' do |pp, w| it 'applies the manifest twice with a stderr regex' do expect(apply_manifest(pp, :catch_failures => true).stderr).to match(/#{Regexp.escape(w)}/m) expect(apply_manifest(pp, :catch_changes => true).stderr).to match(/#{Regexp.escape(w)}/m) @@ -43,8 +43,10 @@ describe file("#{basedir}/file") do it { should be_file } - it { should contain '# This file is managed by Puppet. DO NOT EDIT.' } - it { should contain 'bar' } + its(:content) { + should match '# This file is managed by Puppet. DO NOT EDIT.' + should match 'bar' + } end end end @@ -66,8 +68,10 @@ 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 'bar' } + its(:content) { + should_not match '# This file is managed by Puppet. DO NOT EDIT.' + should match 'bar' + } end end end @@ -100,7 +104,7 @@ describe file("#{basedir}/file") do it { should be_file } - it { should contain 'file1 contents' } + its(:content) { should match 'file1 contents' } end describe 'the fragment can be changed from a symlink to a plain file', :unless => (fact("osfamily") == "windows") do @@ -119,8 +123,10 @@ describe file("#{basedir}/file") do it { should be_file } - it { should contain 'new content' } - it { should_not contain 'file1 contents' } + its(:content) { + should match 'new content' + should_not match 'file1 contents' + } end end end # target file exists @@ -157,7 +163,7 @@ describe file("#{basedir}/file") do it { should be_file } - it { should contain 'new content' } + its(:content) { should match 'new content' } end end end # target file exists diff --git a/spec/acceptance/empty_spec.rb b/spec/acceptance/empty_spec.rb index dc57cb791..4ab6e1e60 100644 --- a/spec/acceptance/empty_spec.rb +++ b/spec/acceptance/empty_spec.rb @@ -17,7 +17,7 @@ describe file("#{basedir}/file") do it { should be_file } - it { should_not contain '1\n2' } + its(:content) { should_not match /1\n2/ } end end end diff --git a/spec/acceptance/fragment_source_spec.rb b/spec/acceptance/fragment_source_spec.rb index f3bbfccdf..a174e02b4 100644 --- a/spec/acceptance/fragment_source_spec.rb +++ b/spec/acceptance/fragment_source_spec.rb @@ -1,18 +1,18 @@ 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' + 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 'concat::fragment source' do @@ -50,9 +50,11 @@ describe file("#{basedir}/foo") do it { should be_file } - it { should contain 'file1 contents' } - it { should contain 'string1 contents' } - it { should contain 'file2 contents' } + its(:content) { + should match 'file1 contents' + should match 'string1 contents' + should match 'file2 contents' + } end end # should read file fragments from local system @@ -106,18 +108,24 @@ end describe file("#{basedir}/result_file1") do it { should be_file } - it { should contain 'file1 contents' } - it { should_not contain 'file2 contents' } + its(:content) { + should match 'file1 contents' + should_not match 'file2 contents' + } end describe file("#{basedir}/result_file2") do it { should be_file } - it { should contain 'file2 contents' } - it { should_not contain 'file1 contents' } + its(:content) { + should match 'file2 contents' + should_not match 'file1 contents' + } end describe file("#{basedir}/result_file3") do it { should be_file } - it { should contain 'file1 contents' } - it { should_not contain 'file2 contents' } + its(:content) { + should match 'file1 contents' + should_not match 'file2 contents' + } end end diff --git a/spec/acceptance/fragments_are_always_replaced_spec.rb b/spec/acceptance/fragments_are_always_replaced_spec.rb index ac714a964..70d738288 100644 --- a/spec/acceptance/fragments_are_always_replaced_spec.rb +++ b/spec/acceptance/fragments_are_always_replaced_spec.rb @@ -39,8 +39,10 @@ describe file("#{basedir}/foo") do it { should be_file } - it { should_not contain 'caller has replace unset run 1' } - it { should contain 'caller has replace unset run 2' } + its(:content) { + should_not match 'caller has replace unset run 1' + should match 'caller has replace unset run 2' + } end end # should create fragment files @@ -82,8 +84,10 @@ describe file("#{basedir}/foo") do it { should be_file } - it { should_not contain 'caller has replace true set run 1' } - it { should contain 'caller has replace true set run 2' } + its(:content) { + should_not match 'caller has replace true set run 1' + should match 'caller has replace true set run 2' + } end end # should replace its own fragment files when caller has File(replace=>true) set @@ -125,8 +129,10 @@ describe file("#{basedir}/foo") do it { should be_file } - it { should_not contain 'caller has replace false set run 1' } - it { should contain 'caller has replace false set run 2' } + its(:content) { + should_not match 'caller has replace false set run 1' + should match 'caller has replace false set run 2' + } end end # should replace its own fragment files even when caller has File(replace=>false) set diff --git a/spec/acceptance/newline_spec.rb b/spec/acceptance/newline_spec.rb index d182f2adc..c1fa16a10 100644 --- a/spec/acceptance/newline_spec.rb +++ b/spec/acceptance/newline_spec.rb @@ -33,7 +33,7 @@ describe file("#{basedir}/file") do it { should be_file } - it { should contain '12' } + its(:content) { should match '12' } end end @@ -54,13 +54,13 @@ it 'applies the manifest twice with no stderr' do apply_manifest(pp, :catch_failures => true) - apply_manifest(pp, :catch_changes => true) + apply_manifest(pp, :catch_changes => true) end describe file("#{basedir}/file") do it { should be_file } - it("should contain 1\n2\n", :unless => (fact('osfamily') == 'Solaris')) { - should contain "1\n2\n" + its(:content) { + should match /1\n2\n/ } end end diff --git a/spec/acceptance/order_spec.rb b/spec/acceptance/order_spec.rb index fd7b05b4f..c158dd880 100644 --- a/spec/acceptance/order_spec.rb +++ b/spec/acceptance/order_spec.rb @@ -3,69 +3,45 @@ describe 'concat order' do basedir = default.tmpdir('concat') - context '=> alpha' do - pp = <<-EOS + context '=> ' do + shared_examples 'sortby' do |order_by, match_output| + pp = <<-EOS concat { '#{basedir}/foo': - order => 'alpha' + order => '#{order_by}' } concat::fragment { '1': target => '#{basedir}/foo', content => 'string1', + order => '1', } concat::fragment { '2': target => '#{basedir}/foo', content => 'string2', + order => '2', } concat::fragment { '10': target => '#{basedir}/foo', content => 'string10', } - EOS + EOS - it 'applies the manifest twice with no stderr' do - apply_manifest(pp, :catch_failures => true) - apply_manifest(pp, :catch_changes => true) - end + 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" - } + describe file("#{basedir}/foo") do + it { should be_file } + its(:content) { should match match_output } + end 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) + describe 'alpha' do + it_behaves_like 'sortby', 'alpha', /string10string1string2/ 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" - } + describe 'numeric' do + it_behaves_like 'sortby', 'numeric', /string1string2string10/ end end end # concat order @@ -74,8 +50,11 @@ basedir = default.tmpdir('concat') context '=> reverse order' do - pp = <<-EOS - concat { '#{basedir}/foo': } + shared_examples 'order_by' do |order_by, match_output| + pp = <<-EOS + concat { '#{basedir}/foo': + order => '#{order_by}' + } concat::fragment { '1': target => '#{basedir}/foo', content => 'string1', @@ -91,19 +70,23 @@ content => 'string3', order => '1', } - EOS + EOS - it 'applies the manifest twice with no stderr' do - apply_manifest(pp, :catch_failures => true) - apply_manifest(pp, :catch_changes => true) - end + 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" - } + describe file("#{basedir}/foo") do + it { should be_file } + its(:content) { should match match_output } + end + end + describe 'alpha' do + it_should_behave_like 'order_by', 'alpha', /string2string1string3/ + end + describe 'numeric' do + it_should_behave_like 'order_by', 'numeric', /string3string2string1/ end end @@ -134,10 +117,7 @@ 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" - } + its(:content) { should match /string1string2string3/ } end end end # concat::fragment order diff --git a/spec/acceptance/quoted_paths_spec.rb b/spec/acceptance/quoted_paths_spec.rb index 165c153fe..042425f92 100644 --- a/spec/acceptance/quoted_paths_spec.rb +++ b/spec/acceptance/quoted_paths_spec.rb @@ -36,9 +36,7 @@ describe file("#{basedir}/concat test/foo") do it { should be_file } - it("should contain string1\nstring2", :unless => (fact('osfamily') == 'Solaris')) { - should contain "string1\nstring2" - } + its(:content) { should match /string1string2/ } end end end diff --git a/spec/acceptance/replace_spec.rb b/spec/acceptance/replace_spec.rb index 688234548..bd597ed19 100644 --- a/spec/acceptance/replace_spec.rb +++ b/spec/acceptance/replace_spec.rb @@ -38,9 +38,11 @@ describe file("#{basedir}/file") do it { should be_file } - it { should contain 'file exists' } - it { should_not contain '1' } - it { should_not contain '2' } + its(:content) { + should match 'file exists' + should_not match '1' + should_not match '2' + } end end @@ -79,9 +81,11 @@ describe file("#{basedir}/file") do it { should be_file } - it { should_not contain 'file exists' } - it { should contain '1' } - it { should contain '2' } + its(:content) { + should_not match 'file exists' + should match '1' + should match '2' + } end end end # file @@ -177,8 +181,10 @@ describe file("#{basedir}/file") do it { should be_file } - it { should contain '1' } - it { should contain '2' } + its(:content) { + should match '1' + should match '2' + } end end end # symlink @@ -249,7 +255,7 @@ describe file("#{basedir}/file") do it { should be_file } - it { should contain '1' } + its(:content) { should match '1' } end end end # directory diff --git a/spec/acceptance/specinfra_stubs.rb b/spec/acceptance/specinfra_stubs.rb new file mode 100644 index 000000000..d42e1c095 --- /dev/null +++ b/spec/acceptance/specinfra_stubs.rb @@ -0,0 +1,18 @@ +class Specinfra::Command::Windows::Base::File < Specinfra::Command::Windows::Base + class << self + def check_is_owned_by(file, owner) + Backend::PowerShell::Command.new do + exec "((gci '#{file}').GetAccessControl().Owner -match '#{owner}').Length -gt 0" + end + end + end +end + + +class Specinfra::Command::Base::File < Specinfra::Command::Base + class << self + def get_content(file) + "cat '#{file}' 2> /dev/null || echo -n" + end + end +end diff --git a/spec/acceptance/symbolic_name_spec.rb b/spec/acceptance/symbolic_name_spec.rb index b0dceac8c..df8d54f52 100644 --- a/spec/acceptance/symbolic_name_spec.rb +++ b/spec/acceptance/symbolic_name_spec.rb @@ -27,7 +27,9 @@ describe file("#{basedir}/file") do it { should be_file } - it { should contain '1' } - it { should contain '2' } + its(:content) { + should match '1' + should match '2' + } end end diff --git a/spec/acceptance/warn_spec.rb b/spec/acceptance/warn_spec.rb index 2fa529da2..7101f61f9 100644 --- a/spec/acceptance/warn_spec.rb +++ b/spec/acceptance/warn_spec.rb @@ -28,9 +28,11 @@ 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' } + its(:content) { + should match '# This file is managed by Puppet. DO NOT EDIT.' + should match '1' + should match '2' + } end end context 'false should not enable default warning message' do @@ -90,9 +92,11 @@ describe file("#{basedir}/file") do it { should be_file } - it { should contain '# foo' } - it { should contain '1' } - it { should contain '2' } + its(:content) { + should match '# foo' + should match '1' + should match '2' + } end end end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index aef9f391d..da994f8df 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -1,5 +1,6 @@ require 'beaker-rspec/spec_helper' require 'beaker-rspec/helpers/serverspec' +require 'acceptance/specinfra_stubs' unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no' # This will install the latest available package on el and deb based @@ -18,16 +19,16 @@ get_stdlib = <<-EOS package{'wget':} exec{'download': - command => "wget -P /root/ https://forgeapi.puppetlabs.com/v3/files/puppetlabs-stdlib-4.3.2.tar.gz --no-check-certificate", + command => "wget -P /root/ https://forgeapi.puppetlabs.com/v3/files/puppetlabs-stdlib-4.5.1.tar.gz --no-check-certificate", path => ['/opt/csw/bin/','/usr/bin/'] } EOS apply_manifest_on(host, get_stdlib) # have to use force otherwise it checks ssl cert even though it is a local file - on host, puppet('module install /root/puppetlabs-stdlib-4.3.2.tar.gz --force --ignore-dependencies'), {:acceptable_exit_codes => [0, 1]} + on host, puppet('module install /root/puppetlabs-stdlib-4.5.1.tar.gz --force --ignore-dependencies'), {:acceptable_exit_codes => [0, 1]} elsif host['platform'] =~ /windows/i - on host, shell('curl -k -o c:/puppetlabs-stdlib-4.3.2.tar.gz https://forgeapi.puppetlabs.com/v3/files/puppetlabs-stdlib-4.3.2.tar.gz') - on host, puppet('module install c:/puppetlabs-stdlib-4.3.2.tar.gz --force --ignore-dependencies'), {:acceptable_exit_codes => [0, 1]} + on host, shell('curl -k -o c:/puppetlabs-stdlib-4.5.1.tar.gz https://forgeapi.puppetlabs.com/v3/files/puppetlabs-stdlib-4.5.1.tar.gz') + on host, puppet('module install c:/puppetlabs-stdlib-4.5.1.tar.gz --force --ignore-dependencies'), {:acceptable_exit_codes => [0, 1]} else on host, puppet('module install puppetlabs-stdlib'), {:acceptable_exit_codes => [0, 1]} end @@ -57,3 +58,4 @@ c.treat_symbols_as_metadata_keys_with_true_values = true end +