diff --git a/spec/acceptance/concat_spec.rb b/spec/acceptance/concat_spec.rb index a3c0507..673d793 100644 --- a/spec/acceptance/concat_spec.rb +++ b/spec/acceptance/concat_spec.rb @@ -1,112 +1,78 @@ 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 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 root' do + context 'owner/group' do pp = <<-EOS include concat::setup concat { '/tmp/concat/file': - owner => 'root', - group => 'root', + owner => '#{username}', + group => '#{groupname}', mode => '0644', } concat::fragment { '1': target => '/tmp/concat/file', content => '1', order => '01', } concat::fragment { '2': target => '/tmp/concat/file', content => '2', order => '02', } EOS it_behaves_like 'successfully_applied', pp describe file('/tmp/concat/file') do it { should be_file } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { 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 - it { should be_file } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { should be_mode 644 } - end - describe file("#{default['puppetvardir']}/concat/_tmp_concat_file/fragments/02_2") do - it { should be_file } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { should be_mode 644 } - end - end - - context 'owner/group non-root' do - before(:all) do - shell "groupadd -g 64444 bob" - shell "useradd -u 42 -g 64444 bob" - end - after(:all) do - shell "userdel bob" - end - - pp=" - concat { '/tmp/concat/file': - owner => 'bob', - group => 'bob', - mode => '0644', + 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") { + should be_mode 644 } - - concat::fragment { '1': - target => '/tmp/concat/file', - content => '1', - order => '01', - } - - concat::fragment { '2': - target => '/tmp/concat/file', - content => '2', - order => '02', - } - " - - it_behaves_like 'successfully_applied', pp - - describe file('/tmp/concat/file') do - it { should be_file } - it { should be_owned_by 'bob' } - it { should be_grouped_into 'bob' } - it { 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.puppet['vardir']}/concat/_tmp_concat_file/fragments/01_1") do it { should be_file } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { should be_mode 644 } - it { should contain '1' } + 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") { + should be_mode 644 + } end - describe file("#{default['puppetvardir']}/concat/_tmp_concat_file/fragments/02_2") do + describe file("#{default.puppet['vardir']}/concat/_tmp_concat_file/fragments/02_2") do it { should be_file } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { should be_mode 644 } - it { should contain '2' } + 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") { + should be_mode 644 + } end end end diff --git a/spec/acceptance/empty_spec.rb b/spec/acceptance/empty_spec.rb index 0999528..f59916d 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 context 'should run successfully' do pp = <<-EOS + include concat::setup concat { '/tmp/concat/file': - owner => root, - group => root, 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('/tmp/concat/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 6c93f0a..6d3493b 100644 --- a/spec/acceptance/fragment_source_spec.rb +++ b/spec/acceptance/fragment_source_spec.rb @@ -1,137 +1,149 @@ 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 context 'should read file fragments from local system' do before(:all) do shell("/bin/echo 'file1 contents' > /tmp/concat/file1") shell("/bin/echo 'file2 contents' > /tmp/concat/file2") end pp = <<-EOS include concat::setup concat { '/tmp/concat/foo': } concat::fragment { '1': target => '/tmp/concat/foo', source => '/tmp/concat/file1', } concat::fragment { '2': target => '/tmp/concat/foo', content => 'string1 contents', } concat::fragment { '3': target => '/tmp/concat/foo', source => '/tmp/concat/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('/tmp/concat/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 /tmp/concat /var/lib/puppet/concat') shell('mkdir -p /tmp/concat') shell("/bin/echo 'file1 contents' > /tmp/concat/file1") shell("/bin/echo 'file2 contents' > /tmp/concat/file2") end pp = <<-EOS include concat::setup concat { '/tmp/concat/result_file1': - owner => root, - group => root, + owner => '#{username}', + group => '#{groupname}', mode => '0644', } concat { '/tmp/concat/result_file2': - owner => root, - group => root, + owner => '#{username}', + group => '#{groupname}', mode => '0644', } concat { '/tmp/concat/result_file3': - owner => root, - group => root, + owner => '#{username}', + group => '#{groupname}', mode => '0644', } concat::fragment { '1': target => '/tmp/concat/result_file1', source => [ '/tmp/concat/file1', '/tmp/concat/file2' ], order => '01', } concat::fragment { '2': target => '/tmp/concat/result_file2', source => [ '/tmp/concat/file2', '/tmp/concat/file1' ], order => '01', } concat::fragment { '3': target => '/tmp/concat/result_file3', source => [ '/tmp/concat/file1', '/tmp/concat/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('/tmp/concat/result_file1') do it { should be_file } it { should contain 'file1 contents' } it { should_not contain 'file2 contents' } end describe file('/tmp/concat/result_file2') do it { should be_file } it { should contain 'file2 contents' } it { should_not contain 'file1 contents' } end describe file('/tmp/concat/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 /tmp/concat /var/lib/puppet/concat') shell('mkdir -p /tmp/concat') shell('/bin/rm -rf /tmp/concat/fail_no_source /tmp/concat/nofilehere /tmp/concat/nothereeither') end pp = <<-EOS include concat::setup concat { '/tmp/concat/fail_no_source': - owner => root, - group => root, + owner => '#{username}', + group => '#{groupname}', mode => '0644', } concat::fragment { '1': target => '/tmp/concat/fail_no_source', source => [ '/tmp/concat/nofilehere', '/tmp/concat/nothereeither' ], order => '01', } EOS it 'applies the manifest with resource failures' do apply_manifest(pp, :expect_failures => true) end describe file('/tmp/concat/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/replace_spec.rb b/spec/acceptance/replace_spec.rb index 4a305e1..99e9d48 100644 --- a/spec/acceptance/replace_spec.rb +++ b/spec/acceptance/replace_spec.rb @@ -1,247 +1,248 @@ require 'spec_helper_acceptance' describe 'replacement of' do context 'file' do context 'should not succeed' do before(:all) do shell('mkdir -p /tmp/concat') shell('echo "file exists" > /tmp/concat/file') end after(:all) do shell('rm -rf /tmp/concat /var/lib/puppet/concat') end pp = <<-EOS include concat::setup concat { '/tmp/concat/file': replace => false, } concat::fragment { '1': target => '/tmp/concat/file', content => '1', } concat::fragment { '2': target => '/tmp/concat/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('/tmp/concat/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 /tmp/concat') shell('echo "file exists" > /tmp/concat/file') end after(:all) do shell('rm -rf /tmp/concat /var/lib/puppet/concat') end pp = <<-EOS include concat::setup concat { '/tmp/concat/file': replace => true, } concat::fragment { '1': target => '/tmp/concat/file', content => '1', } concat::fragment { '2': target => '/tmp/concat/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('/tmp/concat/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 /tmp/concat') shell('ln -s /tmp/concat/dangling /tmp/concat/file') end after(:all) do shell('rm -rf /tmp/concat /var/lib/puppet/concat') end pp = <<-EOS include concat::setup concat { '/tmp/concat/file': replace => false, } concat::fragment { '1': target => '/tmp/concat/file', content => '1', } concat::fragment { '2': target => '/tmp/concat/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('/tmp/concat/file') do + # XXX specinfra doesn't support be_linked_to on AIX + describe file('/tmp/concat/file'), :unless => fact('osfamily') == "AIX" do it { should be_linked_to '/tmp/concat/dangling' } end describe file('/tmp/concat/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 /tmp/concat') shell('ln -s /tmp/concat/dangling /tmp/concat/file') end after(:all) do shell('rm -rf /tmp/concat /var/lib/puppet/concat') end pp = <<-EOS include concat::setup concat { '/tmp/concat/file': replace => true, } concat::fragment { '1': target => '/tmp/concat/file', content => '1', } concat::fragment { '2': target => '/tmp/concat/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('/tmp/concat/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 /tmp/concat/file') end after(:all) do shell('rm -rf /tmp/concat /var/lib/puppet/concat') end pp = <<-EOS include concat::setup concat { '/tmp/concat/file': } concat::fragment { '1': target => '/tmp/concat/file', content => '1', } concat::fragment { '2': target => '/tmp/concat/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('/tmp/concat/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 /tmp/concat/file') end after(:all) do shell('rm -rf /tmp/concat /var/lib/puppet/concat') end pp = <<-EOS include concat::setup concat { '/tmp/concat/file': force => true, } concat::fragment { '1': target => '/tmp/concat/file', content => '1', } concat::fragment { '2': target => '/tmp/concat/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('/tmp/concat/file') do it { should be_file } it { should contain '1' } end end end # directory end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index b064d68..35dacd1 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -1,42 +1,44 @@ require 'beaker-rspec/spec_helper' require 'beaker-rspec/helpers/serverspec' -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']}" +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 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 /var/lib/puppet/concat') + shell("rm -rf /tmp/concat #{default.puppet['vardir']}/concat") end c.treat_symbols_as_metadata_keys_with_true_values = true end