Writing proxy configuration in apt.conf.d/01proxy.
[puppet-modules/puppetlabs-apt.git] / spec / acceptance / apt_spec.rb
index 5b7379fb12d8a12f34634cc86dcd7f8d16521219..f89976e4000cbbf53dda2340c5159695b52c7dc0 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
@@ -68,16 +68,19 @@ describe 'apt class' do
       pp = <<-EOS
       class { 'apt': 
         proxy_host => 'localhost',
-        proxy_port => '8080',
+        proxy_port => '7042',
       }
       EOS
 
       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:8080\";' }
+      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
 
@@ -110,16 +113,19 @@ describe 'apt class' do
       pp = <<-EOS
       class { 'apt': 
         proxy_host => 'localhost',
-        proxy_port => '8080',
+        proxy_port => '7042',
       }
       EOS
 
       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:8080\";' }
+      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
 
@@ -175,6 +181,50 @@ 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 be_file }
+        it 'is managed by Puppet' do
+          shell("grep 'Explanation' /etc/apt/preferences", {:acceptable_exit_codes => 0})
+        end
+      end
+    end
+  end
+
   context 'purge_preferences_d' do
     context 'false' do
       it 'creates a preferences file' do