Release prep v9.1.0
[puppet-modules/puppetlabs-apt.git] / spec / acceptance / apt_spec.rb
index f89976e4000cbbf53dda2340c5159695b52c7dc0..802858e8e24ad59596707eb8ce9d3a417ace19bd 100644 (file)
-require 'spec_helper_acceptance'
-
-describe 'apt class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
-
-  context 'reset' do
-    it 'fixes the sources.list' do
-      shell('cp /etc/apt/sources.list /tmp')
-    end
-  end
-
-  context 'always_apt_update => true' do
-    it 'should work with no errors' do
-      pp = <<-EOS
-      class { 'apt': always_apt_update => true }
-      EOS
+# frozen_string_literal: true
 
-      apply_manifest(pp, :catch_failures => true) do |r|
-        expect(r.stdout).to match(/apt_update/)
-      end
-    end
-  end
-  context 'always_apt_update => false' do
-    it 'should work with no errors' do
-      pp = <<-EOS
-      class { 'apt': always_apt_update => false }
-      EOS
-
-      apply_manifest(pp, :catch_failures => true) do |r|
-        expect(r.stdout).to_not match(/apt_update/)
-      end
-    end
-  end
-
-  # disable_keys drops in a 99unauth file to ignore keys in
-  # other files.
-  context 'disable_keys => true' do
-    it 'should work with no errors' do
-      pp = <<-EOS
-      class { 'apt': disable_keys => true }
-      EOS
-
-      apply_manifest(pp, :catch_failures => true)
-    end
-
-    describe file('/etc/apt/apt.conf.d/99unauth') do
-      it { should be_file }
-      it { should contain 'APT::Get::AllowUnauthenticated 1;' }
-    end
-  end
-  context 'disable_keys => false' do
-    it 'should work with no errors' do
-      pp = <<-EOS
-      class { 'apt': disable_keys => false }
-      EOS
-
-      apply_manifest(pp, :catch_failures => true)
-    end
-
-    describe file('/etc/apt/apt.conf.d/99unauth') do
-      it { should_not be_file }
-    end
-  end
+require 'spec_helper_acceptance'
 
-  # proxy_host sets the proxy to use for transfers.
-  # proxy_port sets the proxy port to use.
-  context 'proxy settings' do
-    it 'should work with no errors' do
-      pp = <<-EOS
-      class { 'apt': 
-        proxy_host => 'localhost',
-        proxy_port => '7042',
+everything_everything_pp = <<-MANIFEST
+      $sources = {
+        'puppetlabs' => {
+          'ensure'   => present,
+          'location' => 'http://apt.puppetlabs.com',
+          'repos'    => 'main',
+          'key'      => {
+            'id'     => '6F6B15509CF8E59E6E469F327F438280EF8D349F',
+            'server' => 'keyserver.ubuntu.com',
+          },
+        },
       }
-      EOS
-
-      apply_manifest(pp, :catch_failures => true)
-    end
-
-    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
-    it 'creates a fake apt file' do
-      shell('touch /etc/apt/sources.list.d/fake.list')
-      shell('echo "deb fake" >> /etc/apt/sources.list')
-    end
-    it 'purge_sources_list and purge_sources_list_d => true' do
-      pp = <<-EOS
       class { 'apt':
-        purge_sources_list   => true,
-        purge_sources_list_d => true,
-      }
-      EOS
-
-      apply_manifest(pp, :catch_failures => true)
-    end
-
-    describe file('/etc/apt/sources.list') do
-      it { should_not contain 'deb fake' }
-    end
-
-    describe file('/etc/apt/sources.list.d/fake.list') do
-      it { should_not be_file }
-    end
-  end
-  context 'proxy settings' do
-    it 'should work with no errors' do
-      pp = <<-EOS
-      class { 'apt': 
-        proxy_host => 'localhost',
-        proxy_port => '7042',
+        update => {
+          'frequency' => 'always',
+          'timeout'   => 400,
+          'tries'     => 3,
+        },
+        purge => {
+          'sources.list'   => true,
+          'sources.list.d' => true,
+          'preferences'    => true,
+          'preferences.d'  => true,
+          'apt.conf.d'     => true,
+        },
+        sources => $sources,
       }
-      EOS
-
-      apply_manifest(pp, :catch_failures => true)
-    end
-
-    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
-    context 'false' do
-      it 'creates a fake apt file' do
-        shell('touch /etc/apt/sources.list.d/fake.list')
-        shell('echo "deb fake" >> /etc/apt/sources.list')
-      end
-      it 'purge_sources_list and purge_sources_list_d => false' do
-        pp = <<-EOS
-        class { 'apt':
-          purge_sources_list   => false,
-          purge_sources_list_d => false,
-        }
-        EOS
-
-        apply_manifest(pp, :catch_failures => false)
-      end
+MANIFEST
 
-      describe file('/etc/apt/sources.list') do
-        it { should contain 'deb fake' }
-      end
-
-      describe file('/etc/apt/sources.list.d/fake.list') do
-        it { should be_file }
-      end
-    end
-
-    context 'true' do
-      it 'creates a fake apt file' do
-        shell('touch /etc/apt/sources.list.d/fake.list')
-        shell('echo "deb fake" >> /etc/apt/sources.list')
-      end
-      it 'purge_sources_list and purge_sources_list_d => true' do
-        pp = <<-EOS
-        class { 'apt':
-          purge_sources_list   => true,
-          purge_sources_list_d => true,
-        }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/sources.list') do
-        it { should_not contain 'deb fake' }
-      end
-
-      describe file('/etc/apt/sources.list.d/fake.list') do
-        it { should_not be_file }
-      end
-    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
+describe 'apt class' do
+  context 'with test start reset' do
+    it 'fixes the sources.list' do
+      run_shell('cp /etc/apt/sources.list /tmp')
     end
   end
 
-  context 'purge_preferences_d' do
-    context 'false' do
-      it 'creates a preferences file' do
-        shell('touch /etc/apt/preferences.d/test')
-      end
-
-      it 'should work with no errors' do
-        pp = <<-EOS
-        class { 'apt': purge_preferences_d => false }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/preferences.d/test') do
-        it { should be_file }
-      end
-    end
-    context 'true' do
-      it 'creates a preferences file' do
-        shell('touch /etc/apt/preferences.d/test')
-      end
-
-      it 'should work with no errors' do
-        pp = <<-EOS
-        class { 'apt': purge_preferences_d => true }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/preferences.d/test') do
-        it { should_not be_file }
+  context 'with all the things' do
+    it 'works with no errors' do
+      # Apply the manifest (Retry if timeout error is received from key pool)
+      retry_on_error_matching do
+        apply_manifest(everything_everything_pp, catch_failures: true)
       end
     end
-  end
 
-  context 'update_timeout' do
-    context '5000' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        class { 'apt': update_timeout => '5000' }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
+    it 'stills work' do
+      run_shell('apt-get update')
+      run_shell('apt-get -y --force-yes upgrade')
     end
   end
 
-  context 'reset' do
+  context 'with test end reset' do
     it 'fixes the sources.list' do
-      shell('cp /tmp/sources.list /etc/apt')
+      run_shell('cp /tmp/sources.list /etc/apt')
     end
   end
-
 end