MODULES-1764 Fix missing method for check_is_owned_by for windows

Fix tests to use its(:content) instead of deprecated should contain
This commit is contained in:
Travis Fields 2015-02-09 14:42:34 -08:00
parent fa5c1cfac3
commit 7bc211ceba
13 changed files with 189 additions and 157 deletions

View file

@ -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 @@ describe 'basic concat test' do
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 @@ describe 'basic concat test' do
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 @@ describe 'basic concat test' do
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

View file

@ -3,7 +3,7 @@ require 'spec_helper_acceptance'
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 'deprecation warnings' do
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 'deprecation warnings' do
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 'deprecation warnings' do
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 'deprecation warnings' do
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 'deprecation warnings' do
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

View file

@ -17,7 +17,7 @@ describe 'concat force empty parameter' do
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

View file

@ -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 'concat::fragment source' do
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 @@ describe 'concat::fragment source' do
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

View file

@ -39,8 +39,10 @@ describe 'concat::fragment replace' do
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 'concat::fragment replace' do
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 'concat::fragment replace' do
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

View file

@ -33,7 +33,7 @@ describe 'concat ensure_newline parameter' do
describe file("#{basedir}/file") do
it { should be_file }
it { should contain '12' }
its(:content) { should match '12' }
end
end
@ -54,13 +54,13 @@ describe 'concat ensure_newline parameter' do
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

View file

@ -3,69 +3,45 @@ require 'spec_helper_acceptance'
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)
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 }
its(:content) { should match match_output }
end
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)
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 @@ describe 'concat::fragment order' do
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 @@ describe 'concat::fragment order' do
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)
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 }
its(:content) { should match match_output }
end
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 '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 'concat::fragment order' do
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

View file

@ -36,9 +36,7 @@ describe 'quoted paths' do
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

View file

@ -38,9 +38,11 @@ describe 'replacement of' do
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 'replacement of' do
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 'replacement of' do
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 'replacement of' do
describe file("#{basedir}/file") do
it { should be_file }
it { should contain '1' }
its(:content) { should match '1' }
end
end
end # directory

View file

@ -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

View file

@ -27,7 +27,9 @@ describe 'symbolic name' do
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

View file

@ -28,9 +28,11 @@ describe 'concat warn =>' do
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 'concat warn =>' do
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

View file

@ -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 @@ unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no'
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 @@ RSpec.configure do |c|
c.treat_symbols_as_metadata_keys_with_true_values = true
end