Merge pull request #339 from mhaskel/test_overhaul
authorAshley Penney <ashley.penney@puppetlabs.com>
Wed, 6 Aug 2014 16:25:14 +0000 (12:25 -0400)
committerAshley Penney <ashley.penney@puppetlabs.com>
Wed, 6 Aug 2014 16:25:14 +0000 (12:25 -0400)
Test overhaul

28 files changed:
manifests/pin.pp
manifests/ppa.pp
manifests/unattended_upgrades.pp
spec/acceptance/apt_builddep_spec.rb [deleted file]
spec/acceptance/apt_key_provider_spec.rb
spec/acceptance/apt_key_spec.rb [deleted file]
spec/acceptance/apt_ppa_spec.rb [deleted file]
spec/acceptance/apt_source_spec.rb [deleted file]
spec/acceptance/apt_spec.rb
spec/acceptance/backports_spec.rb [deleted file]
spec/acceptance/class_spec.rb
spec/acceptance/conf_spec.rb [deleted file]
spec/acceptance/force_spec.rb [deleted file]
spec/acceptance/pin_spec.rb [deleted file]
spec/acceptance/release_spec.rb [deleted file]
spec/acceptance/unattended_upgrade_spec.rb [deleted file]
spec/acceptance/unsupported_spec.rb [deleted file]
spec/classes/apt_spec.rb
spec/classes/init_spec.rb [deleted file]
spec/classes/unattended_upgrades_spec.rb
spec/defines/builddep_spec.rb
spec/defines/conf_spec.rb
spec/defines/force_spec.rb
spec/defines/hold_spec.rb
spec/defines/key_spec.rb
spec/defines/pin_spec.rb
spec/defines/ppa_spec.rb
spec/defines/source_spec.rb

index 2ce81fd6bb292fce2eae61e60bf82b2e01bfa048..54961ec8ddfa7e43fae6109efc44daa414e5c89d 100644 (file)
@@ -16,7 +16,6 @@ define apt::pin(
   $originator      = '', # o=
   $label           = ''  # l=
 ) {
-
   include apt::params
 
   $preferences_d = $apt::params::preferences_d
@@ -35,7 +34,7 @@ define apt::pin(
   $pin_release = join($pin_release_array, '')
 
   # Read the manpage 'apt_preferences(5)', especially the chapter
-  # 'Thea Effect of APT Preferences' to understand the following logic
+  # 'The Effect of APT Preferences' to understand the following logic
   # and the difference between specific and general form
   if is_array($packages) {
     $packages_string = join($packages, ' ')
@@ -44,24 +43,17 @@ define apt::pin(
   }
 
   if $packages_string != '*' { # specific form
-
     if ( $pin_release != '' and ( $origin != '' or $version != '' )) or
-      ( $origin != '' and ( $pin_release != '' or $version != '' )) or
       ( $version != '' and ( $pin_release != '' or $origin != '' )) {
       fail('parameters release, origin, and version are mutually exclusive')
     }
-
   } else { # general form
-
     if $version != '' {
       fail('parameter version cannot be used in general form')
     }
-
-    if ( $pin_release != '' and $origin != '' ) or
-      ( $origin != '' and $pin_release != '' ) {
-      fail('parmeters release and origin are mutually exclusive')
+    if ( $pin_release != '' and $origin != '' ) {
+      fail('parameters release and origin are mutually exclusive')
     }
-
   }
 
 
index 27edff80b21864539f1ca9eb86cfa6cc0f2a8979..5f5c6ae57421993afa99705d3d63b6de081fd066 100644 (file)
@@ -69,9 +69,6 @@ define apt::ppa(
 
     file { "${sources_list_d}/${sources_list_d_filename}":
         ensure => 'absent',
-        mode   => '0644',
-        owner  => 'root',
-        group  => 'root',
         notify => Exec['apt_update'],
     }
   }
index 7e3ccc44b07637ee1a21d86b88f68a7eb03d516d..2f75d5dd19aef4eba17a96bfbf80cd6ba3b163a1 100644 (file)
@@ -52,18 +52,21 @@ class apt::unattended_upgrades (
     ensure => present,
   }
 
-  File {
+  file { '/etc/apt/apt.conf.d/50unattended-upgrades':
     ensure  => file,
     owner   => 'root',
     group   => 'root',
     mode    => '0644',
+    content => template('apt/50unattended-upgrades.erb'),
     require => Package['unattended-upgrades'],
   }
 
-  file {
-    '/etc/apt/apt.conf.d/50unattended-upgrades':
-      content => template('apt/50unattended-upgrades.erb');
-    '/etc/apt/apt.conf.d/10periodic':
-      content => template('apt/10periodic.erb');
+  file { '/etc/apt/apt.conf.d/10periodic':
+    ensure  => file,
+    owner   => 'root',
+    group   => 'root',
+    mode    => '0644',
+    content => template('apt/10periodic.erb'),
+    require => Package['unattended-upgrades'],
   }
 }
diff --git a/spec/acceptance/apt_builddep_spec.rb b/spec/acceptance/apt_builddep_spec.rb
deleted file mode 100644 (file)
index 1e35e4a..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-require 'spec_helper_acceptance'
-
-describe 'apt::builddep', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
-
-  context 'reset' do
-    it 'removes packages' do
-      shell('apt-get -y remove znc')
-      shell('apt-get -y remove g++')
-    end
-  end
-
-  context 'apt::builddep' do
-    it 'should work with no errors' do
-      pp = <<-EOS
-      include '::apt'
-      apt::builddep { 'znc': }
-      EOS
-
-      apply_manifest(pp, :catch_failures => true)
-    end
-
-    describe 'should install g++ as a dependency' do
-      describe package('g++') do
-        it { should be_installed }
-      end
-    end
-  end
-
-  context 'reset' do
-    it 'removes packages' do
-      shell('apt-get -y remove znc')
-      shell('apt-get -y remove g++')
-    end
-  end
-
-end
index d9c2c0d7518c8534b8c89e12933926277124e2cf..497c6edb53d2bdb80d1af336975ab52663360d79 100644 (file)
@@ -7,7 +7,7 @@ CENTOS_GPG_KEY_ID       = 'C105B9DE'
 CENTOS_REPO_URL         = 'ftp.cvut.cz/centos'
 CENTOS_GPG_KEY_FILE     = 'RPM-GPG-KEY-CentOS-6'
 
-describe 'apt_key', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
+describe 'apt_key' do
   before(:each) do
     shell("apt-key del #{PUPPETLABS_GPG_KEY_ID}",
           :acceptable_exit_codes => [0,1,2])
diff --git a/spec/acceptance/apt_key_spec.rb b/spec/acceptance/apt_key_spec.rb
deleted file mode 100644 (file)
index 9f2ba39..0000000
+++ /dev/null
@@ -1,200 +0,0 @@
-require 'spec_helper_acceptance'
-
-describe 'apt::key', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
-  context 'apt::key' do
-    it 'should work with no errors' do
-      pp = <<-EOS
-      include '::apt'
-      apt::key { 'puppetlabs':
-        key        => '4BD6EC30',
-        key_server => 'pgp.mit.edu',
-      }
-
-      apt::key { 'jenkins':
-        key        => 'D50582E6',
-        key_source => 'http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key',
-      }
-      EOS
-
-      shell('apt-key del 4BD6EC30', :acceptable_exit_codes => [0,1,2])
-      shell('apt-key del D50582E6', :acceptable_exit_codes => [0,1,2])
-      apply_manifest(pp, :catch_failures => true)
-    end
-
-    describe 'keys should exist' do
-      it 'finds puppetlabs key' do
-        shell('apt-key list | grep 4BD6EC30')
-      end
-      it 'finds jenkins key' do
-        shell('apt-key list | grep D50582E6')
-      end
-    end
-  end
-  context 'ensure' do
-    context 'absent' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include '::apt'
-        apt::key { 'puppetlabs':
-          ensure     => absent,
-          key        => '4BD6EC30',
-          key_server => 'pgp.mit.edu',
-        }
-
-        apt::key { 'jenkins':
-          ensure     => absent,
-          key        => 'D50582E6',
-          key_source => 'http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key',
-        }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe 'keys shouldnt exist' do
-        it 'fails' do
-          shell('apt-key list | grep 4BD6EC30', :acceptable_exit_codes => [1])
-        end
-        it 'fails' do
-          shell('apt-key list | grep D50582E6', :acceptable_exit_codes => [1])
-        end
-      end
-    end
-  end
-
-  context 'reset' do
-    it 'clean up keys' do
-      shell('apt-key del 4BD6EC30', :acceptable_exit_codes => [0,1,2])
-      shell('apt-key del D50582E6', :acceptable_exit_codes => [0,1,2])
-    end
-  end
-
-  context 'key options' do
-    context 'key_content' do
-
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include '::apt'
-        apt::key { 'puppetlabs':
-          key         => '4BD6EC30',
-          key_content => '-----BEGIN PGP PUBLIC KEY BLOCK-----
-          Version: GnuPG v1.4.12 (GNU/Linux)
-          Comment: GPGTools - http://gpgtools.org
-
-          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
-            =a34C
-          -----END PGP PUBLIC KEY BLOCK-----
-          ',
-        }
-        EOS
-
-        shell('apt-key del 4BD6EC30', :acceptable_exit_codes => [0,1,2])
-        apply_manifest(pp, :catch_failures => true)
-      end
-    end
-    describe 'keys should exist' do
-      it 'finds puppetlabs key' do
-        shell('apt-key list | grep 4BD6EC30')
-      end
-    end
-
-    context 'key_source' do
-
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include '::apt'
-        apt::key { 'puppetlabs':
-          key        => '4BD6EC30',
-          key_source => 'http://apt.puppetlabs.com/pubkey.gpg',
-        }
-        EOS
-
-        shell('apt-key del 4BD6EC30', :acceptable_exit_codes => [0,1,2])
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe 'keys should exist' do
-        it 'finds puppetlabs key' do
-          shell('apt-key list | grep 4BD6EC30')
-        end
-      end
-    end
-
-    context 'key_options' do
-
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include '::apt'
-        apt::key { 'puppetlabs':
-          key        => '4BD6EC30',
-          key_source => 'http://apt.puppetlabs.com/pubkey.gpg',
-          key_options => 'debug'
-        }
-        EOS
-
-        shell('apt-key del 4BD6EC30', :acceptable_exit_codes => [0,1,2])
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe 'keys should exist' do
-        it 'finds puppetlabs key' do
-          shell('apt-key list | grep 4BD6EC30')
-        end
-      end
-    end
-  end
-
-end
diff --git a/spec/acceptance/apt_ppa_spec.rb b/spec/acceptance/apt_ppa_spec.rb
deleted file mode 100644 (file)
index b665c5c..0000000
+++ /dev/null
@@ -1,138 +0,0 @@
-require 'spec_helper_acceptance'
-
-if fact('operatingsystem') == 'Ubuntu'
-  describe 'apt::ppa', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
-
-    context 'reset' do
-      it 'removes ppa' do
-        shell('rm /etc/apt/sources.list.d/canonical-kernel-team-ppa-*', :acceptable_exit_codes => [0,1,2])
-        shell('rm /etc/apt/sources.list.d/raravena80-collectd5-*', :acceptable_exit_codes => [0,1,2])
-      end
-    end
-
-    context 'adding a ppa that doesnt exist' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include '::apt'
-        apt::ppa { 'ppa:canonical-kernel-team/ppa': }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe 'contains the source file' do
-        it 'contains a kernel ppa source' do
-          shell('ls /etc/apt/sources.list.d/canonical-kernel-team-ppa-*', :acceptable_exit_codes => [0])
-        end
-      end
-    end
-
-    context 'reading a removed ppa.' do
-      it 'setup' do
-        # This leaves a blank file
-        shell('echo > /etc/apt/sources.list.d/raravena80-collectd5-$(lsb_release -c -s).list')
-      end
-
-      it 'should read it successfully' do
-        pp = <<-EOS
-        include '::apt'
-        apt::ppa { 'ppa:raravena80/collectd5': }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-    end
-
-    context 'reset' do
-      it 'removes added ppas' do
-        shell('rm /etc/apt/sources.list.d/canonical-kernel-team-ppa-*')
-        shell('rm /etc/apt/sources.list.d/raravena80-collectd5-*')
-      end
-    end
-
-    context 'ensure' do
-      context 'present' do
-        it 'works without failure' do
-          pp = <<-EOS
-          include '::apt'
-          apt::ppa { 'ppa:canonical-kernel-team/ppa': ensure => present }
-          EOS
-
-          apply_manifest(pp, :catch_failures => true)
-        end
-
-        describe 'contains the source file' do
-          it 'contains a kernel ppa source' do
-            shell('ls /etc/apt/sources.list.d/canonical-kernel-team-ppa-*', :acceptable_exit_codes => [0])
-          end
-        end
-      end
-    end
-
-    context 'ensure' do
-      context 'absent' do
-        it 'works without failure' do
-          pp = <<-EOS
-          include '::apt'
-          apt::ppa { 'ppa:canonical-kernel-team/ppa': ensure => absent }
-          EOS
-
-          apply_manifest(pp, :catch_failures => true)
-        end
-
-        describe 'doesnt contain the source file' do
-          it 'fails' do
-            shell('ls /etc/apt/sources.list.d/canonical-kernel-team-ppa-*', :acceptable_exit_codes => [2])
-          end
-        end
-      end
-    end
-
-    context 'release' do
-      context 'precise' do
-        it 'works without failure' do
-          pp = <<-EOS
-          include '::apt'
-          apt::ppa { 'ppa:canonical-kernel-team/ppa':
-            ensure  => present,
-            release => precise,
-          }
-          EOS
-
-          shell('rm -rf /etc/apt/sources.list.d/canonical-kernel-team-ppa*', :acceptable_exit_codes => [0,1,2])
-          apply_manifest(pp, :catch_failures => true)
-        end
-
-        describe file('/etc/apt/sources.list.d/canonical-kernel-team-ppa-precise.list') do
-          it { should be_file }
-        end
-      end
-    end
-
-    context 'options' do
-      context '-y', :unless => default[:platform].match(/10\.04/) do
-        it 'works without failure' do
-          pp = <<-EOS
-          include '::apt'
-          apt::ppa { 'ppa:canonical-kernel-team/ppa':
-            ensure  => present,
-            release => precise,
-            options => '-y',
-          }
-          EOS
-
-          shell('rm -rf /etc/apt/sources.list.d/canonical-kernel-team-ppa*', :acceptable_exit_codes => [0,1,2])
-          apply_manifest(pp, :catch_failures => true)
-        end
-
-        describe file('/etc/apt/sources.list.d/canonical-kernel-team-ppa-precise.list') do
-          it { should be_file }
-        end
-      end
-    end
-
-    context 'reset' do
-      it { shell('rm -rf /etc/apt/sources.list.d/canonical-kernel-team-ppa*', :acceptable_exit_codes => [0,1,2]) }
-    end
-  end
-end
diff --git a/spec/acceptance/apt_source_spec.rb b/spec/acceptance/apt_source_spec.rb
deleted file mode 100644 (file)
index c2d076c..0000000
+++ /dev/null
@@ -1,326 +0,0 @@
-require 'spec_helper_acceptance'
-
-describe 'apt::source', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
-
-  context 'apt::source' do
-    context 'ensure => present' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include '::apt'
-        apt::source { 'puppetlabs':
-          ensure     => present,
-          location   => 'http://apt.puppetlabs.com',
-          repos      => 'main',
-          key        => '4BD6EC30',
-          key_server => 'pgp.mit.edu',
-        }
-        EOS
-
-        shell('apt-key del 4BD6EC30', :acceptable_exit_codes => [0,1,2])
-        shell('rm /etc/apt/sources.list.d/puppetlabs.list', :acceptable_exit_codes => [0,1,2])
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe 'key should exist' do
-        it 'finds puppetlabs key' do
-          shell('apt-key list | grep 4BD6EC30', :acceptable_exit_codes => [0])
-        end
-      end
-
-      describe file('/etc/apt/sources.list.d/puppetlabs.list') do
-        it { should be_file }
-      end
-    end
-
-    context 'ensure => absent' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include '::apt'
-        apt::source { 'puppetlabs':
-          ensure     => absent,
-          location   => 'http://apt.puppetlabs.com',
-          repos      => 'main',
-          key        => '4BD6EC30',
-          key_server => 'pgp.mit.edu',
-        }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      # The key should remain -we don't delete those when deleting a source.
-      describe 'key should exist' do
-        it 'finds puppetlabs key' do
-          shell('apt-key list | grep 4BD6EC30', :acceptable_exit_codes => [0])
-        end
-      end
-      describe file('/etc/apt/sources.list.d/puppetlabs.list') do
-        it { should_not be_file }
-      end
-    end
-
-  end
-
-  context 'release' do
-    context 'test' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include '::apt'
-        apt::source { 'puppetlabs':
-          ensure     => present,
-          location   => 'http://apt.puppetlabs.com',
-          repos      => 'main',
-          key        => '4BD6EC30',
-          key_server => 'pgp.mit.edu',
-          release    => 'precise',
-        }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/sources.list.d/puppetlabs.list') do
-        it { should be_file }
-        it { should contain 'deb http://apt.puppetlabs.com precise main' }
-      end
-    end
-  end
-
-  context 'include_src' do
-    context 'true' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include '::apt'
-        apt::source { 'puppetlabs':
-          ensure      => present,
-          location    => 'http://apt.puppetlabs.com',
-          repos       => 'main',
-          key         => '4BD6EC30',
-          key_server  => 'pgp.mit.edu',
-          include_src => true,
-        }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/sources.list.d/puppetlabs.list') do
-        it { should be_file }
-        it { should contain 'deb-src http://apt.puppetlabs.com' }
-      end
-    end
-
-    context 'false' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include '::apt'
-        apt::source { 'puppetlabs':
-          ensure      => present,
-          location    => 'http://apt.puppetlabs.com',
-          repos       => 'main',
-          key         => '4BD6EC30',
-          key_server  => 'pgp.mit.edu',
-          include_src => false,
-        }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/sources.list.d/puppetlabs.list') do
-        it { should be_file }
-        it { should_not contain 'deb-src http://apt.puppetlabs.com' }
-      end
-    end
-  end
-
-  context 'required_packages' do
-    context 'vim' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include '::apt'
-        apt::source { 'puppetlabs':
-          ensure             => present,
-          location           => 'http://apt.puppetlabs.com',
-          repos              => 'main',
-          key                => '4BD6EC30',
-          key_server         => 'pgp.mit.edu',
-          required_packages  => 'vim',
-        }
-        EOS
-
-        shell('apt-get -y remove vim')
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe package('vim') do
-        it { should be_installed }
-      end
-    end
-  end
-
-  context 'key content' do
-    context 'giant key' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include '::apt'
-        apt::source { 'puppetlabs':
-          ensure      => present,
-          location    => 'http://apt.puppetlabs.com',
-          repos       => 'main',
-          key         => '4BD6EC30',
-          key_content => '-----BEGIN PGP PUBLIC KEY BLOCK-----
-          Version: GnuPG v1.4.12 (GNU/Linux)
-          Comment: GPGTools - http://gpgtools.org
-
-          mQINBEw3u0ABEAC1+aJQpU59fwZ4mxFjqNCgfZgDhONDSYQFMRnYC1dzBpJHzI6b
-          fUBQeaZ8rh6N4kZ+wq1eL86YDXkCt4sCvNTP0eF2XaOLbmxtV9bdpTIBep9bQiKg
-          5iZaz+brUZlFk/MyJ0Yz//VQ68N1uvXccmD6uxQsVO+gx7rnarg/BGuCNaVtGwy+
-          S98g8Begwxs9JmGa8pMCcSxtC7fAfAEZ02cYyrw5KfBvFI3cHDdBqrEJQKwKeLKY
-          GHK3+H1TM4ZMxPsLuR/XKCbvTyl+OCPxU2OxPjufAxLlr8BWUzgJv6ztPe9imqpH
-          Ppp3KuLFNorjPqWY5jSgKl94W/CO2x591e++a1PhwUn7iVUwVVe+mOEWnK5+Fd0v
-          VMQebYCXS+3dNf6gxSvhz8etpw20T9Ytg4EdhLvCJRV/pYlqhcq+E9le1jFOHOc0
-          Nc5FQweUtHGaNVyn8S1hvnvWJBMxpXq+Bezfk3X8PhPT/l9O2lLFOOO08jo0OYiI
-          wrjhMQQOOSZOb3vBRvBZNnnxPrcdjUUm/9cVB8VcgI5KFhG7hmMCwH70tpUWcZCN
-          NlI1wj/PJ7Tlxjy44f1o4CQ5FxuozkiITJvh9CTg+k3wEmiaGz65w9jRl9ny2gEl
-          f4CR5+ba+w2dpuDeMwiHJIs5JsGyJjmA5/0xytB7QvgMs2q25vWhygsmUQARAQAB
-          tEdQdXBwZXQgTGFicyBSZWxlYXNlIEtleSAoUHVwcGV0IExhYnMgUmVsZWFzZSBL
-          ZXkpIDxpbmZvQHB1cHBldGxhYnMuY29tPokCPgQTAQIAKAUCTDe7QAIbAwUJA8Jn
-          AAYLCQgHAwIGFQgCCQoLBBYCAwECHgECF4AACgkQEFS3okvW7DAZaw//aLmE/eob
-          pXpIUVyCUWQxEvPtM/h/SAJsG3KoHN9u216ews+UHsL/7F91ceVXQQdD2e8CtYWF
-          eLNM0RSM9i/KM60g4CvIQlmNqdqhi1HsgGqInZ72/XLAXun0gabfC36rLww2kel+
-          aMpRf58SrSuskY321NnMEJl4OsHV2hfNtAIgw2e/zm9RhoMpGKxoHZCvFhnP7u2M
-          2wMq7iNDDWb6dVsLpzdlVf242zCbubPCxxQXOpA56rzkUPuJ85mdVw4i19oPIFIZ
-          VL5owit1SxCOxBg4b8oaMS36hEl3qtZG834rtLfcqAmqjhx6aJuJLOAYN84QjDEU
-          3NI5IfNRMvluIeTcD4Dt5FCYahN045tW1Rc6s5GAR8RW45GYwQDzG+kkkeeGxwEh
-          qCW7nOHuwZIoVJufNhd28UFn83KGJHCQt4NBBr3K5TcY6bDQEIrpSplWSDBbd3p1
-          IaoZY1WSDdP9OTVOSbsz0JiglWmUWGWCdd/CMSW/D7/3VUOJOYRDwptvtSYcjJc8
-          1UV+1zB+rt5La/OWe4UOORD+jU1ATijQEaFYxBbqBBkFboAEXq9btRQyegqk+eVp
-          HhzacP5NYFTMThvHuTapNytcCso5au/cMywqCgY1DfcMJyjocu4bCtrAd6w4kGKN
-          MUdwNDYQulHZDI+UjJInhramyngdzZLjdeGJARwEEAECAAYFAkw3wEYACgkQIVr+
-          UOQUcDKvEwgAoBuOPnPioBwYp8oHVPTo/69cJn1225kfraUYGebCcrRwuoKd8Iyh
-          R165nXYJmD8yrAFBk8ScUVKsQ/pSnqNrBCrlzQD6NQvuIWVFegIdjdasrWX6Szj+
-          N1OllbzIJbkE5eo0WjCMEKJVI/GTY2AnTWUAm36PLQC5HnSATykqwxeZDsJ/s8Rc
-          kd7+QN5sBVytG3qb45Q7jLJpLcJO6KYH4rz9ZgN7LzyyGbu9DypPrulADG9OrL7e
-          lUnsGDG4E1M8Pkgk9Xv9MRKao1KjYLD5zxOoVtdeoKEQdnM+lWMJin1XvoqJY7FT
-          DJk6o+cVqqHkdKL+sgsscFVQljgCEd0EgIkCHAQQAQgABgUCTPlA6QAKCRBcE9bb
-          kwUuAxdYD/40FxAeNCYByxkr/XRT0gFT+NCjPuqPWCM5tf2NIhSapXtb2+32WbAf
-          DzVfqWjC0G0RnQBve+vcjpY4/rJu4VKIDGIT8CtnKOIyEcXTNFOehi65xO4ypaei
-          BPSb3ip3P0of1iZZDQrNHMW5VcyL1c+PWT/6exXSGsePtO/89tc6mupqZtC05f5Z
-          XG4jswMF0U6Q5s3S0tG7Y+oQhKNFJS4sH4rHe1o5CxKwNRSzqccA0hptKy3MHUZ2
-          +zeHzuRdRWGjb2rUiVxnIvPPBGxF2JHhB4ERhGgbTxRZ6wZbdW06BOE8r7pGrUpU
-          fCw/WRT3gGXJHpGPOzFAvr3Xl7VcDUKTVmIajnpd3SoyD1t2XsvJlSQBOWbViucH
-          dvE4SIKQ77vBLRlZIoXXVb6Wu7Vq+eQs1ybjwGOhnnKjz8llXcMnLzzN86STpjN4
-          qGTXQy/E9+dyUP1sXn3RRwb+ZkdI77m1YY95QRNgG/hqh77IuWWg1MtTSgQnP+F2
-          7mfo0/522hObhdAe73VO3ttEPiriWy7tw3bS9daP2TAVbYyFqkvptkBb1OXRUSzq
-          UuWjBmZ35UlXjKQsGeUHlOiEh84aondF90A7gx0X/ktNIPRrfCGkHJcDu+HVnR7x
-          Kk+F0qb9+/pGLiT3rqeQTr8fYsb4xLHT7uEg1gVFB1g0kd+RQHzV74kCPgQTAQIA
-          KAIbAwYLCQgHAwIGFQgCCQoLBBYCAwECHgECF4AFAk/x5PoFCQtIMjoACgkQEFS3
-          okvW7DAIKQ/9HvZyf+LHVSkCk92Kb6gckniin3+5ooz67hSr8miGBfK4eocqQ0H7
-          bdtWjAILzR/IBY0xj6OHKhYP2k8TLc7QhQjt0dRpNkX+Iton2AZryV7vUADreYz4
-          4B0bPmhiE+LL46ET5IThLKu/KfihzkEEBa9/t178+dO9zCM2xsXaiDhMOxVE32gX
-          vSZKP3hmvnK/FdylUY3nWtPedr+lHpBLoHGaPH7cjI+MEEugU3oAJ0jpq3V8n4w0
-          jIq2V77wfmbD9byIV7dXcxApzciK+ekwpQNQMSaceuxLlTZKcdSqo0/qmS2A863Y
-          ZQ0ZBe+Xyf5OI33+y+Mry+vl6Lre2VfPm3udgR10E4tWXJ9Q2CmG+zNPWt73U1FD
-          7xBI7PPvOlyzCX4QJhy2Fn/fvzaNjHp4/FSiCw0HvX01epcersyun3xxPkRIjwwR
-          M9m5MJ0o4hhPfa97zibXSh8XXBnosBQxeg6nEnb26eorVQbqGx0ruu/W2m5/JpUf
-          REsFmNOBUbi8xlKNS5CZypH3Zh88EZiTFolOMEh+hT6s0l6znBAGGZ4m/Unacm5y
-          DHmg7unCk4JyVopQ2KHMoqG886elu+rm0ASkhyqBAk9sWKptMl3NHiYTRE/m9VAk
-          ugVIB2pi+8u84f+an4Hml4xlyijgYu05pqNvnLRyJDLd61hviLC8GYU=
-          =a34C
-          -----END PGP PUBLIC KEY BLOCK-----',
-        }
-        EOS
-
-        shell('apt-key del 4BD6EC30', :acceptable_exit_codes => [0,1,2])
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/sources.list.d/puppetlabs.list') do
-        it { should be_file }
-      end
-      describe 'keys should exist' do
-        it 'finds puppetlabs key' do
-          shell('apt-key list | grep 4BD6EC30')
-        end
-      end
-    end
-  end
-
-  context 'key_source' do
-    context 'http://apt.puppetlabs.com/pubkey.gpg' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include '::apt'
-        apt::source { 'puppetlabs':
-          ensure     => present,
-          location   => 'http://apt.puppetlabs.com',
-          release    => 'precise',
-          repos      => 'main',
-          key        => '4BD6EC30',
-          key_source  => 'http://apt.puppetlabs.com/pubkey.gpg',
-        }
-        EOS
-
-        shell('apt-key del 4BD6EC30', :acceptable_exit_codes => [0,1,2])
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/sources.list.d/puppetlabs.list') do
-        it { should be_file }
-        it { should contain 'deb http://apt.puppetlabs.com precise main' }
-      end
-      describe 'keys should exist' do
-        it 'finds puppetlabs key' do
-          shell('apt-key list | grep 4BD6EC30')
-        end
-      end
-    end
-  end
-
-  context 'pin' do
-    context 'false' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include '::apt'
-        apt::source { 'puppetlabs':
-          ensure     => present,
-          location   => 'http://apt.puppetlabs.com',
-          repos      => 'main',
-          key        => '4BD6EC30',
-          key_server => 'pgp.mit.edu',
-          pin        => false,
-        }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/preferences.d/puppetlabs.pref') do
-        it { should_not be_file }
-      end
-    end
-    context 'true' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include '::apt'
-        apt::source { 'puppetlabs':
-          ensure     => present,
-          location   => 'http://apt.puppetlabs.com',
-          repos      => 'main',
-          key        => '4BD6EC30',
-          key_server => 'pgp.mit.edu',
-          pin        => true,
-        }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/preferences.d/puppetlabs.pref') do
-        it { should be_file }
-      end
-    end
-  end
-
-end
index 97f00f1681abd418ebe5d00261b5d2556d7d5aef..3c97421ab0c1eded83c1f161544924d0cb552ed3 100644 (file)
@@ -1,6 +1,6 @@
 require 'spec_helper_acceptance'
 
-describe 'apt class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
+describe 'apt class' do
 
   context 'reset' do
     it 'fixes the sources.list' do
@@ -8,294 +8,37 @@ describe 'apt class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')
     end
   end
 
-  context 'always_apt_update => true' do
+  context 'all the things' do
     it 'should work with no errors' do
-      pp = <<-EOS
-      class { 'apt': always_apt_update => true }
-      EOS
-
-      apply_manifest(pp, :catch_failures => true) do |r|
-        expect(r.stdout).to match(/Exec\[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(/Exec\[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
-
-  # 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',
-      }
-      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':
+        always_apt_update    => true,
+        disable_keys         => true,
         purge_sources_list   => true,
         purge_sources_list_d => true,
+        purge_preferences    => true,
+        purge_preferences_d  => true,
+        update_timeout       => '400',
+        update_tries         => '3',
+        sources              => {
+          'puppetlabs' => {
+            'ensure'     => present,
+            'location'   => 'http://apt.puppetlabs.com',
+            'repos'      => 'main',
+            'key'        => '4BD6EC30',
+            'key_server' => 'pgp.mit.edu',
+          }
+        },
+        fancy_progress       => 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',
-      }
-      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
-
-      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_not be_file }
-      end
-    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 }
-      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
-    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 }
+    it 'should still work' do
+      shell('apt-get update')
+      shell('apt-get -y upgrade')
     end
   end
 
diff --git a/spec/acceptance/backports_spec.rb b/spec/acceptance/backports_spec.rb
deleted file mode 100644 (file)
index 78f21fd..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-require 'spec_helper_acceptance'
-
-codename = fact('lsbdistcodename')
-case fact('operatingsystem')
-when 'Ubuntu'
-  repos = 'main universe multiverse restricted'
-when 'Debian'
-  repos = 'main contrib non-free'
-end
-
-describe 'apt::backports class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
-  context 'defaults' do
-    it 'should work with no errors' do
-      pp = <<-EOS
-      class { 'apt::backports': }
-      EOS
-
-      apply_manifest(pp, :catch_failures => true)
-    end
-  end
-
-  context 'release' do
-    it 'should work with no errors' do
-      pp = <<-EOS
-      class { 'apt::backports': release => '#{codename}' }
-      EOS
-
-      apply_manifest(pp, :catch_failures => true)
-    end
-
-    describe file('/etc/apt/sources.list.d/backports.list') do
-      it { should be_file }
-      it { should contain "#{codename}-backports #{repos}" }
-    end
-  end
-
-  context 'location' do
-    it 'should work with no errors' do
-      pp = <<-EOS
-      class { 'apt::backports': release => 'precise', location => 'http://localhost/ubuntu' }
-      EOS
-
-      apply_manifest(pp, :catch_failures => true)
-    end
-
-    describe file('/etc/apt/sources.list.d/backports.list') do
-      it { should be_file }
-      it { should contain "deb http://localhost/ubuntu precise-backports #{repos}" }
-    end
-  end
-
-  context 'pin_priority' do
-    it 'should work with no errors' do
-      pp = <<-EOS
-      class { 'apt::backports': pin_priority => 500, }
-      EOS
-
-      apply_manifest(pp, :catch_failures => true)
-    end
-    describe file('/etc/apt/preferences.d/backports.pref') do
-      it { should be_file }
-      it { should contain "Pin-Priority: 500" }
-    end
-  end
-
-  context 'reset' do
-    it 'deletes backport files' do
-      shell('rm -rf /etc/apt/sources.list.d/backports.list')
-      shell('rm -rf /etc/apt/preferences.d/backports.pref')
-    end
-  end
-
-end
index e5994498b903ffec47f075de8f17a9d157d1428a..f228e4c4565f7b8d825b52ca83a421d2c007c142 100644 (file)
@@ -1,6 +1,6 @@
 require 'spec_helper_acceptance'
 
-describe 'apt class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
+describe 'apt class' do
 
   context 'default parameters' do
     # Using puppet_apply as a helper
diff --git a/spec/acceptance/conf_spec.rb b/spec/acceptance/conf_spec.rb
deleted file mode 100644 (file)
index 8a8ed63..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-require 'spec_helper_acceptance'
-
-describe 'apt::conf define', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
-  context 'defaults' do
-    it 'should work with no errors' do
-      pp = <<-EOS
-      apt::conf { 'test':
-        content => 'test',
-      }
-      EOS
-
-      apply_manifest(pp, :catch_failures => true)
-    end
-
-    describe file('/etc/apt/apt.conf.d/50test') do
-      it { should be_file }
-      it { should contain 'test' }
-    end
-  end
-
-  context 'ensure' do
-    context 'absent' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        apt::conf { 'test':
-          ensure  => absent,
-          content => 'test',
-        }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/apt.conf.d/50test') do
-        it { should_not be_file }
-      end
-    end
-  end
-
-  context 'priority' do
-    context '99' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        apt::conf { 'test':
-          ensure   => present,
-          content  => 'test',
-          priority => '99',
-        }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/apt.conf.d/99test') do
-        it { should be_file }
-        it { should contain 'test' }
-      end
-    end
-  end
-
-  context 'cleanup' do
-    it 'deletes 99test' do
-      shell ('rm -rf /etc/apt/apt.conf.d/99test')
-    end
-  end
-end
diff --git a/spec/acceptance/force_spec.rb b/spec/acceptance/force_spec.rb
deleted file mode 100644 (file)
index 5f4dec3..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-require 'spec_helper_acceptance'
-
-codename = fact('lsbdistcodename')
-
-describe 'apt::force define', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
-  context 'defaults' do
-    it 'should work with no errors' do
-      pp = <<-EOS
-      include apt
-      apt::force { 'vim': }
-      EOS
-
-      shell('apt-get remove -y vim')
-      apply_manifest(pp, :catch_failures => true)
-    end
-
-    describe package('vim') do
-      it { should be_installed }
-    end
-  end
-
-  context 'release' do
-    it 'should work with no errors' do
-      pp = <<-EOS
-      include apt
-      apt::force { 'vim': release => '#{codename}' }
-      EOS
-
-      shell('apt-get remove -y vim')
-      apply_manifest(pp, :catch_failures => true) do |r|
-        expect(r.stdout).to match(/apt-get -y -t #{codename} install vim/)
-      end
-    end
-
-    describe package('vim') do
-      it { should be_installed }
-    end
-  end
-
-  context 'version' do
-    it 'should work with no errors' do
-      pp = <<-EOS
-      include apt
-      apt::force { 'vim': version => '1.1.1' }
-      EOS
-
-      shell('apt-get remove -y vim')
-      apply_manifest(pp, :catch_failures => false) do |r|
-        expect(r.stdout).to match(/apt-get -y  install vim=1.1.1/)
-      end
-    end
-
-    describe package('vim') do
-      it { should_not be_installed }
-    end
-  end
-
-  context 'timeout' do
-    it 'should work with no errors' do
-      pp = <<-EOS
-      include apt
-      apt::force { 'ocaml': timeout => '1' }
-      EOS
-
-      shell('apt-get clean')
-      apply_manifest(pp, :expect_failures => true) do |r|
-        expect(r.stderr).to match(/Error: Command exceeded timeout/)
-      end
-    end
-
-    describe package('ocaml') do
-      it { should_not be_installed }
-    end
-  end
-
-end
diff --git a/spec/acceptance/pin_spec.rb b/spec/acceptance/pin_spec.rb
deleted file mode 100644 (file)
index 07fc607..0000000
+++ /dev/null
@@ -1,286 +0,0 @@
-require 'spec_helper_acceptance'
-
-describe 'apt::pin define', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
-  context 'defaults' do
-    it 'should work with no errors' do
-      pp = <<-EOS
-      include apt
-      apt::pin { 'vim-puppet': }
-      EOS
-
-      apply_manifest(pp, :catch_failures => true)
-    end
-
-    describe file('/etc/apt/preferences.d/vim-puppet.pref') do
-      it { should be_file }
-      it { should contain 'Pin: release a=vim-puppet' }
-    end
-  end
-
-  context 'ensure' do
-    context 'present' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include apt
-        apt::pin { 'vim-puppet': ensure => present }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/preferences.d/vim-puppet.pref') do
-        it { should be_file }
-        it { should contain 'Pin: release a=vim-puppet' }
-      end
-    end
-
-    context 'absent' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include apt
-        apt::pin { 'vim-puppet': ensure => absent }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/preferences.d/vim-puppet.pref') do
-        it { should_not be_file }
-      end
-    end
-  end
-
-  context 'order' do
-    context '99' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include apt
-        apt::pin { 'vim-puppet':
-          ensure => present,
-          order  => '99',
-        }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/preferences.d/99-vim-puppet.pref') do
-        it { should be_file }
-        it { should contain 'Pin: release a=vim-puppet' }
-      end
-    end
-  end
-
-  context 'packages' do
-    context 'test' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include apt
-        apt::pin { 'vim-puppet':
-          ensure   => present,
-          packages => 'test',
-        }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/preferences.d/vim-puppet.pref') do
-        it { should be_file }
-        it { should contain 'Package: test' }
-        it { should contain 'Pin: release a=vim-puppet' }
-      end
-    end
-
-    context 'array' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include apt
-        apt::pin { 'array':
-          ensure   => present,
-          packages => ['apache', 'ntop'],
-        }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/preferences.d/array.pref') do
-        it { should be_file }
-        it { should contain 'Package: apache ntop' }
-        it { should contain 'Pin: release a=array' }
-      end
-    end
-  end
-
-  context 'release' do
-    context 'testrelease' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include apt
-        apt::pin { 'vim-puppet':
-          ensure  => present,
-          release => 'testrelease',
-        }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/preferences.d/vim-puppet.pref') do
-        it { should be_file }
-        it { should contain 'Pin: release a=testrelease' }
-      end
-    end
-  end
-
-  context 'origin' do
-    context 'testrelease' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include apt
-        apt::pin { 'vim-puppet':
-          ensure  => present,
-          origin  => 'testrelease',
-        }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/preferences.d/vim-puppet.pref') do
-        it { should be_file }
-        it { should contain 'Pin: origin testrelease' }
-      end
-    end
-  end
-
-  context 'version' do
-    context '1.0.0' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include apt
-        apt::pin { 'vim-puppet':
-          ensure   => present,
-          packages => 'test',
-          version  => '1.0.0',
-        }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/preferences.d/vim-puppet.pref') do
-        it { should be_file }
-        it { should contain 'Package: test' }
-        it { should contain 'Pin: version 1.0.0' }
-      end
-    end
-  end
-
-  context 'codename' do
-    context 'testname' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include apt
-        apt::pin { 'vim-puppet':
-          ensure   => present,
-          codename => 'testname',
-        }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/preferences.d/vim-puppet.pref') do
-        it { should be_file }
-        it { should contain 'Pin: release n=testname' }
-      end
-    end
-  end
-
-  context 'release_version' do
-    context '1.1.1' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include apt
-        apt::pin { 'vim-puppet':
-          ensure          => present,
-          release_version => '1.1.1',
-        }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/preferences.d/vim-puppet.pref') do
-        it { should be_file }
-        it { should contain 'Pin: release v=1.1.1' }
-      end
-    end
-  end
-
-  context 'component' do
-    context 'testcomponent' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include apt
-        apt::pin { 'vim-puppet':
-          ensure    => present,
-          component => 'testcomponent',
-        }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/preferences.d/vim-puppet.pref') do
-        it { should be_file }
-        it { should contain 'Pin: release c=testcomponent' }
-      end
-    end
-  end
-
-  context 'originator' do
-    context 'testorigin' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include apt
-        apt::pin { 'vim-puppet':
-          ensure     => present,
-          originator => 'testorigin',
-        }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/preferences.d/vim-puppet.pref') do
-        it { should be_file }
-        it { should contain 'Pin: release o=testorigin' }
-      end
-    end
-  end
-
-  context 'label' do
-    context 'testlabel' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include apt
-        apt::pin { 'vim-puppet':
-          ensure => present,
-          label  => 'testlabel',
-        }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/preferences.d/vim-puppet.pref') do
-        it { should be_file }
-        it { should contain 'Pin: release l=testlabel' }
-      end
-    end
-  end
-
-end
diff --git a/spec/acceptance/release_spec.rb b/spec/acceptance/release_spec.rb
deleted file mode 100644 (file)
index e7467bf..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-require 'spec_helper_acceptance'
-
-describe 'apt::release class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
-  context 'release_id' do
-    it 'should work with no errors' do
-      pp = <<-EOS
-      include apt
-      class { 'apt::release': release_id => 'precise', }
-      EOS
-
-      apply_manifest(pp, :catch_failures => true)
-    end
-
-    describe file('/etc/apt/apt.conf.d/01release') do
-      it { should be_file }
-      it { should contain 'APT::Default-Release "precise";' }
-    end
-  end
-
-  context 'reset' do
-    it 'cleans up' do
-      shell('rm -rf /etc/apt/apt.conf.d/01release')
-    end
-  end
-
-end
diff --git a/spec/acceptance/unattended_upgrade_spec.rb b/spec/acceptance/unattended_upgrade_spec.rb
deleted file mode 100644 (file)
index 09f4e2b..0000000
+++ /dev/null
@@ -1,562 +0,0 @@
-require 'spec_helper_acceptance'
-
-describe 'apt::unattended_upgrades class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
-  context 'defaults' do
-    it 'should work with no errors' do
-      pp = <<-EOS
-      include apt
-      include apt::unattended_upgrades
-      EOS
-
-      # Attempted workaround for problems seen on debian with
-      # something holding the package database open.
-      shell('killall -9 apt-get', { :acceptable_exit_codes => [0,1] })
-      shell('killall -9 dpkg', { :acceptable_exit_codes => [0,1] })
-      apply_manifest(pp, :catch_failures => true)
-    end
-
-    describe file('/etc/apt/apt.conf.d/10periodic') do
-      it { should be_file }
-    end
-    describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
-      it { should be_file }
-    end
-  end
-
-  context 'origins' do
-    it 'should work with no errors' do
-      pp = <<-EOS
-      include apt
-      class { 'apt::unattended_upgrades':
-        origins => ['${distro_id}:${distro_codename}-test'],
-      }
-      EOS
-
-      apply_manifest(pp, :catch_failures => true)
-    end
-
-    describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
-      it { should be_file }
-      it { should contain '${distro_id}:${distro_codename}-test' }
-    end
-  end
-
-  context 'blacklist' do
-    it 'should work with no errors' do
-      pp = <<-EOS
-      include apt
-      class { 'apt::unattended_upgrades':
-        blacklist => ['puppet']
-      }
-      EOS
-
-      apply_manifest(pp, :catch_failures => true)
-    end
-
-    describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
-      it { should be_file }
-      it { should contain 'puppet' }
-    end
-  end
-
-  context 'update' do
-    it 'should work with no errors' do
-      pp = <<-EOS
-      include apt
-      class { 'apt::unattended_upgrades':
-        update => '99'
-      }
-      EOS
-
-      apply_manifest(pp, :catch_failures => true)
-    end
-
-    describe file('/etc/apt/apt.conf.d/10periodic') do
-      it { should be_file }
-      it { should contain 'APT::Periodic::Update-Package-Lists "99";' }
-    end
-  end
-
-  context 'download' do
-    it 'should work with no errors' do
-      pp = <<-EOS
-      include apt
-      class { 'apt::unattended_upgrades':
-        download => '99'
-      }
-      EOS
-
-      apply_manifest(pp, :catch_failures => true)
-    end
-
-    describe file('/etc/apt/apt.conf.d/10periodic') do
-      it { should be_file }
-      it { should contain 'APT::Periodic::Download-Upgradeable-Packages "99";' }
-    end
-  end
-
-  context 'upgrade' do
-    it 'should work with no errors' do
-      pp = <<-EOS
-      include apt
-      class { 'apt::unattended_upgrades':
-        upgrade => '99'
-      }
-      EOS
-
-      apply_manifest(pp, :catch_failures => true)
-    end
-
-    describe file('/etc/apt/apt.conf.d/10periodic') do
-      it { should be_file }
-      it { should contain 'APT::Periodic::Unattended-Upgrade "99";' }
-    end
-  end
-
-  context 'autoclean' do
-    it 'should work with no errors' do
-      pp = <<-EOS
-      include apt
-      class { 'apt::unattended_upgrades':
-        autoclean => '99'
-      }
-      EOS
-
-      apply_manifest(pp, :catch_failures => true)
-    end
-
-    describe file('/etc/apt/apt.conf.d/10periodic') do
-      it { should be_file }
-      it { should contain 'APT::Periodic::AutocleanInterval "99";' }
-    end
-  end
-
-  context 'auto_fix' do
-    context 'true' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include apt
-        class { 'apt::unattended_upgrades':
-          auto_fix => true
-        }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
-        it { should be_file }
-        it { should contain 'Unattended-Upgrade::AutoFixInterruptedDpkg "true";' }
-      end
-    end
-
-    context 'false' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include apt
-        class { 'apt::unattended_upgrades':
-          auto_fix => false
-        }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
-        it { should be_file }
-        it { should contain 'Unattended-Upgrade::AutoFixInterruptedDpkg "false";' }
-      end
-    end
-  end
-
-  context 'minimal_steps' do
-    context 'true' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include apt
-        class { 'apt::unattended_upgrades':
-          minimal_steps => true
-        }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
-        it { should be_file }
-        it { should contain 'Unattended-Upgrade::MinimalSteps "true";' }
-      end
-    end
-
-    context 'false' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include apt
-        class { 'apt::unattended_upgrades':
-          minimal_steps => false
-        }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
-        it { should be_file }
-        it { should contain 'Unattended-Upgrade::MinimalSteps "false";' }
-      end
-    end
-  end
-
-  context 'install_on_shutdown' do
-    context 'true' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include apt
-        class { 'apt::unattended_upgrades':
-          install_on_shutdown => true
-        }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
-        it { should be_file }
-        it { should contain 'Unattended-Upgrade::InstallOnShutdown "true";' }
-      end
-    end
-
-    context 'false' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include apt
-        class { 'apt::unattended_upgrades':
-          install_on_shutdown => false
-        }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
-        it { should be_file }
-        it { should contain 'Unattended-Upgrade::InstallOnShutdown "false";' }
-      end
-    end
-  end
-
-  context 'mail_to' do
-    it 'should work with no errors' do
-      pp = <<-EOS
-      include apt
-      class { 'apt::unattended_upgrades':
-        mail_to => 'test@example.com'
-      }
-      EOS
-
-      apply_manifest(pp, :catch_failures => true)
-    end
-
-    describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
-      it { should be_file }
-      it { should contain 'Unattended-Upgrade::Mail "test@example.com";' }
-    end
-  end
-
-  context 'mail_only_on_error' do
-    context 'true' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include apt
-        class { 'apt::unattended_upgrades':
-          mail_to            => 'test@example.com',
-          mail_only_on_error => true
-        }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
-        it { should be_file }
-        it { should contain 'Unattended-Upgrade::MailOnlyOnError "true";' }
-      end
-    end
-
-    context 'false' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include apt
-        class { 'apt::unattended_upgrades':
-          mail_to            => 'test@example.com',
-          mail_only_on_error => false,
-        }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
-        it { should be_file }
-        it { should contain 'Unattended-Upgrade::MailOnlyOnError "false";' }
-      end
-    end
-
-    context 'mail_to missing' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include apt
-        class { 'apt::unattended_upgrades':
-          mail_only_on_error => true,
-        }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
-        it { should be_file }
-        it { should_not contain 'Unattended-Upgrade::MailOnlyOnError "true";' }
-      end
-    end
-  end
-
-  context 'remove_unused' do
-    context 'true' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include apt
-        class { 'apt::unattended_upgrades':
-          remove_unused => true
-        }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
-        it { should be_file }
-        it { should contain 'Unattended-Upgrade::Remove-Unused-Dependencies "true";' }
-      end
-    end
-
-    context 'false' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include apt
-        class { 'apt::unattended_upgrades':
-          remove_unused => false,
-        }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
-        it { should be_file }
-        it { should contain 'Unattended-Upgrade::Remove-Unused-Dependencies "false";' }
-      end
-    end
-  end
-
-  context 'auto_reboot' do
-    context 'true' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include apt
-        class { 'apt::unattended_upgrades':
-          auto_reboot => true
-        }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
-        it { should be_file }
-        it { should contain 'Unattended-Upgrade::Automatic-Reboot "true";' }
-      end
-    end
-
-    context 'false' do
-      it 'should work with no errors' do
-        pp = <<-EOS
-        include apt
-        class { 'apt::unattended_upgrades':
-          auto_reboot => false,
-        }
-        EOS
-
-        apply_manifest(pp, :catch_failures => true)
-      end
-
-      describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
-        it { should be_file }
-        it { should contain 'Unattended-Upgrade::Automatic-Reboot "false";' }
-      end
-    end
-  end
-
-  context 'dl_limit' do
-    it 'should work with no errors' do
-      pp = <<-EOS
-      include apt
-      class { 'apt::unattended_upgrades':
-        dl_limit => '99'
-      }
-      EOS
-
-      apply_manifest(pp, :catch_failures => true)
-    end
-
-    describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
-      it { should be_file }
-      it { should contain 'Acquire::http::Dl-Limit "99"' }
-    end
-  end
-
-  context 'enable' do
-    it 'should work with no errors' do
-      pp = <<-EOS
-      include apt
-      class { 'apt::unattended_upgrades':
-        enable => '2'
-      }
-      EOS
-
-      apply_manifest(pp, :catch_failures => true)
-    end
-
-    describe file('/etc/apt/apt.conf.d/10periodic') do
-      it { should be_file }
-      it { should contain 'APT::Periodic::Enable "2"' }
-    end
-  end
-
-  context 'backup_interval' do
-    it 'should work with no errors' do
-      pp = <<-EOS
-      include apt
-      class { 'apt::unattended_upgrades':
-        backup_interval => '2'
-      }
-      EOS
-
-      apply_manifest(pp, :catch_failures => true)
-    end
-
-    describe file('/etc/apt/apt.conf.d/10periodic') do
-      it { should be_file }
-      it { should contain 'APT::Periodic::BackUpArchiveInterval "2";' }
-    end
-  end
-
-  context 'backup_level' do
-    it 'should work with no errors' do
-      pp = <<-EOS
-      include apt
-      class { 'apt::unattended_upgrades':
-        backup_level => '2'
-      }
-      EOS
-
-      apply_manifest(pp, :catch_failures => true)
-    end
-
-    describe file('/etc/apt/apt.conf.d/10periodic') do
-      it { should be_file }
-      it { should contain 'APT::Periodic::BackUpLevel "2";' }
-    end
-  end
-
-  context 'max_age' do
-    it 'should work with no errors' do
-      pp = <<-EOS
-      include apt
-      class { 'apt::unattended_upgrades':
-        max_age => '2'
-      }
-      EOS
-
-      apply_manifest(pp, :catch_failures => true)
-    end
-
-    describe file('/etc/apt/apt.conf.d/10periodic') do
-      it { should be_file }
-      it { should contain 'APT::Periodic::MaxAge "2";' }
-    end
-  end
-
-  context 'min_age' do
-    it 'should work with no errors' do
-      pp = <<-EOS
-      include apt
-      class { 'apt::unattended_upgrades':
-        min_age => '2'
-      }
-      EOS
-
-      apply_manifest(pp, :catch_failures => true)
-    end
-
-    describe file('/etc/apt/apt.conf.d/10periodic') do
-      it { should be_file }
-      it { should contain 'APT::Periodic::MinAge "2";' }
-    end
-  end
-
-  context 'max_size' do
-    it 'should work with no errors' do
-      pp = <<-EOS
-      include apt
-      class { 'apt::unattended_upgrades':
-        max_size => '2'
-      }
-      EOS
-
-      apply_manifest(pp, :catch_failures => true)
-    end
-
-    describe file('/etc/apt/apt.conf.d/10periodic') do
-      it { should be_file }
-      it { should contain 'APT::Periodic::MaxSize "2";' }
-    end
-  end
-
-  context 'download_delta' do
-    it 'should work with no errors' do
-      pp = <<-EOS
-      include apt
-      class { 'apt::unattended_upgrades':
-        download_delta => '2'
-      }
-      EOS
-
-      apply_manifest(pp, :catch_failures => true)
-    end
-
-    describe file('/etc/apt/apt.conf.d/10periodic') do
-      it { should be_file }
-      it { should contain 'APT::Periodic::Download-Upgradeable-Packages-Debdelta "2";' }
-    end
-  end
-
-  context 'verbose' do
-    it 'should work with no errors' do
-      pp = <<-EOS
-      include apt
-      class { 'apt::unattended_upgrades':
-        verbose => '2'
-      }
-      EOS
-
-      apply_manifest(pp, :catch_failures => true)
-    end
-
-    describe file('/etc/apt/apt.conf.d/10periodic') do
-      it { should be_file }
-      it { should contain 'APT::Periodic::Verbose "2";' }
-    end
-  end
-
-end
diff --git a/spec/acceptance/unsupported_spec.rb b/spec/acceptance/unsupported_spec.rb
deleted file mode 100644 (file)
index 3f74685..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-require 'spec_helper_acceptance'
-
-describe 'unsupported distributions and OSes', :if => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
-  it 'class apt fails' do
-    pp = <<-EOS
-      class { 'apt': }
-    EOS
-    expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/This module only works on Debian or derivatives like Ubuntu/i)
-  end
-end
index a21e0443e2df715b221e712d9457607d26117611..2c70e3e0901258b106a7c42e940131b35acf5e1c 100644 (file)
 require 'spec_helper'
 describe 'apt', :type => :class do
   let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
-  let :default_params do
-    {
-      :disable_keys => :undef,
-      :always_apt_update => false,
-      :purge_sources_list => false,
-      :purge_sources_list_d => false,
-    }
+
+  context 'defaults' do
+    it { should contain_file('sources.list').that_notifies('Exec[apt_update]').only_with({
+      'ensure' => 'present',
+      'path'   => '/etc/apt/sources.list',
+      'owner'  => 'root',
+      'group'  => 'root',
+      'mode'   => '0644',
+      'notify' => 'Exec[apt_update]',
+    })}
+
+    it { should contain_file('sources.list.d').that_notifies('Exec[apt_update]').only_with({
+      'ensure'  => 'directory',
+      'path'    => '/etc/apt/sources.list.d',
+      'owner'   => 'root',
+      'group'   => 'root',
+      'purge'   => false,
+      'recurse' => false,
+      'notify'  => 'Exec[apt_update]',
+    })}
+
+    it { should contain_file('preferences.d').only_with({
+      'ensure'  => 'directory',
+      'path'    => '/etc/apt/preferences.d',
+      'owner'   => 'root',
+      'group'   => 'root',
+      'purge'   => false,
+      'recurse' => false,
+    })}
+
+    it { should contain_file('01proxy').that_notifies('Exec[apt_update]').only_with({
+      'ensure' => 'absent',
+      'path'   => '/etc/apt/apt.conf.d/01proxy',
+      'notify' => 'Exec[apt_update]',
+    })}
+
+    it { should contain_file('old-proxy-file').that_notifies('Exec[apt_update]').only_with({
+      'ensure' => 'absent',
+      'path'   => '/etc/apt/apt.conf.d/proxy',
+      'notify' => 'Exec[apt_update]',
+    })}
+
+    it { should contain_exec('apt_update').with({
+      'refreshonly' => 'true',
+    })}
   end
 
-  [{},
-    {
-      :disable_keys => true,
-      :always_apt_update => true,
-      :proxy_host => true,
-      :proxy_port => '3128',
-      :purge_sources_list => true,
-      :purge_sources_list_d => true,
-    },
-    {
-      :purge_preferences   => true,
-      :purge_preferences_d => true,
-    },
-    {
-      :disable_keys => false
-    }
-  ].each do |param_set|
-    describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
-      let :param_hash do
-        default_params.merge(param_set)
-      end
+  context 'lots of non-defaults' do
+    let :params do
+      {
+        :always_apt_update    => true,
+        :disable_keys         => true,
+        :proxy_host           => 'foo',
+        :proxy_port           => '9876',
+        :purge_sources_list   => true,
+        :purge_sources_list_d => true,
+        :purge_preferences    => true,
+        :purge_preferences_d  => true,
+        :update_timeout       => '1',
+        :update_tries         => '3',
+        :fancy_progress       => true,
+      }
+    end
 
-      let :params do
-        param_set
-      end
+    it { should contain_file('sources.list').with({
+      'content' => "# Repos managed by puppet.\n"
+    })}
 
-      let :refresh_only_apt_update do
-        if param_hash[:always_apt_update]
-          false
-        else
-          true
-        end
-      end
+    it { should contain_file('sources.list.d').with({
+      'purge'   => 'true',
+      'recurse' => 'true',
+    })}
+
+    it { should contain_file('apt-preferences').only_with({
+      'ensure' => 'absent',
+      'path'   => '/etc/apt/preferences',
+    })}
+
+    it { should contain_file('preferences.d').with({
+      'purge'   => 'true',
+      'recurse' => 'true',
+    })}
 
-      it { should contain_class("apt::params") }
-
-      it {
-        if param_hash[:purge_sources_list]
-        should contain_file("sources.list").with({
-            'path'    => "/etc/apt/sources.list",
-            'ensure'  => "present",
-            'owner'   => "root",
-            'group'   => "root",
-            'mode'    => "0644",
-            "content" => "# Repos managed by puppet.\n"
-          })
-        else
-        should contain_file("sources.list").with({
-            'path'    => "/etc/apt/sources.list",
-            'ensure'  => "present",
-            'owner'   => "root",
-            'group'   => "root",
-            'mode'    => "0644",
-            'content' => nil
-          })
-        end
+    it { should contain_file('99progressbar').only_with({
+      'ensure'  => 'present',
+      'content' => 'Dpkg::Progress-Fancy "1";',
+      'path'    => '/etc/apt/apt.conf.d/99progressbar',
+    })}
+
+    it { should contain_file('99unauth').only_with({
+      'ensure'  => 'present',
+      'content' => "APT::Get::AllowUnauthenticated 1;\n",
+      'path'    => '/etc/apt/apt.conf.d/99unauth',
+    })}
+
+    it { should contain_file('01proxy').that_notifies('Exec[apt_update]').only_with({
+      'ensure'  => 'present',
+      'path'    => '/etc/apt/apt.conf.d/01proxy',
+      'content' => "Acquire::http::Proxy \"http://foo:9876\";\n",
+      'notify'  => 'Exec[apt_update]',
+      'mode'    => '0644',
+      'owner'   => 'root',
+      'group'   => 'root'
+    })}
+
+    it { should contain_exec('apt_update').with({
+      'refreshonly' => 'false',
+      'timeout'     => '1',
+      'tries'       => '3',
+    })}
+
+  end
+
+  context 'more non-default' do
+    let :params do
+      {
+        :fancy_progress => false,
+        :disable_keys   => false,
       }
-      it {
-        if param_hash[:purge_sources_list_d]
-          should create_file("sources.list.d").with({
-            'path'    => "/etc/apt/sources.list.d",
-            'ensure'  => "directory",
-            'owner'   => "root",
-            'group'   => "root",
-            'purge'   => true,
-            'recurse' => true,
-            'notify'  => 'Exec[apt_update]'
-          })
-        else
-          should create_file("sources.list.d").with({
-            'path'    => "/etc/apt/sources.list.d",
-            'ensure'  => "directory",
-            'owner'   => "root",
-            'group'   => "root",
-            'purge'   => false,
-            'recurse' => false,
-            'notify'  => 'Exec[apt_update]'
-          })
-        end
+    end
+
+    it { should contain_file('99progressbar').only_with({
+      'ensure'  => 'absent',
+      'path'    => '/etc/apt/apt.conf.d/99progressbar',
+    })}
+
+    it { should contain_file('99unauth').only_with({
+      'ensure'  => 'absent',
+      'path'    => '/etc/apt/apt.conf.d/99unauth',
+    })}
+
+  end
+
+  context 'with sources defined on valid osfamily' do
+    let :facts do
+      { :osfamily        => 'Debian',
+        :lsbdistcodename => 'precise',
+        :lsbdistid       => 'Debian',
       }
-      it {
-        if param_hash[:purge_preferences]
-          should create_file('apt-preferences').with({
-            :ensure  => 'absent',
-            :path    => '/etc/apt/preferences',
-          })
-        else
-          should_not contain_file('apt-preferences')
-        end
+    end
+    let(:params) { { :sources => {
+      'debian_unstable' => {
+        'location'          => 'http://debian.mirror.iweb.ca/debian/',
+        'release'           => 'unstable',
+        'repos'             => 'main contrib non-free',
+        'required_packages' => 'debian-keyring debian-archive-keyring',
+        'key'               => '55BE302B',
+        'key_server'        => 'subkeys.pgp.net',
+        'pin'               => '-10',
+        'include_src'       => true
+      },
+      'puppetlabs' => {
+        'location'   => 'http://apt.puppetlabs.com',
+        'repos'      => 'main',
+        'key'        => '4BD6EC30',
+        'key_server' => 'pgp.mit.edu',
       }
+    } } }
 
-      it {
-        if param_hash[:purge_preferences_d]
-          should create_file("preferences.d").with({
-            'path'    => "/etc/apt/preferences.d",
-            'ensure'  => "directory",
-            'owner'   => "root",
-            'group'   => "root",
-            'purge'   => true,
-            'recurse' => true,
-          })
-        else
-          should create_file("preferences.d").with({
-            'path'    => "/etc/apt/preferences.d",
-            'ensure'  => "directory",
-            'owner'   => "root",
-            'group'   => "root",
-            'purge'   => false,
-            'recurse' => false,
-          })
-        end
-      }
+    it {
+      should contain_file('debian_unstable.list').with({
+        'ensure'  => 'present',
+        'path'    => '/etc/apt/sources.list.d/debian_unstable.list',
+        'owner'   => 'root',
+        'group'   => 'root',
+        'mode'    => '0644',
+        'notify'  => 'Exec[apt_update]',
+      })
+    }
 
-      it {
-        should contain_exec("apt_update").with({
-          'command'     => "/usr/bin/apt-get update",
-          'refreshonly' => refresh_only_apt_update
-        })
-      }
+    it { should contain_file('debian_unstable.list').with_content(/^deb http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }
+    it { should contain_file('debian_unstable.list').with_content(/^deb-src http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }
 
-      it {
-        if param_hash[:disable_keys] == true
-          should create_file("99unauth").with({
-            'content' => "APT::Get::AllowUnauthenticated 1;\n",
-            'ensure'  => "present",
-            'path'    => "/etc/apt/apt.conf.d/99unauth"
-          })
-        elsif param_hash[:disable_keys] == false
-          should create_file("99unauth").with({
-            'ensure' => "absent",
-            'path'   => "/etc/apt/apt.conf.d/99unauth"
-          })
-        elsif param_hash[:disable_keys] != :undef
-          should_not create_file("99unauth").with({
-            'path'   => "/etc/apt/apt.conf.d/99unauth"
-          })
-        end
-      }
-      describe 'when setting a proxy' do
-        it {
-          if param_hash[:proxy_host]
-            should contain_file('01proxy').with(
-              'path'    => '/etc/apt/apt.conf.d/01proxy',
-              'content' => "Acquire::http::Proxy \"http://#{param_hash[:proxy_host]}:#{param_hash[:proxy_port]}\";\n",
-              'notify'  => "Exec[apt_update]"
-            )
-          else
-            should contain_file('01proxy').with(
-              'path'    => '/etc/apt/apt.conf.d/01proxy',
-              'notify'  => 'Exec[apt_update]',
-              'ensure'  => 'absent'
-            )
-          end
+    it {
+      should contain_file('puppetlabs.list').with({
+        'ensure'  => 'present',
+        'path'    => '/etc/apt/sources.list.d/puppetlabs.list',
+        'owner'   => 'root',
+        'group'   => 'root',
+        'mode'    => '0644',
+        'notify'  => 'Exec[apt_update]',
+      })
+    }
+
+    it { should contain_file('puppetlabs.list').with_content(/^deb http:\/\/apt.puppetlabs.com precise main$/) }
+    it { should contain_file('puppetlabs.list').with_content(/^deb-src http:\/\/apt.puppetlabs.com precise main$/) }
+  end
+
+  describe 'failing tests' do
+    context 'bad purge_sources_list' do
+      let :params do
+        {
+          'purge_sources_list' => 'foo'
+        }
+      end
+      it do
+        expect {
+          should compile
+        }.to raise_error(Puppet::Error)
+      end
+    end
+
+    context 'bad purge_sources_list_d' do
+      let :params do
+        {
+          'purge_sources_list_d' => 'foo'
         }
       end
+      it do
+        expect {
+          should compile
+        }.to raise_error(Puppet::Error)
+      end
+    end
+
+    context 'bad purge_preferences' do
+      let :params do
+        {
+          'purge_preferences' => 'foo'
+        }
+      end
+      it do
+        expect {
+          should compile
+        }.to raise_error(Puppet::Error)
+      end
+    end
+
+    context 'bad purge_preferences_d' do
+      let :params do
+        {
+          'purge_preferences_d' => 'foo'
+        }
+      end
+      it do
+        expect {
+          should compile
+        }.to raise_error(Puppet::Error)
+      end
+    end
+
+    context 'with unsupported osfamily' do
+      let :facts do
+        { :osfamily => 'Darwin', }
+      end
+
+      it do
+        expect {
+          should compile
+        }.to raise_error(Puppet::Error, /This module only works on Debian or derivatives like Ubuntu/)
+      end
     end
   end
 end
diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb
deleted file mode 100644 (file)
index c5e938a..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-require 'spec_helper'
-describe 'apt' do
-  context 'with sources defined on valid osfamily' do
-    let :facts do
-      { :osfamily        => 'Debian',
-        :lsbdistcodename => 'precise',
-        :lsbdistid       => 'Debian',
-      }
-    end
-    let(:params) { { :sources => {
-      'debian_unstable' => {
-        'location'          => 'http://debian.mirror.iweb.ca/debian/',
-        'release'           => 'unstable',
-        'repos'             => 'main contrib non-free',
-        'required_packages' => 'debian-keyring debian-archive-keyring',
-        'key'               => '55BE302B',
-        'key_server'        => 'subkeys.pgp.net',
-        'pin'               => '-10',
-        'include_src'       => true
-      },
-      'puppetlabs' => {
-        'location'   => 'http://apt.puppetlabs.com',
-        'repos'      => 'main',
-        'key'        => '4BD6EC30',
-        'key_server' => 'pgp.mit.edu',
-      }
-    } } }
-
-    it {
-      should contain_file('debian_unstable.list').with({
-        'ensure'  => 'present',
-        'path'    => '/etc/apt/sources.list.d/debian_unstable.list',
-        'owner'   => 'root',
-        'group'   => 'root',
-        'mode'    => '0644',
-        'notify'  => 'Exec[apt_update]',
-      })
-    }
-
-    it { should contain_file('debian_unstable.list').with_content(/^deb http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }
-    it { should contain_file('debian_unstable.list').with_content(/^deb-src http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }
-
-    it {
-      should contain_file('puppetlabs.list').with({
-        'ensure'  => 'present',
-        'path'    => '/etc/apt/sources.list.d/puppetlabs.list',
-        'owner'   => 'root',
-        'group'   => 'root',
-        'mode'    => '0644',
-        'notify'  => 'Exec[apt_update]',
-      })
-    }
-
-    it { should contain_file('puppetlabs.list').with_content(/^deb http:\/\/apt.puppetlabs.com precise main$/) }
-    it { should contain_file('puppetlabs.list').with_content(/^deb-src http:\/\/apt.puppetlabs.com precise main$/) }
-  end
-
-  context 'with unsupported osfamily' do
-    let :facts do
-      { :osfamily        => 'Darwin', }
-    end
-
-    it do
-      expect {
-       should compile
-      }.to raise_error(Puppet::Error, /This module only works on Debian or derivatives like Ubuntu/)
-    end
-  end
-end
index 8494f0410d9b6f7631721673e7314e69857aea72..291719b0098b66e986bfeb4cfee5b61cc6ff47bd 100644 (file)
@@ -24,270 +24,165 @@ describe 'apt::unattended_upgrades', :type => :class do
     })
   }
 
-  describe "origins" do
-    describe 'on Debian' do
-      default_facts = { :lsbdistid => 'Debian' }
-      context 'defaults' do
-        let :facts do default_facts end
-        it {
-          should contain_file(file_unattended).with_content(
-            /^Unattended-Upgrade::Origins-Pattern/
-          ).with_content(
-            /"origin=Debian,archive=stable,label=Debian-Security";/
-          )
-        }
-      end
-      context 'defaults with custom origin' do
-        let :facts do default_facts end
-        let :params do { :origins => ['bananana']} end
-        it {
-          should contain_file(file_unattended).with_content(
-            /^Unattended-Upgrade::Origins-Pattern/
-          ).with_content(
-            /"bananana";/
-          )
-        }
-      end
-      context 'defaults with invalid origin' do
-        let :facts do default_facts end
-        let :params do { :origins => 'bananana'} end
-        it {
-          expect {subject}.to raise_error(/is not an Array/)
-        }
-      end
-      context 'squeeze' do
-        let :facts do default_facts.merge({:lsbdistcodename => 'squeeze'}) end
-        it {
-          should contain_file(file_unattended).with_content(
-            /^Unattended-Upgrade::Allowed-Origins/
-          ).with_content(
-            /"\${distro_id} \${distro_codename}-lts";/
-          ).with_content(
-            /"\${distro_id} \${distro_codename}-security";/
-          ).with_content(
-            /"\${distro_id} oldstable";/
-          )
-        }
-      end
-      context 'wheezy' do
-        let :facts do default_facts.merge({:lsbdistcodename => 'wheezy'}) end
-        it {
-          should contain_file(file_unattended).with_content(
-            /^Unattended-Upgrade::Origins-Pattern/
-          ).with_content(
-            /"origin=Debian,archive=stable,label=Debian-Security";/
-          )
+  describe 'failing' do
+    let :facts do
+      {
+        'lsbdistid'       => 'debian',
+        'lsbdistcodename' => 'squeeze',
+      }
+    end
+    context 'bad auto_fix' do
+      let :params do
+        {
+          'auto_fix' => 'foo',
         }
       end
+      it { expect { should raise_error(Puppet::Error) } }
     end
 
-    describe 'on Ubuntu' do
-      default_facts = { :lsbdistid => 'Ubuntu' }
-      context 'default' do
-        let :facts do default_facts end
-        it {
-          should contain_file(file_unattended).with_content(
-            /^Unattended-Upgrade::Allowed-Origins/
-          ).with_content(
-            /"\${distro_id}\:\${distro_codename}-security";/
-          )
-        }
-      end
-      context 'lucid' do
-        let :facts do default_facts.merge({:lsbdistcodename => 'lucid'}) end
-        it {
-          should contain_file(file_unattended).with_content(
-            /^Unattended-Upgrade::Allowed-Origins/
-          ).with_content(
-            /"\${distro_id} \${distro_codename}-security";/
-          )
-        }
-      end
-      context 'precise' do
-        let :facts do default_facts.merge({:lsbdistcodename => 'precise'}) end
-        it {
-          should contain_file(file_unattended).with_content(
-            /^Unattended-Upgrade::Allowed-Origins/
-          ).with_content(
-            /"\${distro_id}\:\${distro_codename}-security";/
-          )
-        }
-      end
-      context 'trusty' do
-        let :facts do default_facts.merge({:lsbdistcodename => 'trusty'}) end
-        it {
-          should contain_file(file_unattended).with_content(
-            /^Unattended-Upgrade::Allowed-Origins/
-          ).with_content(
-            /"\${distro_id}\:\${distro_codename}-security";/
-          )
+    context 'bad minimal_steps' do
+      let :params do
+        {
+          'minimal_steps' => 'foo',
         }
       end
-    end
-  end
-
-  describe "blacklist" do
-    describe "with param defaults" do
-      let(:params) {{ }}
-      it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Package-Blacklist \{\n\};$/) }
+      it { expect { should raise_error(Puppet::Error) } }
     end
 
-    describe "with blacklist => []" do
+    context 'bad install_on_shutdown' do
       let :params do
-        { :blacklist => ['libc6', 'libc6-dev'] }
+        {
+          'install_on_shutdown' => 'foo',
+        }
       end
-      it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Package-Blacklist \{\n\t"libc6";\n\t"libc6-dev";\n\};$/) }
-    end
-  end
-
-  describe "with update => 2" do
-    let :params do
-      { :update => "2" }
-    end
-    it { should contain_file(file_periodic).with_content(/^APT::Periodic::Update-Package-Lists "2";$/) }
-  end
-
-  describe "with download => 2" do
-    let :params do
-      { :download => "2" }
+      it { expect { should raise_error(Puppet::Error) } }
     end
-    it { should contain_file(file_periodic).with_content(/^APT::Periodic::Download-Upgradeable-Packages "2";$/) }
-  end
 
-  describe "with upgrade => 2" do
-    let :params do
-      { :upgrade => "2" }
-    end
-    it { should contain_file(file_periodic).with_content(/^APT::Periodic::Unattended-Upgrade "2";$/) }
-  end
-
-  describe "with autoclean => 2" do
-    let :params do
-      { :autoclean => "2" }
-    end
-    it { should contain_file(file_periodic).with_content(/^APT::Periodic::AutocleanInterval "2";$/) }
-  end
-
-  describe "with auto_fix => false" do
-    let :params do
-      { :auto_fix => false }
-    end
-    it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::AutoFixInterruptedDpkg "false";$/) }
-  end
-
-  describe "with minimal_steps => true" do
-    let :params do
-      { :minimal_steps => true }
-    end
-    it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::MinimalSteps "true";$/) }
-  end
-
-  describe "with install_on_shutdown => true" do
-    let :params do
-      { :install_on_shutdown => true }
-    end
-    it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::InstallOnShutdown "true";$/) }
-  end
-
-  describe "mail_to" do
-    describe "param defaults" do
-      let(:params) {{ }}
-      it { should_not contain_file(file_unattended).with_content(/^Unattended-Upgrade::Mail /) }
-      it { should_not contain_file(file_unattended).with_content(/^Unattended-Upgrade::MailOnlyOnError /) }
-    end
-
-    describe "with mail_to => user@website, mail_only_on_error => true" do
+    context 'bad mail_only_on_error' do
       let :params do
-        { :mail_to => "user@website",
-          :mail_only_on_error => true }
+        {
+          'mail_only_on_error' => 'foo',
+        }
       end
-      it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Mail "user@website";$/) }
-      it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::MailOnlyOnError "true";$/) }
-    end
-  end
-
-  describe "with remove_unused => false" do
-    let :params do
-      { :remove_unused => false }
-    end
-    it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Remove-Unused-Dependencies "false";$/) }
-  end
-
-  describe "with auto_reboot => true" do
-    let :params do
-      { :auto_reboot => true }
-    end
-    it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Automatic-Reboot "true";$/) }
-  end
-
-  describe "dl_limit" do
-    describe "param defaults" do
-      let(:params) {{ }}
-      it { should_not contain_file(file_unattended).with_content(/^Acquire::http::Dl-Limit /) }
+      it { expect { should raise_error(Puppet::Error) } }
     end
 
-    describe "with dl_limit => 70" do
+    context 'bad remove_unused' do
       let :params do
-        { :dl_limit => "70" }
+        {
+          'remove_unused' => 'foo',
+        }
       end
-      it { should contain_file(file_unattended).with_content(/^Acquire::http::Dl-Limit "70";$/) }
-    end
-  end
-
-  describe "with enable => 0" do
-    let :params do
-      { :enable => "0" }
-    end
-    it { should contain_file(file_periodic).with_content(/^APT::Periodic::Enable "0";$/) }
-  end
-
-  describe "with backup_interval => 1" do
-    let :params do
-      { :backup_interval => "1" }
+      it { expect { should raise_error(Puppet::Error) } }
     end
-    it { should contain_file(file_periodic).with_content(/^APT::Periodic::BackUpArchiveInterval "1";$/) }
-  end
 
-  describe "with backup_level => 0" do
-    let :params do
-      { :backup_level => "0" }
-    end
-    it { should contain_file(file_periodic).with_content(/^APT::Periodic::BackUpLevel "0";$/) }
-  end
-
-  describe "with max_age => 1" do
-    let :params do
-      { :max_age => "1" }
-    end
-    it { should contain_file(file_periodic).with_content(/^APT::Periodic::MaxAge "1";$/) }
-  end
-
-  describe "with min_age => 1" do
-    let :params do
-      { :min_age => "1" }
-    end
-    it { should contain_file(file_periodic).with_content(/^APT::Periodic::MinAge "1";$/) }
-  end
-
-  describe "with max_size => 1" do
-    let :params do
-      { :max_size => "1" }
+    context 'bad auto_reboot' do
+      let :params do
+        {
+          'auto_reboot' => 'foo',
+        }
+      end
+      it { expect { should raise_error(Puppet::Error) } }
     end
-    it { should contain_file(file_periodic).with_content(/^APT::Periodic::MaxSize "1";$/) }
-  end
 
-  describe "with download_delta => 2" do
-    let :params do
-      { :download_delta => "2" }
-    end
-    it { should contain_file(file_periodic).with_content(/^APT::Periodic::Download-Upgradeable-Packages-Debdelta "2";$/) }
-  end
+    context 'bad origins' do
+      let :params do
+        {
+          'origins' => 'foo'
+        }
+      end
+      it { expect { should raise_error(Puppet::Error) } }
+    end
+
+  end
+
+  context 'defaults' do
+    let :facts do
+      {
+        'lsbdistid'       => 'debian',
+        'lsbdistcodename' => 'squeeze',
+      }
+    end
+
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Allowed-Origins \{\n\t"\${distro_id} oldstable";\n\t"\${distro_id} \${distro_codename}-security";\n\t"\${distro_id} \${distro_codename}-lts";\n\};} }
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::AutoFixInterruptedDpkg "true";}}
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::MinimalSteps "false";}}
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::InstallOnShutdown "false";}}
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Remove-Unused-Dependencies "true";}}
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Automatic-Reboot "false";}}
+
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Enable "1";}}
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::BackUpArchiveInterval "0";}}
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::BackUpLevel "3";}}
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::MaxAge "0";}}
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::MinAge "0";}}
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::MaxSize "0";}}
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Update-Package-Lists "1";}}
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Download-Upgradeable-Packages "1";}}
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Download-Upgradeable-Packages-Debdelta "0";}}
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Unattended-Upgrade "1";}}
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::AutocleanInterval "7";}}
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Verbose "0";}}
+  end
+
+  context 'anything but defaults' do
+    let :facts do
+      {
+        'lsbdistid'       => 'debian',
+        'lsbdistcodename' => 'wheezy',
+      }
+    end
+
+    let :params do
+      {
+        'enable'              => '0',
+        'backup_interval'     => '3',
+        'backup_level'        => '1',
+        'max_age'             => '7',
+        'min_age'             => '1',
+        'max_size'            => '100',
+        'update'              => '0',
+        'download'            => '0',
+        'download_delta'      => '1',
+        'upgrade'             => '0',
+        'autoclean'           => '0',
+        'verbose'             => '1',
+        'origins'             => ['bananas'],
+        'blacklist'           => ['foo', 'bar'],
+        'auto_fix'            => false,
+        'minimal_steps'       => true,
+        'install_on_shutdown' => true,
+        'mail_to'             => 'root@localhost',
+        'mail_only_on_error'  => true,
+        'remove_unused'       => false,
+        'auto_reboot'         => true,
+        'dl_limit'            => '70',
+      }
+    end
+
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Origins-Pattern \{\n\t"bananas";\n\};} }
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Package-Blacklist \{\n\t"foo";\n\t"bar";\n\};} }
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::AutoFixInterruptedDpkg "false";}}
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::MinimalSteps "true";}}
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::InstallOnShutdown "true";}}
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Mail "root@localhost";}}
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::MailOnlyOnError "true";}}
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Remove-Unused-Dependencies "false";}}
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Automatic-Reboot "true";}}
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Acquire::http::Dl-Limit "70";}}
+
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Enable "0";}}
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::BackUpArchiveInterval "3";}}
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::BackUpLevel "1";}}
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::MaxAge "7";}}
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::MinAge "1";}}
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::MaxSize "100";}}
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Update-Package-Lists "0";}}
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Download-Upgradeable-Packages "0";}}
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Download-Upgradeable-Packages-Debdelta "1";}}
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Unattended-Upgrade "0";}}
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::AutocleanInterval "0";}}
+    it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Verbose "1";}}
 
-  describe "with verbose => 2" do
-    let :params do
-      { :verbose => "2" }
-    end
-    it { should contain_file(file_periodic).with_content(/^APT::Periodic::Verbose "2";$/) }
   end
-
 end
index a0cbaa4cc098e80acde84a7951788d1f64d31698..88cdf4fb6ef65d2372ce84b2abb964ba0f381312 100644 (file)
@@ -4,10 +4,10 @@ describe 'apt::builddep', :type => :define do
   let(:facts) { { :lsbdistid => 'Debian' } }
   let(:title) { 'my_package' }
 
-  describe "should require apt-get update" do
-    it { should contain_exec("apt_update").with({
-        'command' => "/usr/bin/apt-get update",
-        'refreshonly' => true
+  describe "defaults" do
+    it { should contain_exec("apt-builddep-my_package").that_notifies('Exec[apt_update]').with({
+        'command' => "/usr/bin/apt-get -y --force-yes build-dep my_package",
+        'logoutput' => 'on_failure'
       })
     }
     it { should contain_anchor("apt::builddep::my_package").with({
index cda5900c035a3174aa782d8d8e34d678534b6eb5..ec4e229c4449f5122f340ce61a16bc60cd82ff09 100644 (file)
@@ -17,12 +17,6 @@ describe 'apt::conf', :type => :define do
       "/etc/apt/apt.conf.d/00norecommends"
     end
 
-    it { should contain_apt__conf('norecommends').with({
-         'priority' => '00',
-         'content'  => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n"
-      })
-    }
-
     it { should contain_file(filename).with({
           'ensure'    => 'present',
           'content'   => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n",
index 0d3d6e594005be5e1005c66f399d66444ed31409..a3a215c0ca60b93c4d550e8751908129126ba36f 100644 (file)
@@ -17,12 +17,10 @@ describe 'apt::force', :type => :define do
   end
 
   describe "when using default parameters" do
-    let :params do
-      default_params
-    end
     it { should contain_exec("/usr/bin/apt-get -y  install #{title}").with(
-      :unless  => "/usr/bin/dpkg -s #{title} | grep -q 'Status: install'",
-      :timeout => '300'
+      :unless    => "/usr/bin/dpkg -s #{title} | grep -q 'Status: install'",
+      :logoutput => 'on_failure',
+      :timeout   => '300'
     ) }
   end
 
index 9da21d784a9b634016bd49e3a2cebee9a2a94d08..60b991f194f347a86154cf663234707c203eb433 100644 (file)
@@ -1,9 +1,9 @@
 require 'spec_helper'
 describe 'apt::hold' do
   let :facts do {
-      :osfamily   => 'Debian',
-      :lsbdistid  => 'Debian',
-      :lsbrelease => 'wheezy',
+    :osfamily   => 'Debian',
+    :lsbdistid  => 'Debian',
+    :lsbrelease => 'wheezy',
   } end
 
   let :title do
@@ -18,13 +18,6 @@ describe 'apt::hold' do
     let :params do default_params end
 
     it 'creates an apt preferences file' do
-      should contain_apt__hold(title).with({
-        :ensure   => 'present',
-        :package  => title,
-        :version  => params[:version],
-        :priority => 1001,
-      })
-
       should contain_apt__pin("hold_#{title}").with({
         :ensure   => 'present',
         :packages => title,
@@ -38,9 +31,6 @@ describe 'apt::hold' do
     let :params do default_params.merge({:ensure => 'absent',}) end
 
     it 'creates an apt preferences file' do
-      should contain_apt__hold(title).with({
-        :ensure   => params[:ensure],
-      })
 
       should contain_apt__pin("hold_#{title}").with({
         :ensure   => params[:ensure],
@@ -52,22 +42,29 @@ describe 'apt::hold' do
     let :params do default_params.merge({:priority => 990,}) end
 
     it 'creates an apt preferences file' do
-      should contain_apt__hold(title).with({
+      should contain_apt__pin("hold_#{title}").with({
         :ensure   => 'present',
-        :package  => title,
+        :packages => title,
         :version  => params[:version],
         :priority => params[:priority],
       })
+    end
+  end
 
-      should contain_apt__pin("hold_#{title}").with({
+  describe 'package => foo' do
+    let :params do default_params.merge({:package => 'foo'}) end
+
+    it 'creates an apt preferences file' do
+      should contain_apt__pin("hold_foo").with({
         :ensure   => 'present',
-        :packages => title,
+        :packages => 'foo',
         :version  => params[:version],
-        :priority => params[:priority],
+        :priority => 1001,
       })
     end
   end
 
+
   describe 'validation' do
     context 'version => {}' do
       let :params do { :version => {}, } end
index 005c95e4698ab6c426186e4d23b39e8fc4a92cc3..dbb67c4c57439beec2679ea7d2005448b74c9d55 100644 (file)
@@ -10,12 +10,6 @@ describe 'apt::key', :type => :define do
 
   describe 'normal operation' do
     describe 'default options' do
-      it 'contains the apt::key' do
-        should contain_apt__key(title).with({
-          :key    => title,
-          :ensure => 'present',
-        })
-      end
       it 'contains the apt_key' do
         should contain_apt_key(title).with({
           :id                => title,
@@ -40,12 +34,6 @@ describe 'apt::key', :type => :define do
         :key => GPG_KEY_ID,
       } end
 
-      it 'contains the apt::key' do
-        should contain_apt__key(title).with({
-          :key    => GPG_KEY_ID,
-          :ensure => 'present',
-        })
-      end
       it 'contains the apt_key' do
         should contain_apt_key(title).with({
           :id                => GPG_KEY_ID,
@@ -66,12 +54,6 @@ describe 'apt::key', :type => :define do
         :ensure => 'absent',
       } end
 
-      it 'contains the apt::key' do
-        should contain_apt__key(title).with({
-          :key          => title,
-          :ensure       => 'absent',
-        })
-      end
       it 'contains the apt_key' do
         should contain_apt_key(title).with({
           :id                => title,
@@ -87,26 +69,22 @@ describe 'apt::key', :type => :define do
       end
     end
 
-    describe 'key_content =>' do
+    describe 'set a bunch of things!' do
       let :params do {
         :key_content => 'GPG key content',
+        :key_source => 'http://apt.puppetlabs.com/pubkey.gpg',
+        :key_server => 'pgp.mit.edu',
+        :key_options => 'debug',
       } end
 
-      it 'contains the apt::key' do
-        should contain_apt__key(title).with({
-          :key         => title,
-          :ensure      => 'present',
-          :key_content => params[:key_content],
-        })
-      end
       it 'contains the apt_key' do
         should contain_apt_key(title).with({
           :id                => title,
           :ensure            => 'present',
-          :source            => nil,
-          :server            => nil,
+          :source            => 'http://apt.puppetlabs.com/pubkey.gpg',
+          :server            => 'pgp.mit.edu',
           :content           => params[:key_content],
-          :keyserver_options => nil,
+          :keyserver_options => 'debug',
         })
       end
       it 'contains the apt_key present anchor' do
@@ -114,217 +92,131 @@ describe 'apt::key', :type => :define do
       end
     end
 
-    describe 'key_source =>' do
-      let :params do {
-        :key_source => 'http://apt.puppetlabs.com/pubkey.gpg',
+    context "domain with dash" do
+      let(:params) do{
+        :key_server => 'p-gp.m-it.edu',
       } end
-
-      it 'contains the apt::key' do
-        should contain_apt__key(title).with({
-          :key         => title,
-          :ensure      => 'present',
-          :key_source => params[:key_source],
+      it 'contains the apt_key' do
+        should contain_apt_key(title).with({
+          :id        => title,
+          :server => 'p-gp.m-it.edu',
         })
       end
+    end
+
+    context "url" do
+      let :params do
+        {
+          :key_server => 'hkp://pgp.mit.edu',
+        }
+      end
       it 'contains the apt_key' do
         should contain_apt_key(title).with({
-          :id                => title,
-          :ensure            => 'present',
-          :source            => params[:key_source],
-          :server            => nil,
-          :content           => nil,
-          :keyserver_options => nil,
+          :id        => title,
+          :server => 'hkp://pgp.mit.edu',
         })
       end
-      it 'contains the apt_key present anchor' do
-        should contain_anchor("apt_key #{title} present")
-      end
     end
-
-    describe 'key_server =>' do
-       context 'domain name' do
-        let :params do {
-          :key_server => 'pgp.mit.edu',
-       } end
-
-       it 'contains the apt::key' do
-          should contain_apt__key(title).with({
-            :key         => title,
-            :ensure      => 'present',
-            :key_server  => 'pgp.mit.edu',
-          })
-       end
-       it 'contains the apt_key' do
-          should contain_apt_key(title).with({
-            :id                => title,
-            :ensure            => 'present',
-            :source            => nil,
-            :server            => params[:key_server],
-            :content           => nil,
-            :keyserver_options => nil,
-          })
-       end
-       it 'contains the apt_key present anchor' do
-          should contain_anchor("apt_key #{title} present")
-       end
-                       end
-
-      context "domain with dash" do
-        let(:params) do{
-          :key_server => 'p-gp.m-it.edu',
-        } end
-        it "should contain apt::key" do
-          should contain_apt__key(title).with({
-            :key        => title,
-            :ensure     => 'present',
-            :key_server => 'p-gp.m-it.edu',
-          })
-        end
+    context "url with port number" do
+      let :params do
+        {
+          :key_server => 'hkp://pgp.mit.edu:80',
+        }
       end
-
-      context "domain begin with dash" do
-        let(:params) do{
-          :key_server => '-pgp.mit.edu',
-        } end
-        it 'fails' do
-          expect { subject } .to raise_error(/does not match/)
-        end
+      it 'contains the apt_key' do
+        should contain_apt_key(title).with({
+          :id        => title,
+          :server => 'hkp://pgp.mit.edu:80',
+        })
       end
+    end
+  end
 
-      context "domain begin with dot" do
-        let(:params) do{
-          :key_server => '.pgp.mit.edu',
-        } end
-        it 'fails' do
-          expect { subject } .to raise_error(/does not match/)
-        end
+  describe 'validation' do
+    context "domain begin with dash" do
+      let(:params) do{
+        :key_server => '-pgp.mit.edu',
+      } end
+      it 'fails' do
+        expect { subject } .to raise_error(/does not match/)
       end
+    end
 
-      context "domain end with dot" do
-        let(:params) do{
-          :key_server => "pgp.mit.edu.",
-        } end
-        it 'fails' do
-          expect { subject } .to raise_error(/does not match/)
-        end
+    context "domain begin with dot" do
+      let(:params) do{
+        :key_server => '.pgp.mit.edu',
+      } end
+      it 'fails' do
+        expect { subject } .to raise_error(/does not match/)
       end
+    end
 
-      context "url" do
-        let (:params) do{
-          :key_server => 'hkp://pgp.mit.edu',
-        } end
-        it "should contain apt::key" do
-         should contain_apt__key(title).with({
-           :key         => title,
-           :ensure      => 'present',
-           :key_server  => 'hkp://pgp.mit.edu',
-         })
-        end
+    context "domain end with dot" do
+      let(:params) do{
+        :key_server => "pgp.mit.edu.",
+      } end
+      it 'fails' do
+        expect { subject } .to raise_error(/does not match/)
       end
-      context "url with port number" do
-        let (:params) do{
-          :key_server => 'hkp://pgp.mit.edu:80',
-        } end
-        it "should contain apt::key" do
-         should contain_apt__key(title).with({
-            :key        => title,
-            :ensure     => 'present',
-            :key_server => 'hkp://pgp.mit.edu:80',
-         })
-        end
+    end
+    context "exceed character url" do
+      let :params do
+        {
+          :key_server => 'hkp://pgpiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.mit.edu'
+        }
       end
-
-      context "incorrect port number url" do
-        let (:params) do{
+      it 'fails' do
+        expect { subject }.to raise_error(/does not match/)
+      end
+    end
+    context "incorrect port number url" do
+      let :params do
+        {
           :key_server => 'hkp://pgp.mit.edu:8008080'
-        } end
-        it 'fails' do
-          expect { subject }.to raise_error(/does not match/)
-        end
+        }
+      end
+      it 'fails' do
+        expect { subject }.to raise_error(/does not match/)
       end
-      context "incorrect protocol for  url" do
-        let (:params) do{
+    end
+    context "incorrect protocol for  url" do
+      let :params do
+        {
           :key_server => 'abc://pgp.mit.edu:80'
-        } end
-        it 'fails' do
-          expect { subject }.to raise_error(/does not match/)
-        end
+        }
       end
-      context "missing port number url" do
-        let (:params) do{
-          :key_server => 'hkp://pgp.mit.edu:'
-        } end
-        it 'fails' do
-          expect { subject }.to raise_error(/does not match/)
-        end
+      it 'fails' do
+        expect { subject }.to raise_error(/does not match/)
       end
-      context "url ending with a dot" do
-        let (:params) do{
-          :key_server => 'hkp://pgp.mit.edu.'
-        } end
-        it 'fails' do
-          expect { subject }.to raise_error(/does not match/)
-        end
+    end
+    context "missing port number url" do
+      let :params do
+        {
+          :key_server => 'hkp://pgp.mit.edu:'
+        }
       end
-      context "url begin with a dash" do
-        let(:params) do{
-          :key_server => "hkp://-pgp.mit.edu",
-        } end
-        it 'fails' do
-          expect { subject }.to raise_error(/does not match/)
-        end
+      it 'fails' do
+        expect { subject }.to raise_error(/does not match/)
       end
-      context "url with dash" do
-        let(:params) do{
-          :key_server => 'hkp://p-gp.m-it.edu',
-        } end
-        it "should contain apt::key" do
-          should contain_apt__key(title).with({
-            :key        => title,
-            :ensure     => 'present',
-            :key_server => 'hkp://p-gp.m-it.edu',
-          })
-        end
+    end
+    context "url ending with a dot" do
+      let :params do
+        {
+          :key_server => 'hkp://pgp.mit.edu.'
+        }
       end
-      context "exceed characher url" do
-        let (:params) do{
-          :key_server => 'hkp://pgpiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.mit.edu'
-        } end
-        it 'fails' do
-          expect { subject }.to raise_error(/does not match/)
-        end
+      it 'fails' do
+        expect { subject }.to raise_error(/does not match/)
       end
-               end
-
-    describe 'key_options =>' do
-      let :params do {
-        :key_options => 'debug',
+    end
+    context "url begin with a dash" do
+      let(:params) do{
+        :key_server => "hkp://-pgp.mit.edu",
       } end
-
-      it 'contains the apt::key' do
-        should contain_apt__key(title).with({
-          :key          => title,
-          :ensure       => 'present',
-          :key_options  => 'debug',
-        })
-      end
-      it 'contains the apt_key' do
-        should contain_apt_key(title).with({
-          :id                => title,
-          :ensure            => 'present',
-          :source            => nil,
-          :server            => nil,
-          :content           => nil,
-          :keyserver_options => params[:key_options],
-        })
-      end
-      it 'contains the apt_key present anchor' do
-        should contain_anchor("apt_key #{title} present")
+      it 'fails' do
+        expect { subject }.to raise_error(/does not match/)
       end
     end
-  end
-
-  describe 'validation' do
     context 'invalid key' do
       let :title do
         'Out of rum. Why? Why are we out of rum?'
@@ -369,44 +261,55 @@ describe 'apt::key', :type => :define do
         expect { subject }.to raise_error(/is not a string/)
       end
     end
-  end
 
-  describe 'duplication' do
-    context 'two apt::key resources for same key, different titles' do
-      let :pre_condition do
-        "apt::key { 'duplicate': key => #{title}, }"
+    context 'invalid ensure' do
+      let :params do
+        {
+          :ensure => 'foo',
+        }
       end
-
-      it 'contains two apt::key resources' do
-        should contain_apt__key('duplicate').with({
-          :key    => title,
-          :ensure => 'present',
-        })
-        should contain_apt__key(title).with({
-          :key    => title,
-          :ensure => 'present',
-        })
-      end
-
-      it 'contains only a single apt_key' do
-        should contain_apt_key('duplicate').with({
-          :id                => title,
-          :ensure            => 'present',
-          :source            => nil,
-          :server            => nil,
-          :content           => nil,
-          :keyserver_options => nil,
-        })
-        should_not contain_apt_key(title)
+      it 'fails' do
+        expect { subject }.to raise_error(/does not match/)
       end
     end
 
-    context 'two apt::key resources, different ensure' do
-      let :pre_condition do
-        "apt::key { 'duplicate': key => #{title}, ensure => 'absent', }"
+    describe 'duplication' do
+      context 'two apt::key resources for same key, different titles' do
+        let :pre_condition do
+          "apt::key { 'duplicate': key => #{title}, }"
+        end
+
+        it 'contains two apt::key resources' do
+          should contain_apt__key('duplicate').with({
+            :key    => title,
+            :ensure => 'present',
+          })
+          should contain_apt__key(title).with({
+            :key    => title,
+            :ensure => 'present',
+          })
+        end
+
+        it 'contains only a single apt_key' do
+          should contain_apt_key('duplicate').with({
+            :id                => title,
+            :ensure            => 'present',
+            :source            => nil,
+            :server            => nil,
+            :content           => nil,
+            :keyserver_options => nil,
+          })
+          should_not contain_apt_key(title)
+        end
       end
-      it 'informs the user of the impossibility' do
-        expect { subject }.to raise_error(/already ensured as absent/)
+
+      context 'two apt::key resources, different ensure' do
+        let :pre_condition do
+          "apt::key { 'duplicate': key => #{title}, ensure => 'absent', }"
+        end
+        it 'informs the user of the impossibility' do
+          expect { subject }.to raise_error(/already ensured as absent/)
+        end
       end
     end
   end
index d79462cd48ad4cb7a1cccaa50ef499e252725027..23ebd59b32d77d08c28108a3c9ff79c64ead7175 100644 (file)
@@ -3,118 +3,165 @@ describe 'apt::pin', :type => :define do
   let(:facts) { { :lsbdistid => 'Debian' } }
   let(:title) { 'my_pin' }
 
-  let :default_params do
-    {
-      :ensure   => 'present',
-      :order    => '',
-      :packages => '*',
-      :priority => '0',
-      :release  => nil
+  context 'defaults' do
+    it { is_expected.to contain_file("my_pin.pref").with_content(/Explanation: : my_pin\nPackage: \*\nPin: release a=my_pin\nPin-Priority: 0\n/)}
+    it { is_expected.to contain_file("my_pin.pref").with({
+      'ensure' => 'present',
+      'path'   => '/etc/apt/preferences.d/my_pin.pref',
+      'owner'  => 'root',
+      'group'  => 'root',
+      'mode'   => '0644',
+    })
     }
   end
 
-  [
-    { :params  => {},
-      :content => "Explanation: : my_pin\nPackage: *\nPin: release a=my_pin\nPin-Priority: 0\n"
-    },
-    {
-      :params => {
-        :packages => 'apache',
-        :priority => '1'
-      },
-      :content => "Explanation: : my_pin\nPackage: apache\nPin: release a=my_pin\nPin-Priority: 1\n"
-    },
-    {
-      :params => {
-        :order    => 50,
-        :packages => 'apache',
-        :priority => '1'
-      },
-      :content => "Explanation: : my_pin\nPackage: apache\nPin: release a=my_pin\nPin-Priority: 1\n"
-    },
-    {
-      :params => {
-        :ensure   => 'absent',
-        :packages => 'apache',
-        :priority => '1'
-      },
-      :content => "Explanation: : my_pin\nPackage: apache\nPin: release a=my_pin\nPin-Priority: 1\n"
-    },
-    {
-      :params => {
-        :packages => 'apache',
-        :priority => '1',
-        :release  => 'my_newpin'
-      },
-      :content => "Explanation: : my_pin\nPackage: apache\nPin: release a=my_newpin\nPin-Priority: 1\n"
-    },
-    {
-      :params => {
-        :packages => 'apache',
-        :priority => '1',
-        :version  => '2.2.16*'
-      },
-      :content => "Explanation: : my_pin\nPackage: apache\nPin: version 2.2.16*\nPin-Priority: 1\n"
-    },
-    {
-      :params => {
-        :priority => '1',
-        :origin   => 'ftp.de.debian.org'
-      },
-      :content => "Explanation: : my_pin\nPackage: *\nPin: origin ftp.de.debian.org\nPin-Priority: 1\n"
-    },
-    {
-      :params => {
-        :packages        => 'apache',
-        :priority        => '1',
-        :release         => 'stable',
-        :codename        => 'wheezy',
-        :release_version => '3.0',
-        :component       => 'main',
-        :originator      => 'Debian',
-        :label           => 'Debian'
-      },
-      :content => "Explanation: : my_pin\nPackage: apache\nPin: release a=stable, n=wheezy, v=3.0, c=main, o=Debian, l=Debian\nPin-Priority: 1\n"
-    },
-    {
-      :params => {
-        :packages        => ['apache', 'ntop'],
-      },
-      :content => "Explanation: : my_pin\nPackage: apache ntop\nPin: release a=my_pin\nPin-Priority: 0\n"
-    },
-  ].each do |param_set|
-    describe "when #{param_set == {} ? "using default" : "specifying"} define parameters" do
-      let :param_hash do
-        default_params.merge(param_set[:params])
-      end
+  context 'set version' do
+    let :params do
+      {
+        'packages' => 'vim',
+        'version'  => '1',
+      }
+    end
+    it { is_expected.to contain_file("my_pin.pref").with_content(/Explanation: : my_pin\nPackage: vim\nPin: version 1\nPin-Priority: 0\n/)}
+    it { is_expected.to contain_file("my_pin.pref").with({
+      'ensure' => 'present',
+      'path'   => '/etc/apt/preferences.d/my_pin.pref',
+      'owner'  => 'root',
+      'group'  => 'root',
+      'mode'   => '0644',
+    })
+    }
+  end
 
-      let :params do
-        param_set[:params]
-      end
+  context 'set origin' do
+    let :params do
+      {
+        'packages' => 'vim',
+        'origin'   => 'test',
+      }
+    end
+    it { is_expected.to contain_file("my_pin.pref").with_content(/Explanation: : my_pin\nPackage: vim\nPin: origin test\nPin-Priority: 0\n/)}
+    it { is_expected.to contain_file("my_pin.pref").with({
+      'ensure' => 'present',
+      'path'   => '/etc/apt/preferences.d/my_pin.pref',
+      'owner'  => 'root',
+      'group'  => 'root',
+      'mode'   => '0644',
+    })
+    }
+  end
 
-      it { should contain_class("apt::params") }
+  context 'not defaults' do
+    let :params do
+      {
+        'explanation'     => 'foo',
+        'order'           => 99,
+        'release'         => '1',
+        'codename'        => 'bar',
+        'release_version' => '2',
+        'component'       => 'baz',
+        'originator'      => 'foobar',
+        'label'           => 'foobaz',
+        'priority'        => 10,
+      }
+    end
+    it { is_expected.to contain_file("my_pin.pref").with_content(/Explanation: foo\nPackage: \*\nPin: release a=1, n=bar, v=2, c=baz, o=foobar, l=foobaz\nPin-Priority: 10\n/) }
+    it { is_expected.to contain_file("my_pin.pref").with({
+      'ensure' => 'present',
+      'path'   => '/etc/apt/preferences.d/99-my_pin.pref',
+      'owner'  => 'root',
+      'group'  => 'root',
+      'mode'   => '0644',
+    })
+    }
+  end
 
-      it { should contain_file("#{title}.pref").with({
-          'ensure'  => param_hash[:ensure],
-          'path'    => "/etc/apt/preferences.d/#{param_hash[:order] == '' ? "" : "#{param_hash[:order]}-"}#{title}.pref",
-          'owner'   => 'root',
-          'group'   => 'root',
-          'mode'    => '0644',
-          'content' => param_set[:content],
-        })
+  context 'ensure absent' do
+    let :params do
+      {
+        'ensure' => 'absent'
       }
     end
+    it { is_expected.to contain_file("my_pin.pref").with({
+      'ensure' => 'absent',
+    })
+    }
+  end
+
+  context 'bad characters' do
+    let(:title) { 'such  bad && wow!' }
+    it { is_expected.to contain_file("such__bad____wow_.pref") }
   end
 
-  describe 'resource title with invalid chars' do
-    context 'spaces' do
-      let(:title) { 'oh my god this is not valid' }
-      it { should contain_file('oh_my_god_this_is_not_valid.pref') }
+  describe 'validation' do
+    context 'invalid order' do
+      let :params do
+        {
+          'order' => 'foo',
+        }
+      end
+      it do
+        expect {
+          should compile
+        }.to raise_error(Puppet::Error, /Only integers are allowed/)
+      end
+    end
+
+    context 'packages == * and version' do
+      let :params do
+        {
+          'version' => '1',
+        }
+      end
+      it do
+        expect {
+          should compile
+        }.to raise_error(Puppet::Error, /parameter version cannot be used in general form/)
+      end
     end
 
-    context '#$&*$' do
-      let(:title) { 'so && many $* invalid @! things' }
-      it { should contain_file('so____many____invalid____things.pref') }
+    context 'packages == * and release and origin' do
+      let :params do
+        {
+          'origin'  => 'test',
+          'release' => 'foo',
+        }
+      end
+      it do
+        expect {
+          should compile
+        }.to raise_error(Puppet::Error, /parameters release and origin are mutually exclusive/)
+      end
+    end
+
+    context 'specific form with release and origin' do
+      let :params do
+        {
+          'release'  => 'foo',
+          'origin'   => 'test',
+          'packages' => 'vim',
+        }
+      end
+      it do
+        expect {
+          should compile
+        }.to raise_error(Puppet::Error, /parameters release, origin, and version are mutually exclusive/)
+      end
+    end
+
+    context 'specific form with version and origin' do
+      let :params do
+        {
+          'version'  => '1',
+          'origin'   => 'test',
+          'packages' => 'vim',
+        }
+      end
+      it do
+        expect {
+          should compile
+        }.to raise_error(Puppet::Error, /parameters release, origin, and version are mutually exclusive/)
+      end
     end
   end
 end
index 6944f9b2dfc8f67d951bb3d53a7179759003e4f0..3a4c381f6746f794ff037c284bb20766a2ba8145 100644 (file)
 require 'spec_helper'
 describe 'apt::ppa', :type => :define do
-  [
-    {
-      :lsbdistrelease  => '11.04',
-      :lsbdistcodename => 'natty',
-      :operatingsystem => 'Ubuntu',
-      :lsbdistid       => 'Ubuntu',
-      :package         => 'python-software-properties'
-    },
-    {
-      :lsbdistrelease  => '12.10',
-      :lsbdistcodename => 'quantal',
-      :operatingsystem => 'Ubuntu',
-      :lsbdistid       => 'Ubuntu',
-      :package         => 'software-properties-common'
-    },
-  ].each do |platform|
-    context "on #{platform[:lsbdistcodename]}" do
-      let :facts do
-        {
-          :lsbdistrelease  => platform[:lsbdistrelease],
-          :lsbdistcodename => platform[:lsbdistcodename],
-          :operatingsystem => platform[:operatingsystem],
-          :lsbdistid       => platform[:lsbdistid],
-          :osfamily        => 'Debian',
-        }
-      end
-      let :release do
-        "#{platform[:lsbdistcodename]}"
-      end
-      let :package do
-        "#{platform[:package]}"
-      end
-      let :options do
-        "-y"
-      end
-      ['ppa:dans_ppa', 'dans_ppa','ppa:dans-daily/ubuntu'].each do |t|
-        describe "with title #{t}" do
-          let :pre_condition do
-            'class { "apt": }'
-          end
-          let :title do
-            t
-          end
-          let :filename do
-            t.sub(/^ppa:/,'').gsub('/','-') << "-" << "#{release}.list"
-          end
-
-          it { should contain_package("#{package}") }
 
-          it { should contain_exec("apt_update").with(
-            'command'     => '/usr/bin/apt-get update',
-            'refreshonly' => true
-            )
-          }
+  describe 'defaults' do
+    let :pre_condition do
+      'class { "apt": }'
+    end
+    let :facts do
+      {
+        :lsbdistrelease  => '11.04',
+        :lsbdistcodename => 'natty',
+        :operatingsystem => 'Ubuntu',
+        :osfamily        => 'Debian',
+        :lsbdistid       => 'Ubuntu',
+      }
+    end
 
-          it { should contain_exec("add-apt-repository-#{t}").with(
-            'command' => "/usr/bin/add-apt-repository #{options} #{t}",
-            'unless'  => "/usr/bin/test -s /etc/apt/sources.list.d/#{filename}",
-            'require' => ["File[sources.list.d]", "Package[#{package}]"],
-            'notify'  => "Exec[apt_update]"
-            )
-          }
+    let(:title) { 'ppa:needs/such.substitution/wow' }
+    it { is_expected.to contain_package('python-software-properties') }
+    it { is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow').that_notifies('Exec[apt_update]').with({
+      'environment' => [],
+      'command'     => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow',
+      'unless'      => '/usr/bin/test -s /etc/apt/sources.list.d/needs-such_substitution-wow-natty.list',
+      'user'        => 'root',
+      'logoutput'   => 'on_failure',
+    })
+    }
 
-          it { should create_file("/etc/apt/sources.list.d/#{filename}").with(
-            'ensure'  => 'file',
-            'require' => "Exec[add-apt-repository-#{t}]"
-            )
-          }
-        end
-      end
-      describe 'without a proxy defined' do
-        let :title do
-          'rspec_ppa'
-        end
-        let :pre_condition do
-          'class { "apt":
-             proxy_host => false
-          }'
-        end
-        let :filename do
-          "#{title}-#{release}.list"
-        end
+    it { is_expected.to contain_file('/etc/apt/sources.list.d/needs-such_substitution-wow-natty.list').that_requires('Exec[add-apt-repository-ppa:needs/such.substitution/wow]').with({
+      'ensure' => 'file',
+    })
+    }
+  end
 
-        it { should contain_exec("add-apt-repository-#{title}").with(
-          'environment' => [],
-          'command'     => "/usr/bin/add-apt-repository #{options} #{title}",
-          'unless'      => "/usr/bin/test -s /etc/apt/sources.list.d/#{filename}",
-          'require'     => ["File[sources.list.d]", "Package[#{package}]"],
-          'notify'      => "Exec[apt_update]"
-          )
-        }
-      end
+  describe 'apt included, no proxy' do
+    let :pre_condition do
+      'class { "apt": }'
+    end
+    let :facts do
+      {
+        :lsbdistrelease  => '14.04',
+        :lsbdistcodename => 'trusty',
+        :operatingsystem => 'Ubuntu',
+        :lsbdistid       => 'Ubuntu',
+        :osfamily        => 'Debian',
+      }
+    end
+    let :params do
+      {
+        'options' => '',
+      }
+    end
+    let(:title) { 'ppa:foo' }
+    it { is_expected.to contain_package('software-properties-common') }
+    it { is_expected.to contain_exec('add-apt-repository-ppa:foo').that_notifies('Exec[apt_update]').with({
+      'environment' => [],
+      'command'     => '/usr/bin/add-apt-repository  ppa:foo',
+      'unless'      => '/usr/bin/test -s /etc/apt/sources.list.d/foo-trusty.list',
+      'user'        => 'root',
+      'logoutput'   => 'on_failure',
+    })
+    }
 
-      describe 'behind a proxy' do
-        let :title do
-          'rspec_ppa'
-        end
-        let :pre_condition do
-          'class { "apt":
-            proxy_host => "user:pass@proxy",
-          }'
-        end
-          let :filename do
-            "#{title}-#{release}.list"
-          end
+    it { is_expected.to contain_file('/etc/apt/sources.list.d/foo-trusty.list').that_requires('Exec[add-apt-repository-ppa:foo]').with({
+      'ensure' => 'file',
+    })
+    }
+  end
 
-        it { should contain_exec("add-apt-repository-#{title}").with(
-          'environment' => [
-            "http_proxy=http://user:pass@proxy:8080",
-            "https_proxy=http://user:pass@proxy:8080",
-          ],
-          'command'     => "/usr/bin/add-apt-repository #{options} #{title}",
-          'unless'      => "/usr/bin/test -s /etc/apt/sources.list.d/#{filename}",
-          'require'     => ["File[sources.list.d]", "Package[#{package}]"],
-          'notify'      => "Exec[apt_update]"
-          )
-        }
-      end
+  describe 'apt included, proxy' do
+    let :pre_condition do
+      'class { "apt": proxy_host => "example.com" }'
     end
+    let :facts do
+      {
+        :lsbdistrelease  => '14.04',
+        :lsbdistcodename => 'trusty',
+        :operatingsystem => 'Ubuntu',
+        :lsbdistid       => 'Ubuntu',
+        :osfamily        => 'Debian',
+      }
+    end
+    let :params do
+      {
+        'release' => 'lucid',
+      }
+    end
+    let(:title) { 'ppa:foo' }
+    it { is_expected.to contain_package('software-properties-common') }
+    it { is_expected.to contain_exec('add-apt-repository-ppa:foo').that_notifies('Exec[apt_update]').with({
+      'environment' => ['http_proxy=http://example.com:8080', 'https_proxy=http://example.com:8080'],
+      'command'     => '/usr/bin/add-apt-repository -y ppa:foo',
+      'unless'      => '/usr/bin/test -s /etc/apt/sources.list.d/foo-lucid.list',
+      'user'        => 'root',
+      'logoutput'   => 'on_failure',
+    })
+    }
+
+    it { is_expected.to contain_file('/etc/apt/sources.list.d/foo-lucid.list').that_requires('Exec[add-apt-repository-ppa:foo]').with({
+      'ensure' => 'file',
+    })
+    }
   end
 
-  [ { :lsbdistcodename => 'natty',
-      :package => 'python-software-properties' },
-    { :lsbdistcodename => 'quantal',
-      :package => 'software-properties-common'},
-  ].each do |platform|
-    context "on #{platform[:lsbdistcodename]}" do
-      describe "it should not error if package['#{platform[:package]}'] is already defined" do
-        let :pre_condition do
-           'class {"apt": }' +
-           'package { "#{platform[:package]}": }->Apt::Ppa["ppa"]'
-        end
-        let :facts do
-          {:lsbdistcodename => '#{platform[:lsbdistcodename]}',
-           :operatingsystem => 'Ubuntu',
-           :lsbdistid => 'Ubuntu',
-           :osfamily => 'Debian'}
-        end
-        let(:title) { "ppa" }
-        let(:release) { "#{platform[:lsbdistcodename]}" }
-        it { should contain_package('#{platform[:package]}') }
-      end
+  describe 'ensure absent' do
+    let :facts do
+      {
+        :lsbdistrelease  => '14.04',
+        :lsbdistcodename => 'trusty',
+        :operatingsystem => 'Ubuntu',
+        :lsbdistid       => 'Ubuntu',
+        :osfamily        => 'Debian',
+      }
+    end
+    let(:title) { 'ppa:foo' }
+    let :params do
+      {
+        'ensure' => 'absent'
+      }
     end
+    it { is_expected.to contain_file('/etc/apt/sources.list.d/foo-trusty.list').that_notifies('Exec[apt_update]').with({
+      'ensure' => 'absent',
+    })
+    }
   end
 
-  describe "without Class[apt] should raise a Puppet::Error" do
-    let(:release) { "natty" }
-    let(:title) { "ppa" }
-    it { expect { should contain_apt__ppa(title) }.to raise_error(Puppet::Error) }
-  end
+  context 'validation' do
+    describe 'no release' do
+      let :facts do
+        {
+          :lsbdistrelease  => '14.04',
+          :operatingsystem => 'Ubuntu',
+          :lsbdistid       => 'Ubuntu',
+          :osfamily        => 'Debian',
+        }
+      end
+      let(:title) { 'ppa:foo' }
+      it do
+        expect {
+          should compile
+        }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/)
+      end
+    end
 
-  describe "without release should raise a Puppet::Error" do
-    let(:title) { "ppa:" }
-    it { expect { should contain_apt__ppa(:release) }.to raise_error(Puppet::Error) }
+    describe 'not ubuntu' do
+      let :facts do
+        {
+          :lsbdistrelease  => '14.04',
+          :lsbdistcodename => 'trusty',
+          :operatingsystem => 'Debian',
+          :lsbdistid       => 'Ubuntu',
+          :osfamily        => 'Debian',
+        }
+      end
+      let(:title) { 'ppa:foo' }
+      it do
+        expect {
+          should compile
+        }.to raise_error(Puppet::Error, /apt::ppa is currently supported on Ubuntu only./)
+      end
+    end
   end
 end
index 284adca27fe4496413607bdc0b638b127ee8d858..960bb620fc8fa8efe451e722ac56adc49c855471 100644 (file)
 require 'spec_helper'
 
 describe 'apt::source', :type => :define do
-  let(:facts) { { :lsbdistid => 'Debian' } }
   GPG_KEY_ID = '4BD6EC30'
 
   let :title do
     'my_source'
   end
 
-  let :default_params do
-    {
-      :ensure             => 'present',
-      :location           => '',
-      :release            => 'karmic',
-      :repos              => 'main',
-      :include_src        => true,
-      :include_deb        => true,
-      :required_packages  => false,
-      :key                => false,
-      :key_server         => false,
-      :key_content        => false,
-      :key_source         => false,
-      :pin                => false
-    }
-  end
+  context 'mostly defaults' do
+    let :facts do
+      {
+        :lsbdistid       => 'Debian',
+        :lsbdistcodename => 'wheezy',
+      }
+    end
 
-  [{},
-   {
-      :location           => 'http://example.com',
-      :release            => 'precise',
-      :repos              => 'security',
-      :include_src        => false,
-      :required_packages  => 'apache',
-      :key                => GPG_KEY_ID,
-      :key_server         => 'keyserver.debian.com',
-      :pin                => '600',
-      :key_content        => 'ABCD1234'
-    },
-    {
-      :key                => GPG_KEY_ID,
-      :key_server         => 'keyserver.debian.com',
-    },
-    {
-      :ensure             => 'absent',
-      :location           => 'http://example.com',
-      :release            => 'precise',
-      :repos              => 'security',
-    },
-    {
-      :release            => '',
-    },
-    {
-      :release            => 'custom',
-    },
-    {
-      :architecture       => 'amd64',
+    let :params do
+      {
+        'include_deb' => false,
+      }
+    end
+
+    it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({
+      'ensure' => 'present',
+      'path'   => '/etc/apt/sources.list.d/my_source.list',
+      'owner'  => 'root',
+      'group'  => 'root',
+      'mode'   => '0644',
+    }).with_content(/#file generated by puppet\n# my_source\ndeb-src  wheezy main\n/)
     }
-  ].each do |param_set|
-    describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
-      let :param_hash do
-        default_params.merge(param_set)
-      end
+  end
 
-      let :facts do
-        {:lsbdistcodename => 'karmic', :lsbdistid => 'Ubuntu'}
-      end
+  context 'no defaults' do
+    let :facts do
+      {
+        :lsbdistid       => 'Debian',
+        :lsbdistcodename => 'wheezy',
+      }
+    end
+    let :params do
+      {
+        'comment'           => 'foo',
+        'location'          => 'http://debian.mirror.iweb.ca/debian/',
+        'release'           => 'sid',
+        'repos'             => 'testing',
+        'include_src'       => false,
+        'required_packages' => 'vim',
+        'key'               => GPG_KEY_ID,
+        'key_server'        => 'pgp.mit.edu',
+        'key_content'       => 'GPG key content',
+        'key_source'        => 'http://apt.puppetlabs.com/pubkey.gpg',
+        'pin'               => '10',
+        'architecture'      => 'x86_64',
+      }
+    end
 
-      let :params do
-        param_set
-      end
+    it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({
+      'ensure' => 'present',
+      'path'   => '/etc/apt/sources.list.d/my_source.list',
+      'owner'  => 'root',
+      'group'  => 'root',
+      'mode'   => '0644',
+    }).with_content(/#file generated by puppet\n# foo\ndeb \[arch=x86_64\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(/deb-src/)
+    }
 
-      let :filename do
-        "/etc/apt/sources.list.d/#{title}.list"
-      end
+    it { is_expected.to contain_apt__pin('my_source').that_comes_before('File[my_source.list]').with({
+      'ensure'   => 'present',
+      'priority' => '10',
+      'origin'   => 'debian.mirror.iweb.ca',
+    })
+    }
 
-      let :content do
-        content = "#file generated by puppet\n"
-       if param_hash[:comment]
-         content << "# #{comment}"
-       else
-         content << "# #{title}"
-       end
-        if param_hash[:architecture]
-          arch = "[arch=#{param_hash[:architecture]}] "
-        end
-        if param_hash[:include_deb]
-         content << "\ndeb #{arch}#{param_hash[:location]} #{param_hash[:release]} #{param_hash[:repos]}\n"
-       end
-        if param_hash[:include_src]
-          content << "deb-src #{arch}#{param_hash[:location]} #{param_hash[:release]} #{param_hash[:repos]}\n"
-        end
-        content
-      end
+    it { is_expected.to contain_exec("Required packages: 'vim' for my_source").that_comes_before('Exec[apt_update]').that_subscribes_to('File[my_source.list]').with({
+      'command'     => '/usr/bin/apt-get -y install vim',
+      'logoutput'   => 'on_failure',
+      'refreshonly' => true,
+      'tries'       => '3',
+      'try_sleep'   => '1',
+    })
+    }
 
-      it { should contain_apt__params }
+    it { is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('File[my_source.list]').with({
+      'ensure' => 'present',
+        'key'  => GPG_KEY_ID,
+        'key_server' => 'pgp.mit.edu',
+        'key_content' => 'GPG key content',
+        'key_source' => 'http://apt.puppetlabs.com/pubkey.gpg',
+    })
+    }
+  end
 
-      it { should contain_file("#{title}.list").with({
-          'ensure'    => param_hash[:ensure],
-          'path'      => filename,
-          'owner'     => 'root',
-          'group'     => 'root',
-          'mode'      => '0644',
-          'content'   => content,
-        })
+  context 'ensure => absent' do
+    let :facts do
+      {
+        :lsbdistid       => 'Debian',
+        :lsbdistcodename => 'wheezy',
       }
-
-      it {
-        if param_hash[:pin]
-          should contain_apt__pin(title).with({
-            "priority"  => param_hash[:pin],
-            "before"    => "File[#{title}.list]"
-          })
-        else
-          should_not contain_apt__pin(title).with({
-            "priority"  => param_hash[:pin],
-            "before"    => "File[#{title}.list]"
-          })
-        end
+    end
+    let :params do
+      {
+        'ensure' => 'absent',
       }
+    end
 
-      it {
-        should contain_exec("apt_update").with({
-          "command"     => "/usr/bin/apt-get update",
-          "refreshonly" => true
-        })
-      }
+    it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({
+      'ensure' => 'absent'
+    })
+    }
+  end
 
-      it {
-        if param_hash[:required_packages]
-          should contain_exec("Required packages: '#{param_hash[:required_packages]}' for #{title}").with({
-            "command" => "/usr/bin/apt-get -y install #{param_hash[:required_packages]}",
-            "subscribe"   => "File[#{title}.list]",
-            "refreshonly" => true,
-            "before"      => 'Exec[apt_update]',
-          })
-        else
-          should_not contain_exec("Required packages: '#{param_hash[:required_packages]}' for #{title}").with({
-            "command"     => "/usr/bin/apt-get -y install #{param_hash[:required_packages]}",
-            "subscribe"   => "File[#{title}.list]",
-            "refreshonly" => true
-          })
-        end
-      }
+  describe 'validation' do
+    context 'no release' do
+      let :facts do
+        {
+          :lsbdistid       => 'Debian',
+        }
+      end
 
-      it {
-        key_server  = param_hash[:key_server]  || nil
-        key_content = param_hash[:key_content] || nil
-        key_source  = param_hash[:key_source]  || nil
-        if param_hash[:key]
-          should contain_apt__key("Add key: #{param_hash[:key]} from Apt::Source #{title}").with({
-            "key"         => param_hash[:key],
-            "ensure"      => :present,
-            "key_server"  => key_server,
-            "key_content" => key_content,
-            "key_source"  => key_source,
-            "before"      => "File[#{title}.list]"
-          })
-        else
-          should_not contain_apt__key("Add key: #{param_hash[:key]} from Apt::Source #{title}").with({
-            "key"         => param_hash[:key],
-            "ensure"      => :present,
-            "key_server"  => param_hash[:key_server],
-            "key_content" => param_hash[:key_content],
-            "key_source"  => param_hash[:key_source],
-            "before"      => "File[#{title}.list]"
-          })
-        end
-      }
+      it do
+        expect {
+          should compile
+        }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/)
+      end
     end
   end
-  describe "without release should raise a Puppet::Error" do
-    let(:default_params) { Hash.new }
-    let(:facts) { Hash.new }
-    it { expect { should raise_error(Puppet::Error) } }
-    let(:facts) { { :lsbdistcodename => 'lucid', :lsbdistid => 'Ubuntu' } }
-    it { should contain_apt__source(title) }
-  end
 end