Sometimes killing apt is too aggressive.
[puppet-modules/puppetlabs-apt.git] / spec / acceptance / apt_spec.rb
index 35a0d3e70b20ae17f3ed1e26413da5f502ba8245..97f00f1681abd418ebe5d00261b5d2556d7d5aef 100644 (file)
@@ -1,6 +1,6 @@
 require 'spec_helper_acceptance'
 
-describe 'apt class' do
+describe 'apt class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
 
   context 'reset' do
     it 'fixes the sources.list' do
@@ -15,7 +15,7 @@ describe 'apt class' do
       EOS
 
       apply_manifest(pp, :catch_failures => true) do |r|
-        expect(r.stdout).to match(/apt_update/)
+        expect(r.stdout).to match(/Exec\[apt_update\]/)
       end
     end
   end
@@ -26,7 +26,7 @@ describe 'apt class' do
       EOS
 
       apply_manifest(pp, :catch_failures => true) do |r|
-        expect(r.stdout).to_not match(/apt_update/)
+        expect(r.stdout).to_not match(/Exec\[apt_update\]/)
       end
     end
   end
@@ -75,10 +75,13 @@ describe 'apt class' do
       apply_manifest(pp, :catch_failures => true)
     end
 
-    describe file('/etc/apt/apt.conf.d/proxy') do
+    describe file('/etc/apt/apt.conf.d/01proxy') do
       it { should be_file }
       it { should contain 'Acquire::http::Proxy "http://localhost:7042\";' }
     end
+    describe file('/etc/apt/apt.conf.d/proxy') do
+      it { should_not be_file }
+    end
   end
 
   context 'purge_sources' do
@@ -117,10 +120,13 @@ describe 'apt class' do
       apply_manifest(pp, :catch_failures => true)
     end
 
-    describe file('/etc/apt/apt.conf.d/proxy') do
+    describe file('/etc/apt/apt.conf.d/01proxy') do
       it { should be_file }
       it { should contain 'Acquire::http::Proxy "http://localhost:7042\";' }
     end
+    describe file('/etc/apt/apt.conf.d/proxy') do
+      it { should_not be_file }
+    end
   end
 
   context 'purge_sources' do
@@ -175,6 +181,47 @@ describe 'apt class' do
     end
   end
 
+  context 'purge_preferences' do
+    context 'false' do
+      it 'creates a preferences file' do
+        shell("echo 'original' > /etc/apt/preferences")
+      end
+
+      it 'should work with no errors' do
+        pp = <<-EOS
+        class { 'apt': purge_preferences => false }
+        EOS
+
+        apply_manifest(pp, :catch_failures => true)
+      end
+
+      describe file('/etc/apt/preferences') do
+        it { should be_file }
+        it 'is not managed by Puppet' do
+          shell("grep 'original' /etc/apt/preferences", {:acceptable_exit_codes => 0})
+        end
+      end
+    end
+
+    context 'true' do
+      it 'creates a preferences file' do
+        shell('touch /etc/apt/preferences')
+      end
+
+      it 'should work with no errors' do
+        pp = <<-EOS
+        class { 'apt': purge_preferences => true }
+        EOS
+
+        apply_manifest(pp, :catch_failures => true)
+      end
+
+      describe file('/etc/apt/preferences') do
+        it { should_not be_file }
+      end
+    end
+  end
+
   context 'purge_preferences_d' do
     context 'false' do
       it 'creates a preferences file' do
@@ -224,6 +271,34 @@ describe 'apt class' do
     end
   end
 
+  context 'fancy_progress => true' do
+    it 'should work with no errors' do
+      pp = <<-EOS
+      class { 'apt': fancy_progress => true }
+      EOS
+
+      apply_manifest(pp, :catch_failures => true)
+    end
+
+    describe file('/etc/apt/apt.conf.d/99progressbar') do
+      it { should be_file }
+      it { should contain 'Dpkg::Progress-Fancy "1";' }
+    end
+  end
+  context 'fancy_progress => false' do
+    it 'should work with no errors' do
+      pp = <<-EOS
+      class { 'apt': fancy_progress => false }
+      EOS
+
+      apply_manifest(pp, :catch_failures => true)
+    end
+
+    describe file('/etc/apt/apt.conf.d/99progressbar') do
+      it { should_not be_file }
+    end
+  end
+
   context 'reset' do
     it 'fixes the sources.list' do
       shell('cp /tmp/sources.list /etc/apt')