]> git.donarmstrong.com Git - dsa-puppet.git/blobdiff - 3rdparty/modules/concat/spec/unit/defines/concat_spec.rb
try if downgrading to 1.2.2 solves my problem
[dsa-puppet.git] / 3rdparty / modules / concat / spec / unit / defines / concat_spec.rb
index b2254f4ec138b73f81d4f4f56c4aa4c3fed56904..115a0f55bca4035272e69e78520edb011b4729c8 100644 (file)
@@ -14,13 +14,19 @@ describe 'concat', :type => :define do
       :group          => nil,
       :mode           => '0644',
       :warn           => false,
+      :force          => false,
       :backup         => 'puppet',
       :replace        => true,
+      :order          => 'alpha',
+      :ensure_newline => false,
+      :validate_cmd   => nil,
     }.merge(params)
 
     safe_name            = title.gsub('/', '_')
+    concatdir            = '/var/lib/puppet/concat'
+    fragdir              = "#{concatdir}/#{safe_name}"
     concat_name          = 'fragments.concat.out'
-    default_warn_message = "# This file is managed by Puppet. DO NOT EDIT.\n"
+    default_warn_message = '# This file is managed by Puppet. DO NOT EDIT.'
 
     file_defaults = {
       :backup  => p[:backup],
@@ -30,6 +36,7 @@ describe 'concat', :type => :define do
     let(:params) { params }
     let(:facts) do
       {
+        :concat_basedir => concatdir,
         :id             => id,
         :osfamily       => 'Debian',
         :path           => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
@@ -40,23 +47,117 @@ describe 'concat', :type => :define do
 
     if p[:ensure] == 'present'
       it do
-        should contain_concat(title).with(file_defaults.merge({
+        should contain_file(fragdir).with(file_defaults.merge({
+          :ensure => 'directory',
+          :mode   => '0750',
+        }))
+      end
+
+      it do
+        should contain_file("#{fragdir}/fragments").with(file_defaults.merge({
+          :ensure  => 'directory',
+          :mode    => '0750',
+          :force   => true,
+          :ignore  => ['.svn', '.git', '.gitignore'],
+          :purge   => true,
+          :recurse => true,
+        }))
+      end
+
+      [
+        "#{fragdir}/fragments.concat",
+        "#{fragdir}/#{concat_name}",
+      ].each do |file|
+        it do
+          should contain_file(file).with(file_defaults.merge({
+            :ensure => 'present',
+            :mode   => '0640',
+          }))
+        end
+      end
+
+      it do
+        should contain_file(title).with(file_defaults.merge({
           :ensure       => 'present',
           :owner        => p[:owner],
           :group        => p[:group],
           :mode         => p[:mode],
+          :replace      => p[:replace],
           :path         => p[:path],
+          :alias        => "concat_#{title}",
+          :source       => "#{fragdir}/#{concat_name}",
+          :validate_cmd => p[:validate_cmd],
           :backup       => p[:backup],
-          :replace      => p[:replace],
         }))
       end
+
+      cmd = "#{concatdir}/bin/concatfragments.rb " +
+            "-o \"#{concatdir}/#{safe_name}/fragments.concat.out\" " +
+            "-d \"#{concatdir}/#{safe_name}\""
+
+      # flag order: fragdir, warnflag, forceflag, orderflag, newlineflag 
+      if p.has_key?(:warn)
+        case p[:warn]
+        when TrueClass
+          message = default_warn_message
+        when 'true', 'yes', 'on'
+          # should generate a stringified boolean warning
+          message = default_warn_message
+        when FalseClass
+          message = nil
+        when 'false', 'no', 'off'
+          # should generate a stringified boolean warning
+          message = nil
+        else
+          message = p[:warn]
+        end
+
+        unless message.nil?
+          cmd += " -w \'#{message}\'"
+        end
+      end
+
+      cmd += " -f" if p[:force]
+      cmd += " -n" if p[:order] == 'numeric'
+      cmd += " -l" if p[:ensure_newline] == true
+
+      it do
+        should contain_exec("concat_#{title}").with({
+          :alias   => "concat_#{fragdir}",
+          :command => cmd,
+          :unless  => "#{cmd} -t",
+        })
+      end
     else
+      [
+        fragdir,
+        "#{fragdir}/fragments",
+        "#{fragdir}/fragments.concat",
+        "#{fragdir}/#{concat_name}",
+      ].each do |file|
+        it do
+          should contain_file(file).with(file_defaults.merge({
+            :ensure => 'absent',
+            :force  => true,
+          }))
+        end
+      end
+
       it do
-        should contain_concat(title).with(file_defaults.merge({
+        should contain_file(title).with(file_defaults.merge({
           :ensure => 'absent',
           :backup => p[:backup],
         }))
       end
+
+      it do
+        should contain_exec("concat_#{title}").with({
+          :alias   => "concat_#{fragdir}",
+          :command => 'true',
+          :unless  => 'true',
+          :path    => '/bin:/usr/bin',
+        })
+      end
     end
   end
 
@@ -74,14 +175,14 @@ describe 'concat', :type => :define do
         context title do
           let(:title) { title }
           it 'should fail' do
-            expect { catalogue }.to raise_error(Puppet::Error, /is not an absolute path/)
+            expect { should }.to raise_error(Puppet::Error, /is not an absolute path/)
           end
         end
       end
     end
 
     context 'with path param' do
-      ['/foo', 'foo', 'foo/bar'].each do |title|
+      ['./foo', 'foo', 'foo/bar'].each do |title|
         context title do
           it_behaves_like 'concat', title, { :path => '/etc/foo.bar' }
         end
@@ -104,7 +205,7 @@ describe 'concat', :type => :define do
       let(:title) { '/etc/foo.bar' }
       let(:params) {{ :ensure => 'invalid' }}
       it 'should fail' do
-        expect { catalogue }.to raise_error(Puppet::Error, /#{Regexp.escape('does not match "^present$|^absent$"')}/)
+        expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape('does not match "^present$|^absent$"')}/)
       end
     end
   end # ensure =>
@@ -119,7 +220,7 @@ describe 'concat', :type => :define do
         let(:title) { '/etc/foo.bar' }
         let(:params) {{ :path => path }}
         it 'should fail' do
-          expect { catalogue }.to raise_error(Puppet::Error, /is not an absolute path/)
+          expect { should }.to raise_error(Puppet::Error, /is not an absolute path/)
         end
       end
     end
@@ -134,7 +235,7 @@ describe 'concat', :type => :define do
       let(:title) { '/etc/foo.bar' }
       let(:params) {{ :owner => false }}
       it 'should fail' do
-        expect { catalogue }.to raise_error(Puppet::Error, /is not a string/)
+        expect { should }.to raise_error(Puppet::Error, /is not a string/)
       end
     end
   end # owner =>
@@ -148,7 +249,7 @@ describe 'concat', :type => :define do
       let(:title) { '/etc/foo.bar' }
       let(:params) {{ :group => false }}
       it 'should fail' do
-        expect { catalogue }.to raise_error(Puppet::Error, /is not a string/)
+        expect { should }.to raise_error(Puppet::Error, /is not a string/)
       end
     end
   end # group =>
@@ -162,7 +263,7 @@ describe 'concat', :type => :define do
       let(:title) { '/etc/foo.bar' }
       let(:params) {{ :mode => false }}
       it 'should fail' do
-        expect { catalogue }.to raise_error(Puppet::Error, /is not a string/)
+        expect { should }.to raise_error(Puppet::Error, /is not a string/)
       end
     end
   end # mode =>
@@ -190,11 +291,27 @@ describe 'concat', :type => :define do
       let(:title) { '/etc/foo.bar' }
       let(:params) {{ :warn => 123 }}
       it 'should fail' do
-        expect { catalogue }.to raise_error(Puppet::Error, /is not a string or boolean/)
+        expect { should }.to raise_error(Puppet::Error, /is not a string or boolean/)
       end
     end
   end # warn =>
 
+  context 'force =>' do
+    [true, false].each do |force|
+      context force do
+        it_behaves_like 'concat', '/etc/foo.bar', { :force => force }
+      end
+    end
+
+    context '123' do
+      let(:title) { '/etc/foo.bar' }
+      let(:params) {{ :force => 123 }}
+      it 'should fail' do
+        expect { should }.to raise_error(Puppet::Error, /is not a boolean/)
+      end
+    end
+  end # force =>
+
   context 'backup =>' do
     context 'reverse' do
       it_behaves_like 'concat', '/etc/foo.bar', { :backup => 'reverse' }
@@ -212,7 +329,7 @@ describe 'concat', :type => :define do
       let(:title) { '/etc/foo.bar' }
       let(:params) {{ :backup => [] }}
       it 'should fail' do
-        expect { catalogue }.to raise_error(Puppet::Error, /backup must be string or bool/)
+        expect { should }.to raise_error(Puppet::Error, /backup must be string or bool/)
       end
     end
   end # backup =>
@@ -228,7 +345,7 @@ describe 'concat', :type => :define do
       let(:title) { '/etc/foo.bar' }
       let(:params) {{ :replace => 123 }}
       it 'should fail' do
-        expect { catalogue }.to raise_error(Puppet::Error, /is not a boolean/)
+        expect { should }.to raise_error(Puppet::Error, /is not a boolean/)
       end
     end
   end # replace =>
@@ -244,7 +361,7 @@ describe 'concat', :type => :define do
       let(:title) { '/etc/foo.bar' }
       let(:params) {{ :order => 'invalid' }}
       it 'should fail' do
-        expect { catalogue }.to raise_error(Puppet::Error, /#{Regexp.escape('does not match "^alpha$|^numeric$"')}/)
+        expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape('does not match "^alpha$|^numeric$"')}/)
       end
     end
   end # order =>
@@ -260,7 +377,7 @@ describe 'concat', :type => :define do
       let(:title) { '/etc/foo.bar' }
       let(:params) {{ :ensure_newline => 123 }}
       it 'should fail' do
-        expect { catalogue }.to raise_error(Puppet::Error, /is not a boolean/)
+        expect { should }.to raise_error(Puppet::Error, /is not a boolean/)
       end
     end
   end # ensure_newline =>
@@ -275,9 +392,24 @@ describe 'concat', :type => :define do
         let(:title) { '/etc/foo.bar' }
         let(:params) {{ :validate_cmd => cmd }}
         it 'should fail' do
-          expect { catalogue }.to raise_error(Puppet::Error, /\$validate_cmd must be a string/)
+          expect { should }.to raise_error(Puppet::Error, /\$validate_cmd must be a string/)
         end
       end
     end
   end # validate_cmd =>
+
+  describe 'deprecated parameter' do
+    context 'gnu =>' do
+      context 'foo' do
+        it_behaves_like 'concat', '/etc/foo.bar', { :gnu => 'foo'}
+
+        it 'should create a warning' do
+          skip('rspec-puppet support for testing warning()')
+        end
+      end
+    end
+  end
+
 end
+
+# vim:sw=2:ts=2:expandtab:textwidth=79