Update stdlib and concat to 6.1.0 both
[mirror/dsa-puppet.git] / 3rdparty / modules / concat / spec / acceptance / concat_spec.rb
index 3e24a58..6de9766 100644 (file)
 require 'spec_helper_acceptance'
 
-case fact('osfamily')
-  when 'AIX'
-    username = 'root'
-    groupname = 'system'
-    scriptname = 'concatfragments.rb'
-    vardir = default.puppet['vardir']
-    if vardir.nil? or vardir == ''
-      vardir = '/opt/puppetlabs/puppet/cache'
-    end
-  when 'Darwin'
-    username = 'root'
-    groupname = 'wheel'
-    scriptname = 'concatfragments.rb'
-    vardir = default.puppet['vardir']
-    if vardir.nil? or vardir == ''
-      vardir = '/opt/puppetlabs/puppet/cache'
-    end
-  when 'windows'
-    username = 'Administrator'
-    groupname = 'Administrators'
-    scriptname = 'concatfragments.rb'
-    result = on default, "echo #{default.puppet['vardir']}"
-    vardir = result.raw_output.chomp
-  when 'Solaris'
-    username = 'root'
-    groupname = 'root'
-    scriptname = 'concatfragments.rb'
-    vardir = default.puppet['vardir']
-    if vardir.nil? or vardir == ''
-      vardir = '/opt/puppetlabs/puppet/cache'
-    end
-  else
-    username = 'root'
-    groupname = 'root'
-    scriptname = 'concatfragments.rb'
-    vardir = default.puppet['vardir']
-    if vardir.nil? or vardir == ''
-      vardir = '/opt/puppetlabs/puppet/cache'
-    end
+case os[:family]
+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
+  before(:all) do
+    @basedir = setup_test_directory
   end
 
-  context 'owner/group root' do
-    before(:all) do
-      pp = <<-EOS
-        file { '#{basedir}':
-          ensure => directory,
+  describe 'with owner/group root' do
+    let(:pp) do
+      <<-MANIFEST
+        concat { '#{@basedir}/file':
+          owner => '#{username}',
+          group => '#{groupname}',
+          mode  => '0644',
         }
-      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
+        concat::fragment { '1':
+          target  => '#{@basedir}/file',
+          content => '1',
+          order   => '01',
+        }
 
-    it_behaves_like 'successfully_applied', pp
+        concat::fragment { '2':
+          target  => '#{@basedir}/file',
+          content => '2',
+          order   => '02',
+        }
+      MANIFEST
+    end
 
-    describe file("#{basedir}/file") do
-      it { should be_file }
-      it { should be_owned_by username }
-      it("should be group", :unless => (fact('osfamily') == 'windows')) { should be_grouped_into groupname }
-      it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
-        should be_mode 644
-      }
-      its(:content) {
-        should match '1'
-        should match '2'
-      }
+    it 'idempotent, file matches' do
+      idempotent_apply(pp)
+      expect(file("#{@basedir}/file")).to be_file
+      expect(file("#{@basedir}/file")).to be_owned_by username unless os[:family] == 'windows'
+      expect(file("#{@basedir}/file")).to be_grouped_into groupname unless os[:family] == 'windows' || os[:family] == 'darwin'
+      expect(file("#{@basedir}/file")).to be_mode 644 unless os[:family] == 'aix' || os[:family] == 'windows'
+      expect(file("#{@basedir}/file").content).to match '1'
+      expect(file("#{@basedir}/file").content).to match '2'
     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="
+  describe 'when present with path set' do
+    let(:pp) do
+      <<-MANIFEST
         concat { 'file':
           ensure => present,
-          path   => '#{basedir}/file',
+          path   => '#{@basedir}/file',
           mode   => '0644',
         }
         concat::fragment { '1':
@@ -118,31 +67,23 @@ describe 'basic concat test' do
           content => '1',
           order   => '01',
         }
-      "
-
-      it_behaves_like 'successfully_applied', pp
+      MANIFEST
+    end
 
-      describe file("#{basedir}/file") do
-        it { should be_file }
-        it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
-          should be_mode 644
-        }
-        its(:content) { should match '1' }
-      end
+    it 'idempotent, file matches' do
+      idempotent_apply(pp)
+      expect(file("#{@basedir}/file")).to be_file
+      expect(file("#{@basedir}/file")).to be_mode 644 unless os[:family] == 'aix' || os[:family] == 'windows'
+      expect(file("#{@basedir}/file").content).to match '1'
     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="
+  end
+
+  describe 'when absent with path set' do
+    let(:pp) do
+      <<-MANIFEST
         concat { 'file':
           ensure => absent,
-          path   => '#{basedir}/file',
+          path   => '#{@basedir}/file',
           mode   => '0644',
         }
         concat::fragment { '1':
@@ -150,32 +91,23 @@ describe 'basic concat test' do
           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
+      MANIFEST
+    end
 
-      describe file("#{basedir}/file") do
-        it { should_not be_file }
-      end
+    it 'applies the manifest twice with no stderr' do
+      idempotent_apply(pp)
+      expect(file("#{@basedir}/file")).not_to be_file
     end
-    context 'works when set to present with path that has special characters' do
-      filename = fact('osfamily') == 'windows' ? 'file(1)' : 'file(1:2)'
+  end
 
-      before(:all) do
-        pp = <<-EOS
-        file { '#{basedir}':
-          ensure => directory,
-        }
-        EOS
-        apply_manifest(pp)
-      end
-      pp="
+  describe 'when present with path that has special characters' do
+    filename = (os[:family] == 'windows') ? 'file(1)' : 'file(1:2)'
+
+    let(:pp) do
+      <<-MANIFEST
         concat { '#{filename}':
           ensure => present,
-          path   => '#{basedir}/#{filename}',
+          path   => '#{@basedir}/#{filename}',
           mode   => '0644',
         }
         concat::fragment { '1':
@@ -183,31 +115,23 @@ describe 'basic concat test' do
           content => '1',
           order   => '01',
         }
-      "
-
-      it_behaves_like 'successfully_applied', pp
+      MANIFEST
+    end
 
-      describe file("#{basedir}/#{filename}") do
-        it { should be_file }
-        it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
-          should be_mode 644
-        }
-        its(:content) { should match '1' }
-      end
+    it 'idempotent, file matches' do
+      idempotent_apply(pp)
+      expect(file("#{@basedir}/#{filename}")).to be_file
+      expect(file("#{@basedir}/#{filename}")).to be_mode 644 unless os[:family] == 'aix' || os[:family] == 'windows'
+      expect(file("#{@basedir}/#{filename}").content).to match '1'
     end
-    context 'noop properly' do
-      before(:all) do
-        pp = <<-EOS
-        file { '#{basedir}':
-          ensure => directory,
-        }
-        EOS
-        apply_manifest(pp)
-      end
-      pp="
+  end
+
+  describe 'with noop properly' do
+    let(:pp) do
+      <<-MANIFEST
         concat { 'file':
           ensure => present,
-          path   => '#{basedir}/file',
+          path   => '#{@basedir}/file',
           mode   => '0644',
           noop   => true,
         }
@@ -216,13 +140,12 @@ describe 'basic concat test' do
           content => '1',
           order   => '01',
         }
-      "
-
-      it_behaves_like 'successfully_applied', pp
+      MANIFEST
+    end
 
-      describe file("#{basedir}/file") do
-        it { should_not be_file }
-      end
+    it 'applies manifest twice with no stderr' do
+      idempotent_apply(pp)
+      expect(file("#{@basedir}/file")).not_to be_file
     end
   end
 end