Index: src/puppetcode/environments/test/modules/apt/spec/acceptance/apt_key_provider_spec.rb
===================================================================
--- src/puppetcode/environments/test/modules/apt/spec/acceptance/apt_key_provider_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/spec/acceptance/apt_key_provider_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,738 @@
+require 'spec_helper_acceptance'
+
+PUPPETLABS_GPG_KEY_SHORT_ID    = '4BD6EC30'
+PUPPETLABS_GPG_KEY_LONG_ID     = '1054B7A24BD6EC30'
+PUPPETLABS_GPG_KEY_FINGERPRINT = '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30'
+PUPPETLABS_APT_URL             = 'apt.puppetlabs.com'
+PUPPETLABS_GPG_KEY_FILE        = 'pubkey.gpg'
+CENTOS_GPG_KEY_SHORT_ID        = 'C105B9DE'
+CENTOS_GPG_KEY_LONG_ID         = '0946FCA2C105B9DE'
+CENTOS_GPG_KEY_FINGERPRINT     = 'C1DAC52D1664E8A4386DBA430946FCA2C105B9DE'
+CENTOS_REPO_URL                = 'ftp.cvut.cz/centos'
+CENTOS_GPG_KEY_FILE            = 'RPM-GPG-KEY-CentOS-6'
+
+SHOULD_NEVER_EXIST_ID          = '4BD6EC30'
+
+KEY_CHECK_COMMAND              = "apt-key adv --list-keys --with-colons --fingerprint | grep "
+PUPPETLABS_KEY_CHECK_COMMAND   = "#{KEY_CHECK_COMMAND} #{PUPPETLABS_GPG_KEY_FINGERPRINT}"
+CENTOS_KEY_CHECK_COMMAND       = "#{KEY_CHECK_COMMAND} #{CENTOS_GPG_KEY_FINGERPRINT}"
+
+describe 'apt_key' do
+  before(:each) do
+    # Delete twice to make sure everything is cleaned
+    # up after the short key collision
+    shell("apt-key del #{PUPPETLABS_GPG_KEY_SHORT_ID}",
+          :acceptable_exit_codes => [0,1,2])
+    shell("apt-key del #{PUPPETLABS_GPG_KEY_SHORT_ID}",
+          :acceptable_exit_codes => [0,1,2])
+  end
+
+  describe 'default options' do
+    key_versions = {
+      '32bit key id'                        => '4BD6EC30',
+      '64bit key id'                        => '1054B7A24BD6EC30',
+      '160bit key fingerprint'              => '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30',
+      '32bit lowercase key id'              => '4bd6ec30',
+      '64bit lowercase key id'              => '1054b7a24bd6ec30',
+      '160bit lowercase key fingerprint'    => '47b320eb4c7c375aa9dae1a01054b7a24bd6ec30',
+      '0x formatted 32bit key id'           => '0x4BD6EC30',
+      '0x formatted 64bit key id'           => '0x1054B7A24BD6EC30',
+      '0x formatted 160bit key fingerprint' => '0x47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30',
+      '0x formatted 32bit lowercase key id' => '0x4bd6ec30',
+      '0x formatted 64bit lowercase key id' => '0x1054b7a24bd6ec30',
+      '0x formatted 160bit lowercase key fingerprint' => '0x47b320eb4c7c375aa9dae1a01054b7a24bd6ec30',
+    }
+
+    key_versions.each do |key, value|
+      context "#{key}" do
+        it 'works' do
+          pp = <<-EOS
+          apt_key { 'puppetlabs':
+            id     => '#{value}',
+            ensure => 'present',
+          }
+          EOS
+
+          apply_manifest(pp, :catch_failures => true)
+          apply_manifest(pp, :catch_changes => true)
+          shell(PUPPETLABS_KEY_CHECK_COMMAND)
+        end
+      end
+    end
+
+    context 'invalid length key id' do
+      it 'fails' do
+        pp = <<-EOS
+        apt_key { 'puppetlabs':
+          id => '4B7A24BD6EC30',
+        }
+        EOS
+
+        apply_manifest(pp, :expect_failures => true) do |r|
+          expect(r.stderr).to match(/Valid values match/)
+        end
+      end
+    end
+  end
+
+  describe 'ensure =>' do
+    context 'absent' do
+      it 'is removed' do
+        pp = <<-EOS
+        apt_key { 'centos':
+          id     => '#{CENTOS_GPG_KEY_LONG_ID}',
+          ensure => 'absent',
+        }
+        EOS
+
+        # Install the key first
+        shell("apt-key adv --keyserver keyserver.ubuntu.com \
+              --recv-keys #{CENTOS_GPG_KEY_FINGERPRINT}")
+        shell(CENTOS_KEY_CHECK_COMMAND)
+
+        # Time to remove it using Puppet
+        apply_manifest(pp, :catch_failures => true)
+        apply_manifest(pp, :catch_failures => true)
+
+        shell(CENTOS_KEY_CHECK_COMMAND,
+              :acceptable_exit_codes => [1])
+
+        shell("apt-key adv --keyserver keyserver.ubuntu.com \
+              --recv-keys #{CENTOS_GPG_KEY_FINGERPRINT}")
+      end
+    end
+
+    context 'absent, added with long key', :unless => (fact('operatingsystem') == 'Debian' and fact('operatingsystemmajrelease') == '6') do
+      it 'is removed' do
+        pp = <<-EOS
+        apt_key { 'puppetlabs':
+          id     => '#{PUPPETLABS_GPG_KEY_LONG_ID}',
+          ensure => 'absent',
+        }
+        EOS
+
+        # Install the key first
+        shell("apt-key adv --keyserver keyserver.ubuntu.com \
+              --recv-keys #{PUPPETLABS_GPG_KEY_LONG_ID}")
+        shell(PUPPETLABS_KEY_CHECK_COMMAND)
+
+        # Time to remove it using Puppet
+        apply_manifest(pp, :catch_failures => true)
+        apply_manifest(pp, :catch_failures => true)
+
+        shell(PUPPETLABS_KEY_CHECK_COMMAND,
+              :acceptable_exit_codes => [1])
+      end
+    end
+  end
+
+  describe 'content =>' do
+    context 'puppetlabs gpg key' do
+      it 'works' do
+        pp = <<-EOS
+          apt_key { 'puppetlabs':
+            id      => '#{PUPPETLABS_GPG_KEY_FINGERPRINT}',
+            ensure  => 'present',
+            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+
+S98g8Begwxs9JmGa8pMCcSxtC7fAfAEZ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qBAk9sWKptMl3NHiYTRE/m9VAk
+ugVIB2pi+8u84f+an4Hml4xlyijgYu05pqNvnLRyJDLd61hviLC8GYU=
+=a34C
+-----END PGP PUBLIC KEY BLOCK-----",
+          }
+        EOS
+
+        apply_manifest(pp, :catch_failures => true)
+        apply_manifest(pp, :catch_failures => true)
+        shell(PUPPETLABS_KEY_CHECK_COMMAND)
+      end
+    end
+
+    context 'multiple keys' do
+      it 'runs without errors' do
+        pp = <<-EOS
+          apt_key { 'puppetlabs':
+            id      => '#{PUPPETLABS_GPG_KEY_FINGERPRINT}',
+            ensure  => 'present',
+            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+k3wEmiaGz65w9jR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/+lA/MqRZ4kOD/Bx07
+CpZfYIAi2STc0MIDvpyDnZLiYVMMkqV4+gn2ANtkF+GKbra3Aeof9b4KEVabSaQ5
+5W70DJF0G5bmHBSdyqdYnKB/yRj1rH+dgRbiRMv7rBAx5Q8rbYiym8im+5XNUDy2
+ZTQcCD53HcBLvKX6RJ4ByYawKaQqMa27WK/YWVmFXqVDVk12iKrQW6zktDdGInnD
++f0rRH7c/7F/QuBR6Y4Zkso0CuVMNsmxv0E+7Zk0z4dWalzQuXpN7OXcZ8Gp
+=Gl+v
+-----END PGP PUBLIC KEY BLOCK-----",
+          }
+        EOS
+        apply_manifest(pp, :catch_failures => true)
+        apply_manifest(pp, :catch_failures => true)
+        shell(PUPPETLABS_KEY_CHECK_COMMAND)
+      end
+    end
+
+    context 'bogus key' do
+      it 'fails' do
+        pp = <<-EOS
+        apt_key { 'puppetlabs':
+          id      => '#{PUPPETLABS_GPG_KEY_LONG_ID}',
+          ensure  => 'present',
+          content => 'For posterity: such content, much bogus, wow',
+        }
+        EOS
+
+        apply_manifest(pp, :expect_failures => true) do |r|
+          expect(r.stderr).to match(/no valid OpenPGP data found/)
+        end
+      end
+    end
+  end
+
+  describe 'server =>' do
+    context 'pgp.mit.edu' do
+      it 'works' do
+        pp = <<-EOS
+        apt_key { 'puppetlabs':
+          id     => '#{PUPPETLABS_GPG_KEY_LONG_ID}',
+          ensure => 'present',
+          server => 'pgp.mit.edu',
+        }
+        EOS
+
+        apply_manifest(pp, :catch_failures => true)
+        apply_manifest(pp, :catch_failures => true)
+        shell(PUPPETLABS_KEY_CHECK_COMMAND)
+      end
+    end
+
+    context 'hkp://pgp.mit.edu:80' do
+      it 'works' do
+        pp = <<-EOS
+        apt_key { 'puppetlabs':
+          id     => '#{PUPPETLABS_GPG_KEY_FINGERPRINT}',
+          ensure => 'present',
+          server => 'hkp://pgp.mit.edu:80',
+        }
+        EOS
+
+        apply_manifest(pp, :catch_failures => true)
+        apply_manifest(pp, :catch_failures => true)
+        shell(PUPPETLABS_KEY_CHECK_COMMAND)
+      end
+    end
+
+    context 'nonexistant.key.server' do
+      it 'fails' do
+        pp = <<-EOS
+        apt_key { 'puppetlabs':
+          id     => '#{PUPPETLABS_GPG_KEY_LONG_ID}',
+          ensure => 'present',
+          server => 'nonexistant.key.server',
+        }
+        EOS
+
+        apply_manifest(pp, :expect_failures => true) do |r|
+          expect(r.stderr).to match(/(Host not found|Couldn't resolve host)/)
+        end
+      end
+    end
+
+    context 'key server start with dot' do
+      it 'fails' do
+        pp = <<-EOS
+        apt_key { 'puppetlabs':
+          id     => '#{PUPPETLABS_GPG_KEY_LONG_ID}',
+          ensure => 'present',
+          server => '.pgp.key.server',
+        }
+        EOS
+
+        apply_manifest(pp, :expect_failures => true) do |r|
+          expect(r.stderr).to match(/Invalid value \".pgp.key.server\"/)
+        end
+      end
+    end
+  end
+
+  describe 'source =>' do
+    context 'http://' do
+      it 'works' do
+        pp = <<-EOS
+        apt_key { 'puppetlabs':
+          id     => '#{PUPPETLABS_GPG_KEY_LONG_ID}',
+          ensure => 'present',
+          source => 'http://#{PUPPETLABS_APT_URL}/#{PUPPETLABS_GPG_KEY_FILE}',
+        }
+        EOS
+
+        apply_manifest(pp, :catch_failures => true)
+        apply_manifest(pp, :catch_failures => true)
+        shell(PUPPETLABS_KEY_CHECK_COMMAND)
+      end
+
+      it 'fails with a 404' do
+        pp = <<-EOS
+        apt_key { 'puppetlabs':
+          id     => '#{PUPPETLABS_GPG_KEY_LONG_ID}',
+          ensure => 'present',
+          source => 'http://#{PUPPETLABS_APT_URL}/herpderp.gpg',
+        }
+        EOS
+
+        apply_manifest(pp, :expect_failures => true) do |r|
+          expect(r.stderr).to match(/404 Not Found/)
+        end
+      end
+
+      it 'fails with a socket error' do
+        pp = <<-EOS
+        apt_key { 'puppetlabs':
+          id     => '#{PUPPETLABS_GPG_KEY_LONG_ID}',
+          ensure => 'present',
+          source => 'http://apt.puppetlabss.com/herpderp.gpg',
+        }
+        EOS
+
+        apply_manifest(pp, :expect_failures => true) do |r|
+          expect(r.stderr).to match(/could not resolve/)
+        end
+      end
+    end
+
+    context 'ftp://' do
+      before(:each) do
+        shell("apt-key del #{CENTOS_GPG_KEY_LONG_ID}",
+              :acceptable_exit_codes => [0,1,2])
+      end
+
+      it 'works' do
+        pp = <<-EOS
+        apt_key { 'CentOS 6':
+          id     => '#{CENTOS_GPG_KEY_LONG_ID}',
+          ensure => 'present',
+          source => 'ftp://#{CENTOS_REPO_URL}/#{CENTOS_GPG_KEY_FILE}',
+        }
+        EOS
+
+        apply_manifest(pp, :catch_failures => true)
+        apply_manifest(pp, :catch_failures => true)
+        shell(CENTOS_KEY_CHECK_COMMAND)
+      end
+
+      it 'fails with a 550' do
+        pp = <<-EOS
+        apt_key { 'CentOS 6':
+          id     => '#{SHOULD_NEVER_EXIST_ID}',
+          ensure => 'present',
+          source => 'ftp://#{CENTOS_REPO_URL}/herpderp.gpg',
+        }
+        EOS
+
+        apply_manifest(pp, :expect_failures => true) do |r|
+          expect(r.stderr).to match(/550 Failed to open/)
+        end
+      end
+
+      it 'fails with a socket error' do
+        pp = <<-EOS
+        apt_key { 'puppetlabs':
+          id     => '#{PUPPETLABS_GPG_KEY_LONG_ID}',
+          ensure => 'present',
+          source => 'ftp://apt.puppetlabss.com/herpderp.gpg',
+        }
+        EOS
+
+        apply_manifest(pp, :expect_failures => true) do |r|
+          expect(r.stderr).to match(/could not resolve/)
+        end
+      end
+    end
+
+    context 'https://' do
+      it 'works' do
+        pp = <<-EOS
+        apt_key { 'puppetlabs':
+          id     => '#{PUPPETLABS_GPG_KEY_LONG_ID}',
+          ensure => 'present',
+          source => 'https://#{PUPPETLABS_APT_URL}/#{PUPPETLABS_GPG_KEY_FILE}',
+        }
+        EOS
+
+        apply_manifest(pp, :catch_failures => true)
+        apply_manifest(pp, :catch_failures => true)
+        shell(PUPPETLABS_KEY_CHECK_COMMAND)
+      end
+
+      it 'fails with a 404' do
+        pp = <<-EOS
+        apt_key { 'puppetlabs':
+          id     => '#{SHOULD_NEVER_EXIST_ID}',
+          ensure => 'present',
+          source => 'https://#{PUPPETLABS_APT_URL}/herpderp.gpg',
+        }
+        EOS
+
+        apply_manifest(pp, :expect_failures => true) do |r|
+          expect(r.stderr).to match(/404 Not Found/)
+        end
+      end
+
+      it 'fails with a socket error' do
+        pp = <<-EOS
+        apt_key { 'puppetlabs':
+          id     => '#{SHOULD_NEVER_EXIST_ID}',
+          ensure => 'present',
+          source => 'https://apt.puppetlabss.com/herpderp.gpg',
+        }
+        EOS
+
+        apply_manifest(pp, :expect_failures => true) do |r|
+          expect(r.stderr).to match(/could not resolve/)
+        end
+      end
+    end
+
+    context '/path/that/exists' do
+      before(:each) do
+        shell("curl -o /tmp/puppetlabs-pubkey.gpg \
+              http://#{PUPPETLABS_APT_URL}/#{PUPPETLABS_GPG_KEY_FILE}")
+      end
+
+      after(:each) do
+        shell('rm /tmp/puppetlabs-pubkey.gpg')
+      end
+
+      it 'works' do
+        pp = <<-EOS
+        apt_key { 'puppetlabs':
+          id     => '4BD6EC30',
+          ensure => 'present',
+          source => '/tmp/puppetlabs-pubkey.gpg',
+        }
+        EOS
+
+        apply_manifest(pp, :catch_failures => true)
+        apply_manifest(pp, :catch_failures => true)
+        shell(PUPPETLABS_KEY_CHECK_COMMAND)
+      end
+    end
+
+    context '/path/that/does/not/exist' do
+      it 'fails' do
+        pp = <<-EOS
+        apt_key { 'puppetlabs':
+          id     => '#{PUPPETLABS_GPG_KEY_LONG_ID}',
+          ensure => 'present',
+          source => '/tmp/totally_bogus.file',
+        }
+        EOS
+
+        apply_manifest(pp, :expect_failures => true) do |r|
+          expect(r.stderr).to match(/does not exist/)
+        end
+      end
+    end
+
+    context '/path/that/exists/with/bogus/content' do
+      before(:each) do
+        shell('echo "here be dragons" > /tmp/fake-key.gpg')
+      end
+
+      after(:each) do
+        shell('rm /tmp/fake-key.gpg')
+      end
+      it 'fails' do
+        pp = <<-EOS
+        apt_key { 'puppetlabs':
+          id     => '#{PUPPETLABS_GPG_KEY_LONG_ID}',
+          ensure => 'present',
+          source => '/tmp/fake-key.gpg',
+        }
+        EOS
+
+        apply_manifest(pp, :expect_failures => true) do |r|
+          expect(r.stderr).to match(/no valid OpenPGP data found/)
+        end
+      end
+    end
+  end
+
+  describe 'options =>' do
+    context 'debug' do
+      it 'works' do
+        pp = <<-EOS
+        apt_key { 'puppetlabs':
+          id      => '#{PUPPETLABS_GPG_KEY_LONG_ID}',
+          ensure  => 'present',
+          options => 'debug',
+        }
+        EOS
+
+        apply_manifest(pp, :catch_failures => true)
+        apply_manifest(pp, :catch_failures => true)
+        shell(PUPPETLABS_KEY_CHECK_COMMAND)
+      end
+
+      it 'fails on invalid options' do
+        pp = <<-EOS
+        apt_key { 'puppetlabs':
+          id      => '#{PUPPETLABS_GPG_KEY_LONG_ID}',
+          ensure  => 'present',
+          options => 'this is totally bonkers',
+        }
+        EOS
+
+        shell("apt-key del #{PUPPETLABS_GPG_KEY_FINGERPRINT}", :acceptable_exit_codes => [0,1,2])
+        apply_manifest(pp, :expect_failures => true) do |r|
+          expect(r.stderr).to match(/--keyserver-options this is totally/)
+        end
+      end
+    end
+  end
+
+  describe 'fingerprint validation against source/content' do
+    context 'fingerprint in id matches fingerprint from remote key' do
+      it 'works' do
+        pp = <<-EOS
+        apt_key { 'puppetlabs':
+          id      => '#{PUPPETLABS_GPG_KEY_FINGERPRINT}',
+          ensure  => 'present',
+          source  => 'https://#{PUPPETLABS_APT_URL}/#{PUPPETLABS_GPG_KEY_FILE}',
+        }
+        EOS
+
+        apply_manifest(pp, :catch_failures => true)
+        apply_manifest(pp, :catch_failures => true)
+      end
+    end
+
+    context 'fingerprint in id does NOT match fingerprint from remote key' do
+      it 'works' do
+        pp = <<-EOS
+        apt_key { 'puppetlabs':
+          id      => '47B320EB4C7C375AA9DAE1A01054B7A24BD6E666',
+          ensure  => 'present',
+          source  => 'https://#{PUPPETLABS_APT_URL}/#{PUPPETLABS_GPG_KEY_FILE}',
+        }
+        EOS
+
+        apply_manifest(pp, :expect_failures => true) do |r|
+          expect(r.stderr).to match(/do not match/)
+        end
+      end
+    end
+  end
+
+end
Index: src/puppetcode/environments/test/modules/apt/spec/acceptance/apt_spec.rb
===================================================================
--- src/puppetcode/environments/test/modules/apt/spec/acceptance/apt_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/spec/acceptance/apt_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,60 @@
+require 'spec_helper_acceptance'
+
+describe 'apt class' do
+
+  context 'reset' do
+    it 'fixes the sources.list' do
+      shell('cp /etc/apt/sources.list /tmp')
+    end
+  end
+
+  context 'all the things' do
+    it 'should work with no errors' do
+      pp = <<-EOS
+      if $::lsbdistcodename == 'lucid' {
+        $sources = undef
+      } else {
+        $sources = {
+          'puppetlabs' => {
+            'ensure'   => present,
+            'location' => 'http://apt.puppetlabs.com',
+            'repos'    => 'main',
+            'key'      => {
+              'id'     => '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30',
+              'server' => 'pgp.mit.edu',
+            },
+          },
+        }
+      }
+      class { 'apt':
+        update => {
+          'frequency' => 'always',
+          'timeout'   => '400',
+          'tries'     => '3',
+        },
+        purge => {
+          'sources.list'   => true,
+          'sources.list.d' => true,
+          'preferences'    => true,
+          'preferences.d'  => true,
+        },
+        sources => $sources,
+      }
+      EOS
+
+      apply_manifest(pp, :catch_failures => true)
+      apply_manifest(pp, :catch_failures => true)
+    end
+    it 'should still work' do
+      shell('apt-get update')
+      shell('apt-get -y --force-yes upgrade')
+    end
+  end
+
+  context 'reset' do
+    it 'fixes the sources.list' do
+      shell('cp /tmp/sources.list /etc/apt')
+    end
+  end
+
+end
Index: src/puppetcode/environments/test/modules/apt/spec/acceptance/class_spec.rb
===================================================================
--- src/puppetcode/environments/test/modules/apt/spec/acceptance/class_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/spec/acceptance/class_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,17 @@
+require 'spec_helper_acceptance'
+
+describe 'apt class' do
+
+  context 'default parameters' do
+    # Using puppet_apply as a helper
+    it 'should work with no errors' do
+      pp = <<-EOS
+      class { 'apt': }
+      EOS
+
+      # Run it twice and test for idempotency
+      apply_manifest(pp, :catch_failures => true)
+      apply_manifest(pp, :catch_failures => true)
+    end
+  end
+end
Index: src/puppetcode/environments/test/modules/apt/spec/acceptance/nodesets/centos-59-x64.yml
===================================================================
--- src/puppetcode/environments/test/modules/apt/spec/acceptance/nodesets/centos-59-x64.yml	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/spec/acceptance/nodesets/centos-59-x64.yml	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,10 @@
+HOSTS:
+  centos-59-x64:
+    roles:
+      - master
+    platform: el-5-x86_64
+    box : centos-59-x64-vbox4210-nocm
+    box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-59-x64-vbox4210-nocm.box
+    hypervisor : vagrant
+CONFIG:
+  type: git
Index: src/puppetcode/environments/test/modules/apt/spec/acceptance/nodesets/centos-64-x64-pe.yml
===================================================================
--- src/puppetcode/environments/test/modules/apt/spec/acceptance/nodesets/centos-64-x64-pe.yml	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/spec/acceptance/nodesets/centos-64-x64-pe.yml	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,12 @@
+HOSTS:
+  centos-64-x64:
+    roles:
+      - master
+      - database
+      - dashboard
+    platform: el-6-x86_64
+    box : centos-64-x64-vbox4210-nocm
+    box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box
+    hypervisor : vagrant
+CONFIG:
+  type: pe
Index: src/puppetcode/environments/test/modules/apt/spec/acceptance/nodesets/centos-65-x64.yml
===================================================================
--- src/puppetcode/environments/test/modules/apt/spec/acceptance/nodesets/centos-65-x64.yml	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/spec/acceptance/nodesets/centos-65-x64.yml	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,10 @@
+HOSTS:
+  centos-65-x64:
+    roles:
+      - master
+    platform: el-6-x86_64
+    box : centos-65-x64-vbox436-nocm
+    box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-65-x64-virtualbox-nocm.box
+    hypervisor : vagrant
+CONFIG:
+  type: foss
Index: src/puppetcode/environments/test/modules/apt/spec/acceptance/nodesets/debian-70rc1-x64.yml
===================================================================
--- src/puppetcode/environments/test/modules/apt/spec/acceptance/nodesets/debian-70rc1-x64.yml	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/spec/acceptance/nodesets/debian-70rc1-x64.yml	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,10 @@
+HOSTS:
+  debian-70rc1-x64:
+    roles:
+      - master
+    platform: debian-70rc1-x64
+    box : debian-70rc1-x64-vbox4210-nocm
+    box_url : http://puppet-vagrant-boxes.puppetlabs.com/debian-70rc1-x64-vbox4210-nocm.box
+    hypervisor : vagrant
+CONFIG:
+  type: foss
Index: src/puppetcode/environments/test/modules/apt/spec/acceptance/nodesets/debian-73-x64.yml
===================================================================
--- src/puppetcode/environments/test/modules/apt/spec/acceptance/nodesets/debian-73-x64.yml	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/spec/acceptance/nodesets/debian-73-x64.yml	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,11 @@
+HOSTS:
+  debian-73-x64:
+    roles:
+      - master
+    platform: debian-7-amd64
+    box : debian-73-x64-virtualbox-nocm
+    box_url : http://puppet-vagrant-boxes.puppetlabs.com/debian-73-x64-virtualbox-nocm.box
+    hypervisor : vagrant
+CONFIG:
+  log_level: debug
+  type: git
Index: src/puppetcode/environments/test/modules/apt/spec/acceptance/nodesets/default.yml
===================================================================
--- src/puppetcode/environments/test/modules/apt/spec/acceptance/nodesets/default.yml	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/spec/acceptance/nodesets/default.yml	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,11 @@
+HOSTS:
+  ubuntu-server-12042-x64:
+    roles:
+      - master
+    platform: ubuntu-server-12.04-amd64
+    box : ubuntu-server-12042-x64-vbox4210-nocm
+    box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box
+    hypervisor : vagrant
+CONFIG:
+  type: foss
+  vagrant_ssh_port_random: true
Index: src/puppetcode/environments/test/modules/apt/spec/acceptance/nodesets/ubuntu-server-10044-x64.yml
===================================================================
--- src/puppetcode/environments/test/modules/apt/spec/acceptance/nodesets/ubuntu-server-10044-x64.yml	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/spec/acceptance/nodesets/ubuntu-server-10044-x64.yml	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,10 @@
+HOSTS:
+  ubuntu-server-10044-x64:
+    roles:
+      - master
+    platform: ubuntu-10.04-amd64
+    box : ubuntu-server-10044-x64-vbox4210-nocm
+    box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-10044-x64-vbox4210-nocm.box
+    hypervisor : vagrant
+CONFIG:
+  type: foss
Index: src/puppetcode/environments/test/modules/apt/spec/acceptance/nodesets/ubuntu-server-12042-x64.yml
===================================================================
--- src/puppetcode/environments/test/modules/apt/spec/acceptance/nodesets/ubuntu-server-12042-x64.yml	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/spec/acceptance/nodesets/ubuntu-server-12042-x64.yml	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,10 @@
+HOSTS:
+  ubuntu-server-12042-x64:
+    roles:
+      - master
+    platform: ubuntu-12.04-amd64
+    box : ubuntu-server-12042-x64-vbox4210-nocm
+    box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box
+    hypervisor : vagrant
+CONFIG:
+  type: foss
Index: src/puppetcode/environments/test/modules/apt/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml
===================================================================
--- src/puppetcode/environments/test/modules/apt/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,11 @@
+HOSTS:
+  ubuntu-server-1404-x64:
+    roles:
+      - master
+    platform: ubuntu-14.04-amd64
+    box : puppetlabs/ubuntu-14.04-64-nocm
+    box_url : https://vagrantcloud.com/puppetlabs/ubuntu-14.04-64-nocm
+    hypervisor : vagrant
+CONFIG:
+  log_level   : debug
+  type: git
Index: src/puppetcode/environments/test/modules/apt/spec/classes/apt_backports_spec.rb
===================================================================
--- src/puppetcode/environments/test/modules/apt/spec/classes/apt_backports_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/spec/classes/apt_backports_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,268 @@
+#!/usr/bin/env rspec
+require 'spec_helper'
+
+describe 'apt::backports', :type => :class do
+  let (:pre_condition) { "class{ '::apt': }" }
+  describe 'debian/ubuntu tests' do
+    context 'defaults on deb' do
+      let(:facts) do
+        {
+          :lsbdistid       => 'Debian',
+          :osfamily        => 'Debian',
+          :lsbdistcodename => 'wheezy',
+          :puppetversion   => Puppet.version,
+        }
+      end
+      it { is_expected.to contain_apt__source('backports').with({
+        :location => 'http://httpredir.debian.org/debian',
+        :key      => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
+        :repos    => 'main contrib non-free',
+        :release  => 'wheezy-backports',
+        :pin      => { 'priority' => 200, 'release' => 'wheezy-backports' },
+      })
+      }
+    end
+    context 'defaults on squeeze' do
+      let(:facts) do
+        {
+          :lsbdistid       => 'Debian',
+          :osfamily        => 'Debian',
+          :lsbdistcodename => 'squeeze',
+          :puppetversion   => Puppet.version,
+        }
+      end
+      it { is_expected.to contain_apt__source('backports').with({
+        :location => 'http://httpredir.debian.org/debian-backports',
+        :key      => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
+        :repos    => 'main contrib non-free',
+        :release  => 'squeeze-backports',
+        :pin      => { 'priority' => 200, 'release' => 'squeeze-backports' },
+      })
+      }
+    end
+    context 'defaults on ubuntu' do
+      let(:facts) do
+        {
+          :lsbdistid       => 'Ubuntu',
+          :osfamily        => 'Debian',
+          :lsbdistcodename => 'trusty',
+          :puppetversion   => Puppet.version,
+        }
+      end
+      it { is_expected.to contain_apt__source('backports').with({
+        :location => 'http://archive.ubuntu.com/ubuntu',
+        :key      => '630239CC130E1A7FD81A27B140976EAF437D05B5',
+        :repos    => 'main universe multiverse restricted',
+        :release  => 'trusty-backports',
+        :pin      => { 'priority' => 200, 'release' => 'trusty-backports' },
+      })
+      }
+    end
+    context 'set everything' do
+      let(:facts) do
+        {
+          :lsbdistid       => 'Ubuntu',
+          :osfamily        => 'Debian',
+          :lsbdistcodename => 'trusty',
+          :puppetversion   => Puppet.version,
+        }
+      end
+      let(:params) do
+        {
+          :location => 'http://archive.ubuntu.com/ubuntu-test',
+          :release  => 'vivid',
+          :repos    => 'main',
+          :key      => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
+          :pin      => '90',
+        }
+      end
+      it { is_expected.to contain_apt__source('backports').with({
+        :location => 'http://archive.ubuntu.com/ubuntu-test',
+        :key      => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
+        :repos    => 'main',
+        :release  => 'vivid',
+        :pin      => { 'priority' => 90, 'release' => 'vivid' },
+      })
+      }
+    end
+    context 'set things with hashes' do
+      let(:facts) do
+        {
+          :lsbdistid       => 'Ubuntu',
+          :osfamily        => 'Debian',
+          :lsbdistcodename => 'trusty',
+          :puppetversion   => Puppet.version,
+        }
+      end
+      let(:params) do
+        {
+          :key => {
+            'id' => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
+          },
+          :pin => {
+            'priority' => '90',
+          },
+        }
+      end
+      it { is_expected.to contain_apt__source('backports').with({
+        :key      => { 'id' => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553' },
+        :pin      => { 'priority' => '90' },
+      })
+      }
+    end
+  end
+  describe 'mint tests' do
+    let(:facts) do
+      {
+        :lsbdistid       => 'linuxmint',
+        :osfamily        => 'Debian',
+        :lsbdistcodename => 'qiana',
+        :puppetversion   => Puppet.version,
+      }
+    end
+    context 'sets all the needed things' do
+      let(:params) do
+        {
+          :location => 'http://archive.ubuntu.com/ubuntu',
+          :release  => 'trusty-backports',
+          :repos    => 'main universe multiverse restricted',
+          :key      => '630239CC130E1A7FD81A27B140976EAF437D05B5',
+        }
+      end
+      it { is_expected.to contain_apt__source('backports').with({
+        :location => 'http://archive.ubuntu.com/ubuntu',
+        :key      => '630239CC130E1A7FD81A27B140976EAF437D05B5',
+        :repos    => 'main universe multiverse restricted',
+        :release  => 'trusty-backports',
+        :pin      => { 'priority' => 200, 'release' => 'trusty-backports' },
+      })
+      }
+    end
+    context 'missing location' do
+      let(:params) do
+        {
+          :release  => 'trusty-backports',
+          :repos    => 'main universe multiverse restricted',
+          :key      => '630239CC130E1A7FD81A27B140976EAF437D05B5',
+        }
+      end
+      it do
+        expect {
+          subject.call
+        }.to raise_error(Puppet::Error, /If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key/)
+      end
+    end
+    context 'missing release' do
+      let(:params) do
+        {
+          :location => 'http://archive.ubuntu.com/ubuntu',
+          :repos    => 'main universe multiverse restricted',
+          :key      => '630239CC130E1A7FD81A27B140976EAF437D05B5',
+        }
+      end
+      it do
+        expect {
+          subject.call
+        }.to raise_error(Puppet::Error, /If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key/)
+      end
+    end
+    context 'missing repos' do
+      let(:params) do
+        {
+          :location => 'http://archive.ubuntu.com/ubuntu',
+          :release  => 'trusty-backports',
+          :key      => '630239CC130E1A7FD81A27B140976EAF437D05B5',
+        }
+      end
+      it do
+        expect {
+          subject.call
+        }.to raise_error(Puppet::Error, /If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key/)
+      end
+    end
+    context 'missing key' do
+      let(:params) do
+        {
+          :location => 'http://archive.ubuntu.com/ubuntu',
+          :release  => 'trusty-backports',
+          :repos    => 'main universe multiverse restricted',
+        }
+      end
+      it do
+        expect {
+          subject.call
+        }.to raise_error(Puppet::Error, /If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key/)
+      end
+    end
+  end
+  describe 'validation' do
+    let(:facts) do
+      {
+        :lsbdistid       => 'Ubuntu',
+        :osfamily        => 'Debian',
+        :lsbdistcodename => 'trusty',
+        :puppetversion   => Puppet.version,
+      }
+    end
+    context 'invalid location' do
+      let(:params) do
+        {
+          :location => true
+        }
+      end
+      it do
+        expect {
+          subject.call
+        }.to raise_error(Puppet::Error, /is not a string/)
+      end
+    end
+    context 'invalid release' do
+      let(:params) do
+        {
+          :release => true
+        }
+      end
+      it do
+        expect {
+          subject.call
+        }.to raise_error(Puppet::Error, /is not a string/)
+      end
+    end
+    context 'invalid repos' do
+      let(:params) do
+        {
+          :repos => true
+        }
+      end
+      it do
+        expect {
+          subject.call
+        }.to raise_error(Puppet::Error, /is not a string/)
+      end
+    end
+    context 'invalid key' do
+      let(:params) do
+        {
+          :key => true
+        }
+      end
+      it do
+        expect {
+          subject.call
+        }.to raise_error(Puppet::Error, /is not a string/)
+      end
+    end
+    context 'invalid pin' do
+      let(:params) do
+        {
+          :pin => true
+        }
+      end
+      it do
+        expect {
+          subject.call
+        }.to raise_error(Puppet::Error, /pin must be either a string, number or hash/)
+      end
+    end
+  end
+end
Index: src/puppetcode/environments/test/modules/apt/spec/classes/apt_spec.rb
===================================================================
--- src/puppetcode/environments/test/modules/apt/spec/classes/apt_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/spec/classes/apt_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,307 @@
+require 'spec_helper'
+describe 'apt' do
+  let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :puppetversion   => Puppet.version} }
+
+  context 'defaults' do
+    it { is_expected.to contain_file('sources.list').that_notifies('Class[Apt::Update]').only_with({
+      :ensure  => 'file',
+      :path    => '/etc/apt/sources.list',
+      :owner   => 'root',
+      :group   => 'root',
+      :mode    => '0644',
+      :notify  => 'Class[Apt::Update]',
+    })}
+
+    it { is_expected.to contain_file('sources.list.d').that_notifies('Class[Apt::Update]').only_with({
+      :ensure  => 'directory',
+      :path    => '/etc/apt/sources.list.d',
+      :owner   => 'root',
+      :group   => 'root',
+      :mode    => '0644',
+      :purge   => false,
+      :recurse => false,
+      :notify  => 'Class[Apt::Update]',
+    })}
+
+    it { is_expected.to contain_file('preferences').that_notifies('Class[Apt::Update]').only_with({
+      :ensure  => 'file',
+      :path    => '/etc/apt/preferences',
+      :owner   => 'root',
+      :group   => 'root',
+      :mode    => '0644',
+      :notify  => 'Class[Apt::Update]',
+    })}
+
+    it { is_expected.to contain_file('preferences.d').that_notifies('Class[Apt::Update]').only_with({
+      :ensure  => 'directory',
+      :path    => '/etc/apt/preferences.d',
+      :owner   => 'root',
+      :group   => 'root',
+      :mode    => '0644',
+      :purge   => false,
+      :recurse => false,
+      :notify  => 'Class[Apt::Update]',
+    })}
+
+    it 'should lay down /etc/apt/apt.conf.d/15update-stamp' do
+      is_expected.to contain_file('/etc/apt/apt.conf.d/15update-stamp').with({
+        :group => 'root',
+        :mode  => '0644',
+        :owner => 'root',
+      }).with_content(/APT::Update::Post-Invoke-Success \{"touch \/var\/lib\/apt\/periodic\/update-success-stamp 2>\/dev\/null \|\| true";\};/)
+    end
+
+    it { is_expected.to contain_exec('apt_update').with({
+      :refreshonly => 'true',
+    })}
+
+    it { is_expected.not_to contain_apt__setting('conf-proxy') }
+  end
+
+  describe 'proxy=' do
+    context 'host=localhost' do
+      let(:params) { { :proxy => { 'host' => 'localhost'} } }
+      it { is_expected.to contain_apt__setting('conf-proxy').with({
+        :priority => '01',
+      }).with_content(
+        /Acquire::http::proxy "http:\/\/localhost:8080\/";/
+      ).without_content(
+        /Acquire::https::proxy/
+      )}
+    end
+
+    context 'host=localhost and port=8180' do
+      let(:params) { { :proxy => { 'host' => 'localhost', 'port' => 8180} } }
+      it { is_expected.to contain_apt__setting('conf-proxy').with({
+        :priority => '01',
+      }).with_content(
+        /Acquire::http::proxy "http:\/\/localhost:8180\/";/
+      ).without_content(
+        /Acquire::https::proxy/
+      )}
+    end
+
+    context 'host=localhost and https=true' do
+      let(:params) { { :proxy => { 'host' => 'localhost', 'https' => true} } }
+      it { is_expected.to contain_apt__setting('conf-proxy').with({
+        :priority => '01',
+      }).with_content(
+        /Acquire::http::proxy "http:\/\/localhost:8080\/";/
+      ).with_content(
+        /Acquire::https::proxy "https:\/\/localhost:8080\/";/
+      )}
+    end
+
+    context 'ensure=absent' do
+      let(:params) { { :proxy => { 'ensure' => 'absent'} } }
+      it { is_expected.to contain_apt__setting('conf-proxy').with({
+        :ensure   => 'absent',
+        :priority => '01',
+      })}
+    end
+  end
+  context 'lots of non-defaults' do
+    let :params do
+      {
+        :update => { 'frequency' => 'always', 'timeout' => 1, 'tries' => 3 },
+        :purge  => { 'sources.list' => false, 'sources.list.d' => false,
+                     'preferences' => false, 'preferences.d' => false, },
+      }
+    end
+
+    it { is_expected.to contain_file('sources.list').with({
+      :content => nil,
+    })}
+
+    it { is_expected.to contain_file('sources.list.d').with({
+      :purge   => false,
+      :recurse => false,
+    })}
+
+    it { is_expected.to contain_file('preferences').with({
+      :ensure => 'file',
+    })}
+
+    it { is_expected.to contain_file('preferences.d').with({
+      :purge   => false,
+      :recurse => false,
+    })}
+
+    it { is_expected.to contain_exec('apt_update').with({
+      :refreshonly => false,
+      :timeout     => 1,
+      :tries       => 3,
+    })}
+
+  end
+
+  context 'with sources defined on valid osfamily' do
+    let :facts do
+      { :osfamily        => 'Debian',
+        :lsbdistcodename => 'precise',
+        :lsbdistid       => 'Debian',
+        :puppetversion   => Puppet.version,
+      }
+    end
+    let(:params) { { :sources => {
+      'debian_unstable' => {
+        'location'          => 'http://debian.mirror.iweb.ca/debian/',
+        'release'           => 'unstable',
+        'repos'             => 'main contrib non-free',
+        'key'               => { 'id' => '150C8614919D8446E01E83AF9AA38DCD55BE302B', 'server' => 'subkeys.pgp.net' },
+        'pin'               => '-10',
+        'include'           => {'src' => true,},
+      },
+      'puppetlabs' => {
+        'location'   => 'http://apt.puppetlabs.com',
+        'repos'      => 'main',
+        'key'        => { 'id' => '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30', 'server' => 'pgp.mit.edu' },
+      }
+    } } }
+
+    it {
+      is_expected.to contain_apt__setting('list-debian_unstable').with({
+        :ensure => 'present',
+      })
+    }
+
+    it { is_expected.to contain_file('/etc/apt/sources.list.d/debian_unstable.list').with_content(/^deb http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }
+    it { is_expected.to contain_file('/etc/apt/sources.list.d/debian_unstable.list').with_content(/^deb-src http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }
+
+    it {
+      is_expected.to contain_apt__setting('list-puppetlabs').with({
+        :ensure => 'present',
+      })
+    }
+
+    it { is_expected.to contain_file('/etc/apt/sources.list.d/puppetlabs.list').with_content(/^deb http:\/\/apt.puppetlabs.com precise main$/) }
+  end
+
+  context 'with keys defined on valid osfamily' do
+    let :facts do
+      { :osfamily        => 'Debian',
+        :lsbdistcodename => 'precise',
+        :lsbdistid       => 'Debian',
+        :puppetversion   => Puppet.version,
+      }
+    end
+    let(:params) { { :keys => {
+      '55BE302B' => {
+        'server' => 'subkeys.pgp.net',
+      },
+      '4BD6EC30' => {
+        'server' => 'pgp.mit.edu',
+      }
+    } } }
+
+    it { is_expected.to contain_apt__key('55BE302B').with({
+        :server => 'subkeys.pgp.net',
+    })}
+
+    it { is_expected.to contain_apt__key('4BD6EC30').with({
+        :server => 'pgp.mit.edu',
+    })}
+  end
+
+  context 'with ppas defined on valid osfamily' do
+    let :facts do
+      { :osfamily        => 'Debian',
+        :lsbdistcodename => 'precise',
+        :lsbdistid       => 'ubuntu',
+        :lsbdistrelease  => '12.04',
+        :puppetversion   => Puppet.version,
+      }
+    end
+    let(:params) { { :ppas => {
+      'ppa:drizzle-developers/ppa' => {},
+      'ppa:nginx/stable' => {},
+    } } }
+
+    it { is_expected.to contain_apt__ppa('ppa:drizzle-developers/ppa')}
+    it { is_expected.to contain_apt__ppa('ppa:nginx/stable')}
+  end
+
+  context 'with settings defined on valid osfamily' do
+    let :facts do
+      { :osfamily        => 'Debian',
+        :lsbdistcodename => 'precise',
+        :lsbdistid       => 'Debian',
+        :puppetversion   => Puppet.version,
+      }
+    end
+    let(:params) { { :settings => {
+      'conf-banana' => { 'content' => 'banana' },
+      'pref-banana' => { 'content' => 'banana' },
+    } } }
+
+    it { is_expected.to contain_apt__setting('conf-banana')}
+    it { is_expected.to contain_apt__setting('pref-banana')}
+  end
+
+  context 'with pins defined on valid osfamily' do
+    let :facts do
+      { :osfamily        => 'Debian',
+        :lsbdistcodename => 'precise',
+        :lsbdistid       => 'Debian',
+        :puppetversion   => Puppet.version,
+      }
+    end
+    let(:params) { { :pins => {
+      'stable' => { 'priority' => 600, 'order' => 50 },
+      'testing' =>  { 'priority' => 700, 'order' => 100 },
+    } } }
+
+    it { is_expected.to contain_apt__pin('stable') }
+    it { is_expected.to contain_apt__pin('testing') }
+  end
+
+  describe 'failing tests' do
+    context "purge['sources.list']=>'banana'" do
+      let(:params) { { :purge => { 'sources.list' => 'banana' }, } }
+      it do
+        expect {
+          subject.call
+        }.to raise_error(Puppet::Error)
+      end
+    end
+
+    context "purge['sources.list.d']=>'banana'" do
+      let(:params) { { :purge => { 'sources.list.d' => 'banana' }, } }
+      it do
+        expect {
+          subject.call
+        }.to raise_error(Puppet::Error)
+      end
+    end
+
+    context "purge['preferences']=>'banana'" do
+      let(:params) { { :purge => { 'preferences' => 'banana' }, } }
+      it do
+        expect {
+          subject.call
+        }.to raise_error(Puppet::Error)
+      end
+    end
+
+    context "purge['preferences.d']=>'banana'" do
+      let(:params) { { :purge => { 'preferences.d' => 'banana' }, } }
+      it do
+        expect {
+          subject.call
+        }.to raise_error(Puppet::Error)
+      end
+    end
+
+    context 'with unsupported osfamily' do
+      let :facts do
+        { :osfamily => 'Darwin', :puppetversion   => Puppet.version,}
+      end
+
+      it do
+        expect {
+          subject.call
+        }.to raise_error(Puppet::Error, /This module only works on Debian or derivatives like Ubuntu/)
+      end
+    end
+  end
+end
Index: src/puppetcode/environments/test/modules/apt/spec/classes/apt_update_spec.rb
===================================================================
--- src/puppetcode/environments/test/modules/apt/spec/classes/apt_update_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/spec/classes/apt_update_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,75 @@
+#!/usr/bin/env rspec
+require 'spec_helper'
+
+describe 'apt::update', :type => :class do
+  context "and apt::update['frequency']='always'" do
+    { 'a recent run' => Time.now.to_i, 'we are due for a run' => 1406660561,'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval|
+      context "and $::apt_update_last_success indicates #{desc}" do
+        let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval, :lsbdistcodename => 'wheezy', :puppetversion   => Puppet.version, } }
+        let (:pre_condition) { "class{'::apt': update => {'frequency' => 'always' },}" }
+        it 'should trigger an apt-get update run' do
+          #set the apt_update exec's refreshonly attribute to false
+          is_expected.to contain_exec('apt_update').with({'refreshonly' => false})
+        end
+      end
+    end
+    context 'when $::apt_update_last_success is nil' do
+      let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :puppetversion   => Puppet.version, } }
+      let (:pre_condition) { "class{ '::apt': update => {'frequency' => 'always' },}" }
+      it 'should trigger an apt-get update run' do
+        #set the apt_update exec\'s refreshonly attribute to false
+        is_expected.to contain_exec('apt_update').with({'refreshonly' => false})
+      end
+    end
+  end
+  context "and apt::update['frequency']='reluctantly'" do
+    {'a recent run' => Time.now.to_i, 'we are due for a run' => 1406660561,'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval|
+      context "and $::apt_update_last_success indicates #{desc}" do
+        let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval, :lsbdistcodename => 'wheezy', :puppetversion   => Puppet.version,} }
+        let (:pre_condition) { "class{ '::apt': update => {'frequency' => 'reluctantly' },}" }
+        it 'should not trigger an apt-get update run' do
+          #don't change the apt_update exec's refreshonly attribute. (it should be true)
+          is_expected.to contain_exec('apt_update').with({'refreshonly' => true})
+        end
+      end
+    end
+    context 'when $::apt_update_last_success is nil' do
+      let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :puppetversion   => Puppet.version, } }
+      let (:pre_condition) { "class{ '::apt': update => {'frequency' => 'reluctantly' },}" }
+      it 'should not trigger an apt-get update run' do
+        #don't change the apt_update exec's refreshonly attribute. (it should be true)
+        is_expected.to contain_exec('apt_update').with({'refreshonly' => true})
+      end
+    end
+  end
+  ['daily','weekly'].each do |update_frequency|
+    context "and apt::update['frequency'] has the value of #{update_frequency}" do
+      { 'we are due for a run' => 1406660561,'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval|
+        context "and $::apt_update_last_success indicates #{desc}" do
+          let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval, :lsbdistcodename => 'wheezy', :puppetversion   => Puppet.version, } }
+          let (:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" }
+          it 'should trigger an apt-get update run' do
+            #set the apt_update exec\'s refreshonly attribute to false
+            is_expected.to contain_exec('apt_update').with({'refreshonly' => false})
+          end
+        end
+      end
+      context 'when the $::apt_update_last_success fact has a recent value' do
+        let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :apt_update_last_success => Time.now.to_i, :puppetversion   => Puppet.version, } }
+        let (:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" }
+        it 'should not trigger an apt-get update run' do
+          #don't change the apt_update exec\'s refreshonly attribute. (it should be true)
+          is_expected.to contain_exec('apt_update').with({'refreshonly' => true})
+        end
+      end
+      context 'when $::apt_update_last_success is nil' do
+        let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :apt_update_last_success => nil, :puppetversion   => Puppet.version, } }
+        let (:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" }
+        it 'should trigger an apt-get update run' do
+          #set the apt_update exec\'s refreshonly attribute to false
+          is_expected.to contain_exec('apt_update').with({'refreshonly' => false})
+        end
+      end
+    end
+  end
+end
Index: src/puppetcode/environments/test/modules/apt/spec/classes/params_spec.rb
===================================================================
--- src/puppetcode/environments/test/modules/apt/spec/classes/params_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/spec/classes/params_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,25 @@
+require 'spec_helper'
+describe 'apt::params', :type => :class do
+  let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :puppetversion   => Puppet.version, } }
+  let (:title) { 'my_package' }
+
+  it { is_expected.to contain_apt__params }
+
+  # There are 4 resources in this class currently
+  # there should not be any more resources because it is a params class
+  # The resources are class[apt::params], class[main], class[settings], stage[main]
+  it "Should not contain any resources" do
+    expect(subject.call.resources.size).to eq(4)
+  end
+
+  describe "With lsb-release not installed" do
+    let(:facts) { { :osfamily => 'Debian', :puppetversion   => Puppet.version, } }
+    let (:title) { 'my_package' }
+
+    it do
+      expect {
+        subject.call
+      }.to raise_error(Puppet::Error, /Unable to determine lsbdistid, please install lsb-release first/)
+    end
+  end
+end
Index: src/puppetcode/environments/test/modules/apt/spec/defines/conf_spec.rb
===================================================================
--- src/puppetcode/environments/test/modules/apt/spec/defines/conf_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/spec/defines/conf_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,84 @@
+require 'spec_helper'
+describe 'apt::conf', :type => :define do
+  let :pre_condition do
+    'class { "apt": }'
+  end
+  let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :puppetversion   => Puppet.version, } }
+  let :title do
+    'norecommends'
+  end
+
+  describe "when creating an apt preference" do
+    let :default_params do
+      {
+        :priority => '00',
+        :content  => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n"
+      }
+    end
+    let :params do
+      default_params
+    end
+
+    let :filename do
+      "/etc/apt/apt.conf.d/00norecommends"
+    end
+
+    it { is_expected.to contain_file(filename).with({
+          'ensure'    => 'present',
+          'content'   => /Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;/,
+          'owner'     => 'root',
+          'group'     => 'root',
+          'mode'      => '0644',
+        })
+      }
+
+    context "with notify_update = true (default)" do
+      let :params do
+        default_params
+      end
+      it { is_expected.to contain_apt__setting("conf-#{title}").with_notify_update(true) }
+    end
+
+    context "with notify_update = false" do
+      let :params do
+        default_params.merge({
+          :notify_update => false
+        })
+      end
+      it { is_expected.to contain_apt__setting("conf-#{title}").with_notify_update(false) }
+    end
+  end
+
+  describe "when creating a preference without content" do
+    let :params do
+      {
+        :priority => '00',
+      }
+    end
+
+    it 'fails' do
+      expect { subject.call } .to raise_error(/pass in content/)
+    end
+  end
+
+  describe "when removing an apt preference" do
+    let :params do
+      {
+        :ensure   => 'absent',
+        :priority => '00',
+      }
+    end
+
+    let :filename do
+      "/etc/apt/apt.conf.d/00norecommends"
+    end
+
+    it { is_expected.to contain_file(filename).with({
+        'ensure'    => 'absent',
+        'owner'     => 'root',
+        'group'     => 'root',
+        'mode'      => '0644',
+      })
+    }
+  end
+end
Index: src/puppetcode/environments/test/modules/apt/spec/defines/key_compat_spec.rb
===================================================================
--- src/puppetcode/environments/test/modules/apt/spec/defines/key_compat_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/spec/defines/key_compat_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,316 @@
+require 'spec_helper'
+
+describe 'apt::key', :type => :define do
+  let(:facts) { { :lsbdistid => 'Debian' } }
+  GPG_KEY_ID = '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30'
+
+  let :title do
+    GPG_KEY_ID
+  end
+
+  describe 'normal operation' do
+    describe 'default options' do
+      it 'contains the apt_key' do
+        should contain_apt_key(title).with({
+          :id                => title,
+          :ensure            => 'present',
+          :source            => nil,
+          :server            => nil,
+          :content           => nil,
+          :keyserver_options => nil,
+        })
+      end
+      it 'contains the apt_key present anchor' do
+        should contain_anchor("apt_key #{title} present")
+      end
+    end
+
+    describe 'title and key =>' do
+      let :title do
+        'puppetlabs'
+      end
+
+      let :params do {
+        :key => GPG_KEY_ID,
+      } end
+
+      it 'contains the apt_key' do
+        should contain_apt_key(title).with({
+          :id                => GPG_KEY_ID,
+          :ensure            => 'present',
+          :source            => nil,
+          :server            => nil,
+          :content           => nil,
+          :keyserver_options => nil,
+        })
+      end
+      it 'contains the apt_key present anchor' do
+        should contain_anchor("apt_key #{GPG_KEY_ID} present")
+      end
+    end
+
+    describe 'ensure => absent' do
+      let :params do {
+        :ensure => 'absent',
+      } end
+
+      it 'contains the apt_key' do
+        should contain_apt_key(title).with({
+          :id                => title,
+          :ensure            => 'absent',
+          :source            => nil,
+          :server            => nil,
+          :content           => nil,
+          :keyserver_options => nil,
+        })
+      end
+      it 'contains the apt_key absent anchor' do
+        should contain_anchor("apt_key #{title} absent")
+      end
+    end
+
+    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({
+          :id      => title,
+          :ensure  => 'present',
+          :source  => 'http://apt.puppetlabs.com/pubkey.gpg',
+          :server  => 'pgp.mit.edu',
+          :content => params[:key_content],
+          :options => 'debug',
+        })
+      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 '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,
+          :server => 'hkp://pgp.mit.edu',
+        })
+      end
+    end
+    context "url with port number" do
+      let :params do
+        {
+          :key_server => 'hkp://pgp.mit.edu:80',
+        }
+      end
+      it 'contains the apt_key' do
+        should contain_apt_key(title).with({
+          :id        => title,
+          :server => 'hkp://pgp.mit.edu:80',
+        })
+      end
+    end
+  end
+
+  describe 'validation' do
+    context "domain begin with dash" do
+      let(:params) do{
+        :key_server => '-pgp.mit.edu',
+      } end
+      it 'fails' do
+        expect { subject.call } .to raise_error(/does not match/)
+      end
+    end
+
+    context "domain begin with dot" do
+      let(:params) do{
+        :key_server => '.pgp.mit.edu',
+      } end
+      it 'fails' do
+        expect { subject.call } .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.call } .to raise_error(/does not match/)
+      end
+    end
+    context "exceed character url" do
+      let :params do
+        {
+          :key_server => 'hkp://pgpiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.mit.edu'
+        }
+      end
+      it 'fails' do
+        expect { subject.call }.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.call }.to raise_error(/does not match/)
+      end
+    end
+    context "incorrect protocol for  url" do
+      let :params do
+        {
+          :key_server => 'abc://pgp.mit.edu:80'
+        }
+      end
+      it 'fails' do
+        expect { subject.call }.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.call }.to raise_error(/does not match/)
+      end
+    end
+    context "url ending with a dot" do
+      let :params do
+        {
+          :key_server => 'hkp://pgp.mit.edu.'
+        }
+      end
+      it 'fails' do
+        expect { subject.call }.to raise_error(/does not match/)
+      end
+    end
+    context "url begin with a dash" do
+      let(:params) do{
+        :key_server => "hkp://-pgp.mit.edu",
+      } end
+      it 'fails' do
+        expect { subject.call }.to raise_error(/does not match/)
+      end
+    end
+    context 'invalid key' do
+      let :title do
+        'Out of rum. Why? Why are we out of rum?'
+      end
+      it 'fails' do
+        expect { subject.call }.to raise_error(/does not match/)
+      end
+    end
+
+    context 'invalid source' do
+      let :params do {
+        :key_source => 'afp://puppetlabs.com/key.gpg',
+      } end
+      it 'fails' do
+        expect { subject.call }.to raise_error(/does not match/)
+      end
+    end
+
+    context 'invalid content' do
+      let :params do {
+        :key_content => [],
+      } end
+      it 'fails' do
+        expect { subject.call }.to raise_error(/is not a string/)
+      end
+    end
+
+    context 'invalid server' do
+      let :params do {
+        :key_server => 'two bottles of rum',
+      } end
+      it 'fails' do
+        expect { subject.call }.to raise_error(/does not match/)
+      end
+    end
+
+    context 'invalid keyserver_options' do
+      let :params do {
+        :key_options => {},
+      } end
+      it 'fails' do
+        expect { subject.call }.to raise_error(/is not a string/)
+      end
+    end
+
+    context 'invalid ensure' do
+      let :params do
+        {
+          :ensure => 'foo',
+        }
+      end
+      it 'fails' do
+        expect { subject.call }.to raise_error(/does not match/)
+      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}', }"
+        end
+
+        it 'contains two apt::key resources' do
+          should contain_apt__key('duplicate').with({
+            :key    => title,
+            :ensure => 'present',
+          })
+          should contain_apt__key(title).with({
+            :id     => 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
+
+      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.call }.to raise_error(/already ensured as absent/)
+        end
+      end
+    end
+  end
+end
Index: src/puppetcode/environments/test/modules/apt/spec/defines/key_spec.rb
===================================================================
--- src/puppetcode/environments/test/modules/apt/spec/defines/key_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/spec/defines/key_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,323 @@
+require 'spec_helper'
+
+describe 'apt::key' do
+  let :pre_condition do
+    'class { "apt": }'
+  end
+
+  let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :puppetversion   => Puppet.version, } }
+
+  GPG_KEY_ID = '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30'
+
+  let :title do
+    GPG_KEY_ID
+  end
+
+  describe 'normal operation' do
+    describe 'default options' do
+      it 'contains the apt_key' do
+        is_expected.to contain_apt_key(title).with({
+          :id      => title,
+          :ensure  => 'present',
+          :source  => nil,
+          :server  => 'keyserver.ubuntu.com',
+          :content => nil,
+          :options => nil,
+        })
+      end
+      it 'contains the apt_key present anchor' do
+        is_expected.to contain_anchor("apt_key #{title} present")
+      end
+    end
+
+    describe 'title and key =>' do
+      let :title do
+        'puppetlabs'
+      end
+
+      let :params do {
+        :id => GPG_KEY_ID,
+      } end
+
+      it 'contains the apt_key' do
+        is_expected.to contain_apt_key(title).with({
+          :id      => GPG_KEY_ID,
+          :ensure  => 'present',
+          :source  => nil,
+          :server  => 'keyserver.ubuntu.com',
+          :content => nil,
+          :options => nil,
+        })
+      end
+      it 'contains the apt_key present anchor' do
+        is_expected.to contain_anchor("apt_key #{GPG_KEY_ID} present")
+      end
+    end
+
+    describe 'ensure => absent' do
+      let :params do {
+        :ensure => 'absent',
+      } end
+
+      it 'contains the apt_key' do
+        is_expected.to contain_apt_key(title).with({
+          :id        => title,
+          :ensure    => 'absent',
+          :source    => nil,
+          :server    => 'keyserver.ubuntu.com',
+          :content   => nil,
+          :keyserver => nil,
+        })
+      end
+      it 'contains the apt_key absent anchor' do
+        is_expected.to contain_anchor("apt_key #{title} absent")
+      end
+    end
+
+    describe 'set a bunch of things!' do
+      let :params do {
+        :content => 'GPG key content',
+        :source  => 'http://apt.puppetlabs.com/pubkey.gpg',
+        :server  => 'pgp.mit.edu',
+        :options => 'debug',
+      } end
+
+      it 'contains the apt_key' do
+        is_expected.to contain_apt_key(title).with({
+          :id      => title,
+          :ensure  => 'present',
+          :source  => 'http://apt.puppetlabs.com/pubkey.gpg',
+          :server  => 'pgp.mit.edu',
+          :content => params[:content],
+          :options => 'debug',
+        })
+      end
+      it 'contains the apt_key present anchor' do
+        is_expected.to contain_anchor("apt_key #{title} present")
+      end
+    end
+
+    context "domain with dash" do
+      let(:params) do{
+        :server => 'p-gp.m-it.edu',
+      } end
+      it 'contains the apt_key' do
+        is_expected.to contain_apt_key(title).with({
+          :id        => title,
+          :server => 'p-gp.m-it.edu',
+        })
+      end
+    end
+
+    context "url" do
+      let :params do
+        {
+          :server => 'hkp://pgp.mit.edu',
+        }
+      end
+      it 'contains the apt_key' do
+        is_expected.to contain_apt_key(title).with({
+          :id        => title,
+          :server => 'hkp://pgp.mit.edu',
+        })
+      end
+    end
+    context "url with port number" do
+      let :params do
+        {
+          :server => 'hkp://pgp.mit.edu:80',
+        }
+      end
+      it 'contains the apt_key' do
+        is_expected.to contain_apt_key(title).with({
+          :id        => title,
+          :server => 'hkp://pgp.mit.edu:80',
+        })
+      end
+    end
+  end
+
+  describe 'validation' do
+    context "domain begin with dash" do
+      let(:params) do{
+        :server => '-pgp.mit.edu',
+      } end
+      it 'fails' do
+        expect { subject.call } .to raise_error(/does not match/)
+      end
+    end
+
+    context "domain begin with dot" do
+      let(:params) do{
+        :server => '.pgp.mit.edu',
+      } end
+      it 'fails' do
+        expect { subject.call } .to raise_error(/does not match/)
+      end
+    end
+
+    context "domain end with dot" do
+      let(:params) do{
+        :server => "pgp.mit.edu.",
+      } end
+      it 'fails' do
+        expect { subject.call } .to raise_error(/does not match/)
+      end
+    end
+    context "exceed character url" do
+      let :params do
+        {
+          :server => 'hkp://pgpiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.mit.edu'
+        }
+      end
+      it 'fails' do
+        expect { subject.call }.to raise_error(/does not match/)
+      end
+    end
+    context "incorrect port number url" do
+      let :params do
+        {
+          :server => 'hkp://pgp.mit.edu:8008080'
+        }
+      end
+      it 'fails' do
+        expect { subject.call }.to raise_error(/does not match/)
+      end
+    end
+    context "incorrect protocol for  url" do
+      let :params do
+        {
+          :server => 'abc://pgp.mit.edu:80'
+        }
+      end
+      it 'fails' do
+        expect { subject.call }.to raise_error(/does not match/)
+      end
+    end
+    context "missing port number url" do
+      let :params do
+        {
+          :server => 'hkp://pgp.mit.edu:'
+        }
+      end
+      it 'fails' do
+        expect { subject.call }.to raise_error(/does not match/)
+      end
+    end
+    context "url ending with a dot" do
+      let :params do
+        {
+          :server => 'hkp://pgp.mit.edu.'
+        }
+      end
+      it 'fails' do
+        expect { subject.call }.to raise_error(/does not match/)
+      end
+    end
+    context "url begin with a dash" do
+      let(:params) do{
+        :server => "hkp://-pgp.mit.edu",
+      } end
+      it 'fails' do
+        expect { subject.call }.to raise_error(/does not match/)
+      end
+    end
+    context 'invalid key' do
+      let :title do
+        'Out of rum. Why? Why are we out of rum?'
+      end
+      it 'fails' do
+        expect { subject.call }.to raise_error(/does not match/)
+      end
+    end
+
+    context 'invalid source' do
+      let :params do {
+        :source => 'afp://puppetlabs.com/key.gpg',
+      } end
+      it 'fails' do
+        expect { subject.call }.to raise_error(/does not match/)
+      end
+    end
+
+    context 'invalid content' do
+      let :params do {
+        :content => [],
+      } end
+      it 'fails' do
+        expect { subject.call }.to raise_error(/is not a string/)
+      end
+    end
+
+    context 'invalid server' do
+      let :params do {
+        :server => 'two bottles of rum',
+      } end
+      it 'fails' do
+        expect { subject.call }.to raise_error(/does not match/)
+      end
+    end
+
+    context 'invalid options' do
+      let :params do {
+        :options => {},
+      } end
+      it 'fails' do
+        expect { subject.call }.to raise_error(/is not a string/)
+      end
+    end
+
+    context 'invalid ensure' do
+      let :params do
+        {
+          :ensure => 'foo',
+        }
+      end
+      it 'fails' do
+        expect { subject.call }.to raise_error(/does not match/)
+      end
+    end
+
+    describe 'duplication' do
+      context 'two apt::key resources for same key, different titles' do
+        let :pre_condition do
+          "class { 'apt': }
+          apt::key { 'duplicate': id => '#{title}', }"
+        end
+
+        it 'contains two apt::key resources' do
+          is_expected.to contain_apt__key('duplicate').with({
+            :id     => title,
+            :ensure => 'present',
+          })
+          is_expected.to contain_apt__key(title).with({
+            :id     => title,
+            :ensure => 'present',
+          })
+        end
+
+        it 'contains only a single apt_key' do
+          is_expected.to contain_apt_key('duplicate').with({
+            :id      => title,
+            :ensure  => 'present',
+            :source  => nil,
+            :server  => 'keyserver.ubuntu.com',
+            :content => nil,
+            :options => nil,
+          })
+          is_expected.not_to contain_apt_key(title)
+        end
+      end
+
+      context 'two apt::key resources, different ensure' do
+        let :pre_condition do
+          "class { 'apt': }
+          apt::key { 'duplicate': id => '#{title}', ensure => 'absent', }"
+        end
+        it 'informs the user of the impossibility' do
+          expect { subject.call }.to raise_error(/already ensured as absent/)
+        end
+      end
+    end
+  end
+end
Index: src/puppetcode/environments/test/modules/apt/spec/defines/pin_spec.rb
===================================================================
--- src/puppetcode/environments/test/modules/apt/spec/defines/pin_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/spec/defines/pin_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,145 @@
+require 'spec_helper'
+describe 'apt::pin', :type => :define do
+  let :pre_condition do
+    'class { "apt": }'
+  end
+  let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :puppetversion   => Puppet.version, } }
+  let(:title) { 'my_pin' }
+
+  context 'defaults' do
+    it { is_expected.to contain_apt__setting("pref-my_pin").with_content(/Explanation: : my_pin\nPackage: \*\nPin: release a=my_pin\nPin-Priority: 0\n/)}
+    it { is_expected.to contain_apt__setting("pref-my_pin") }
+  end
+
+  context 'set version' do
+    let :params do
+      {
+        'packages' => 'vim',
+        'version'  => '1',
+      }
+    end
+    it { is_expected.to contain_apt__setting("pref-my_pin").with_content(/Explanation: : my_pin\nPackage: vim\nPin: version 1\nPin-Priority: 0\n/)}
+    it { is_expected.to contain_apt__setting("pref-my_pin") }
+  end
+
+  context 'set origin' do
+    let :params do
+      {
+        'packages' => 'vim',
+        'origin'   => 'test',
+      }
+    end
+    it { is_expected.to contain_apt__setting("pref-my_pin").with_content(/Explanation: : my_pin\nPackage: vim\nPin: origin test\nPin-Priority: 0\n/)}
+    it { is_expected.to contain_apt__setting("pref-my_pin") }
+  end
+
+  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_apt__setting("pref-my_pin").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_apt__setting("pref-my_pin").with({
+      'priority'     => 99,
+    })
+    }
+  end
+
+  context 'ensure absent' do
+    let :params do
+      {
+        'ensure' => 'absent'
+      }
+    end
+    it { is_expected.to contain_apt__setting("pref-my_pin").with({
+      'ensure' => 'absent',
+    })
+    }
+  end
+
+  context 'bad characters' do
+    let(:title) { 'such  bad && wow!' }
+    it { is_expected.to contain_apt__setting("pref-such__bad____wow_") }
+  end
+
+  describe 'validation' do
+    context 'invalid order' do
+      let :params do
+        {
+          'order' => 'foo',
+        }
+      end
+      it do
+        expect {
+          subject.call
+        }.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 {
+          subject.call
+        }.to raise_error(Puppet::Error, /parameter version cannot be used in general form/)
+      end
+    end
+
+    context 'packages == * and release and origin' do
+      let :params do
+        {
+          'origin'  => 'test',
+          'release' => 'foo',
+        }
+      end
+      it do
+        expect {
+          subject.call
+        }.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 {
+          subject.call
+        }.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 {
+          subject.call
+        }.to raise_error(Puppet::Error, /parameters release, origin, and version are mutually exclusive/)
+      end
+    end
+  end
+end
Index: src/puppetcode/environments/test/modules/apt/spec/defines/ppa_spec.rb
===================================================================
--- src/puppetcode/environments/test/modules/apt/spec/defines/ppa_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/spec/defines/ppa_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,378 @@
+require 'spec_helper'
+describe 'apt::ppa' do
+  let :pre_condition do
+    'class { "apt": }'
+  end
+
+  describe 'defaults' do
+    let :facts do
+      {
+        :lsbdistrelease  => '11.04',
+        :lsbdistcodename => 'natty',
+        :operatingsystem => 'Ubuntu',
+        :osfamily        => 'Debian',
+        :lsbdistid       => 'Ubuntu',
+        :puppetversion   => Puppet.version,
+      }
+    end
+
+    let(:title) { 'ppa:needs/such.substitution/wow+type' }
+    it { is_expected.to_not contain_package('python-software-properties') }
+    it { is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow+type').that_notifies('Class[Apt::Update]').with({
+      :environment => [],
+      :command     => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow+type',
+      :unless      => '/usr/bin/test -s /etc/apt/sources.list.d/needs-such_substitution-wow_type-natty.list',
+      :user        => 'root',
+      :logoutput   => 'on_failure',
+    })
+    }
+  end
+
+  describe 'Ubuntu 15.10 sources.list filename' do
+    let :facts do
+      {
+        :lsbdistrelease  => '15.10',
+        :lsbdistcodename => 'wily',
+        :operatingsystem => 'Ubuntu',
+        :osfamily        => 'Debian',
+        :lsbdistid       => 'Ubuntu',
+        :puppetversion   => Puppet.version,
+      }
+    end
+
+    let(:title) { 'ppa:user/foo' }
+    it { is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with({
+      :environment => [],
+      :command     => '/usr/bin/add-apt-repository -y ppa:user/foo',
+      :unless      => '/usr/bin/test -s /etc/apt/sources.list.d/user-ubuntu-foo-wily.list',
+      :user        => 'root',
+      :logoutput   => 'on_failure',
+    })
+    }
+  end
+
+  describe 'ppa depending on ppa, MODULES-1156' do
+    let :pre_condition do
+      'class { "apt": }'
+    end
+  end
+
+  describe 'package_name => software-properties-common' do
+    let :pre_condition do
+      'class { "apt": }'
+    end
+    let :params do
+      {
+        :package_name   => 'software-properties-common',
+        :package_manage => true,
+      }
+    end
+    let :facts do
+      {
+        :lsbdistrelease  => '11.04',
+        :lsbdistcodename => 'natty',
+        :operatingsystem => 'Ubuntu',
+        :osfamily        => 'Debian',
+        :lsbdistid       => 'Ubuntu',
+        :puppetversion   => Puppet.version,
+      }
+    end
+
+    let(:title) { 'ppa:needs/such.substitution/wow' }
+    it { is_expected.to contain_package('software-properties-common') }
+    it { is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow').that_notifies('Class[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 { 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
+
+  describe 'package_manage => true, multiple ppas, MODULES-2873' do
+    let :pre_condition do
+      'class { "apt": }
+       apt::ppa {"ppa:user/foo":
+         package_manage => true
+       }'
+    end
+    let :facts do
+      {
+        :lsbdistrelease  => '11.04',
+        :lsbdistcodename => 'natty',
+        :operatingsystem => 'Ubuntu',
+        :osfamily        => 'Debian',
+        :lsbdistid       => 'Ubuntu',
+        :puppetversion   => Puppet.version,
+      }
+    end
+    let :params do
+      {
+        :package_manage => true,
+      }
+    end
+
+    let(:title) { 'ppa:user/bar' }
+    it { is_expected.to contain_package('python-software-properties') }
+    it { is_expected.to contain_exec('add-apt-repository-ppa:user/bar').that_notifies('Class[Apt::Update]').with({
+      'environment' => [],
+      'command'     => '/usr/bin/add-apt-repository -y ppa:user/bar',
+      'unless'      => '/usr/bin/test -s /etc/apt/sources.list.d/user-bar-natty.list',
+      'user'        => 'root',
+      'logoutput'   => 'on_failure',
+    })
+    }
+
+    it { is_expected.to contain_file('/etc/apt/sources.list.d/user-bar-natty.list').that_requires('Exec[add-apt-repository-ppa:user/bar]').with({
+      'ensure' => 'file',
+    })
+    }
+  end
+
+  describe 'package_manage => false' do
+    let :pre_condition do
+      'class { "apt": }'
+    end
+    let :facts do
+      {
+        :lsbdistrelease  => '11.04',
+        :lsbdistcodename => 'natty',
+        :operatingsystem => 'Ubuntu',
+        :osfamily        => 'Debian',
+        :lsbdistid       => 'Ubuntu',
+        :puppetversion   => Puppet.version,
+      }
+    end
+    let :params do
+      {
+        :package_manage => false,
+      }
+    end
+
+    let(:title) { 'ppa:needs/such.substitution/wow' }
+    it { is_expected.to_not contain_package('python-software-properties') }
+    it { is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow').that_notifies('Class[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 { 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
+
+  describe 'apt included, no proxy' do
+    let :pre_condition do
+      'class { "apt": }
+      apt::ppa { "ppa:user/foo2": }
+      '
+    end
+    let :facts do
+      {
+        :lsbdistrelease  => '14.04',
+        :lsbdistcodename => 'trusty',
+        :operatingsystem => 'Ubuntu',
+        :lsbdistid       => 'Ubuntu',
+        :osfamily        => 'Debian',
+        :puppetversion   => Puppet.version,
+      }
+    end
+    let :params do
+      {
+        :options        => '',
+        :package_manage => true,
+        :require        => 'Apt::Ppa[ppa:user/foo2]',
+      }
+    end
+    let(:title) { 'ppa:user/foo' }
+    it { is_expected.to compile.with_all_deps }
+    it { is_expected.to contain_package('software-properties-common') }
+    it { is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with({
+      :environment => [],
+      :command     => '/usr/bin/add-apt-repository  ppa:user/foo',
+      :unless      => '/usr/bin/test -s /etc/apt/sources.list.d/user-foo-trusty.list',
+      :user        => 'root',
+      :logoutput   => 'on_failure',
+    })
+    }
+  end
+
+  describe 'apt included, proxy host' do
+    let :pre_condition do
+      'class { "apt":
+        proxy => { "host" => "localhost" },
+      }'
+    end
+    let :facts do
+      {
+        :lsbdistrelease  => '14.04',
+        :lsbdistcodename => 'trusty',
+        :operatingsystem => 'Ubuntu',
+        :lsbdistid       => 'Ubuntu',
+        :osfamily        => 'Debian',
+        :puppetversion   => Puppet.version,
+      }
+    end
+    let :params do
+      {
+        'options' => '',
+        'package_manage' => true,
+      }
+    end
+    let(:title) { 'ppa:user/foo' }
+    it { is_expected.to contain_package('software-properties-common') }
+    it { is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with({
+      :environment => ['http_proxy=http://localhost:8080'],
+      :command     => '/usr/bin/add-apt-repository  ppa:user/foo',
+      :unless      => '/usr/bin/test -s /etc/apt/sources.list.d/user-foo-trusty.list',
+      :user        => 'root',
+      :logoutput   => 'on_failure',
+    })
+    }
+  end
+
+  describe 'apt included, proxy host and port' do
+    let :pre_condition do
+      'class { "apt":
+        proxy => { "host" => "localhost", "port" => 8180 },
+      }'
+    end
+    let :facts do
+      {
+        :lsbdistrelease  => '14.04',
+        :lsbdistcodename => 'trusty',
+        :operatingsystem => 'Ubuntu',
+        :lsbdistid       => 'Ubuntu',
+        :osfamily        => 'Debian',
+        :puppetversion   => Puppet.version,
+      }
+    end
+    let :params do
+      {
+        :options => '',
+        :package_manage => true,
+      }
+    end
+    let(:title) { 'ppa:user/foo' }
+    it { is_expected.to contain_package('software-properties-common') }
+    it { is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with({
+      :environment => ['http_proxy=http://localhost:8180'],
+      :command     => '/usr/bin/add-apt-repository  ppa:user/foo',
+      :unless      => '/usr/bin/test -s /etc/apt/sources.list.d/user-foo-trusty.list',
+      :user        => 'root',
+      :logoutput   => 'on_failure',
+    })
+    }
+  end
+
+  describe 'apt included, proxy host and port and https' do
+    let :pre_condition do
+      'class { "apt":
+        proxy => { "host" => "localhost", "port" => 8180, "https" => true },
+      }'
+    end
+    let :facts do
+      {
+        :lsbdistrelease  => '14.04',
+        :lsbdistcodename => 'trusty',
+        :operatingsystem => 'Ubuntu',
+        :lsbdistid       => 'Ubuntu',
+        :osfamily        => 'Debian',
+        :puppetversion   => Puppet.version,
+      }
+    end
+    let :params do
+      {
+        :options => '',
+        :package_manage => true,
+      }
+    end
+    let(:title) { 'ppa:user/foo' }
+    it { is_expected.to contain_package('software-properties-common') }
+    it { is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with({
+      :environment => ['http_proxy=http://localhost:8180', 'https_proxy=https://localhost:8180'],
+      :command     => '/usr/bin/add-apt-repository  ppa:user/foo',
+      :unless      => '/usr/bin/test -s /etc/apt/sources.list.d/user-foo-trusty.list',
+      :user        => 'root',
+      :logoutput   => 'on_failure',
+    })
+    }
+  end
+
+  describe 'ensure absent' do
+    let :pre_condition do
+      'class { "apt": }'
+    end
+    let :facts do
+      {
+        :lsbdistrelease  => '14.04',
+        :lsbdistcodename => 'trusty',
+        :operatingsystem => 'Ubuntu',
+        :lsbdistid       => 'Ubuntu',
+        :osfamily        => 'Debian',
+        :puppetversion   => Puppet.version,
+      }
+    end
+    let(:title) { 'ppa:user/foo' }
+    let :params do
+      {
+        :ensure => 'absent'
+      }
+    end
+    it { is_expected.to contain_file('/etc/apt/sources.list.d/user-foo-trusty.list').that_notifies('Class[Apt::Update]').with({
+      :ensure => 'absent',
+    })
+    }
+  end
+
+  context 'validation' do
+    describe 'no release' do
+      let :facts do
+        {
+          :lsbdistrelease  => '14.04',
+          :operatingsystem => 'Ubuntu',
+          :lsbdistid       => 'Ubuntu',
+          :osfamily        => 'Debian',
+          :lsbdistcodeanme => nil,
+          :puppetversion   => Puppet.version,
+        }
+      end
+      let(:title) { 'ppa:user/foo' }
+      it do
+        expect {
+          subject.call
+        }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/)
+      end
+    end
+
+    describe 'not ubuntu' do
+      let :facts do
+        {
+          :lsbdistrelease  => '6.0.7',
+          :lsbdistcodename => 'wheezy',
+          :operatingsystem => 'Debian',
+          :lsbdistid       => 'debian',
+          :osfamily        => 'Debian',
+          :puppetversion   => Puppet.version,
+        }
+      end
+      let(:title) { 'ppa:user/foo' }
+      it do
+        expect {
+          subject.call
+        }.to raise_error(Puppet::Error, /not currently supported on Debian/)
+      end
+    end
+  end
+end
Index: src/puppetcode/environments/test/modules/apt/spec/defines/setting_spec.rb
===================================================================
--- src/puppetcode/environments/test/modules/apt/spec/defines/setting_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/spec/defines/setting_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,115 @@
+require 'spec_helper'
+
+describe 'apt::setting' do
+  let(:pre_condition) { 'class { "apt": }' }
+  let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :puppetversion   => Puppet.version, } }
+  let(:title) { 'conf-teddybear' }
+
+  let(:default_params) { { :content => 'di' } }
+
+  describe 'when using the defaults' do
+    context 'without source or content' do
+      it do
+        expect { subject.call }.to raise_error(Puppet::Error, /needs either of /)
+      end
+    end
+
+    context 'with title=conf-teddybear ' do
+      let(:params) { default_params }
+      it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Class[Apt::Update]') }
+    end
+
+    context 'with title=pref-teddybear' do
+      let(:title) { 'pref-teddybear' }
+      let(:params) { default_params }
+      it { is_expected.to contain_file('/etc/apt/preferences.d/teddybear.pref').that_notifies('Class[Apt::Update]') }
+    end
+
+    context 'with title=list-teddybear' do
+      let(:title) { 'list-teddybear' }
+      let(:params) { default_params }
+      it { is_expected.to contain_file('/etc/apt/sources.list.d/teddybear.list').that_notifies('Class[Apt::Update]') }
+    end
+
+    context 'with source' do
+      let(:params) { { :source => 'puppet:///la/die/dah' } }
+      it {
+        is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Class[Apt::Update]').with({
+        :ensure => 'file',
+        :owner  => 'root',
+        :group  => 'root',
+        :mode   => '0644',
+        :source => "#{params[:source]}",
+      })}
+    end
+
+    context 'with content' do
+      let(:params) { default_params }
+      it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Class[Apt::Update]').with({
+        :ensure  => 'file',
+        :owner   => 'root',
+        :group   => 'root',
+        :mode    => '0644',
+        :content => "#{params[:content]}",
+      })}
+    end
+  end
+
+  describe 'settings requiring settings, MODULES-769' do
+    let(:pre_condition) do
+      'class { "apt": }
+      apt::setting { "list-teddybear": content => "foo" }
+      '
+    end
+    let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :puppetversion   => Puppet.version, } }
+    let(:title) { 'conf-teddybear' }
+    let(:default_params) { { :content => 'di' } }
+
+    let(:params) { default_params.merge({ :require => 'Apt::Setting[list-teddybear]' }) }
+
+    it { is_expected.to compile.with_all_deps }
+  end
+
+  describe 'when trying to pull one over' do
+    context 'with source and content' do
+      let(:params) { default_params.merge({ :source => 'la' }) }
+      it do
+        expect { subject.call }.to raise_error(Puppet::Error, /cannot have both /)
+      end
+    end
+
+    context 'with title=ext-teddybear' do
+      let(:title) { 'ext-teddybear' }
+      let(:params) { default_params }
+      it do
+        expect { subject.call }.to raise_error(Puppet::Error, /must start with /)
+      end
+    end
+
+    context 'with ensure=banana' do
+      let(:params) { default_params.merge({ :ensure => 'banana' }) }
+      it do
+        expect { subject.call }.to raise_error(Puppet::Error, /"banana" does not /)
+      end
+    end
+
+    context 'with priority=1.2' do
+      let(:params) { default_params.merge({ :priority => 1.2 }) }
+      it do
+        expect { subject.call }.to raise_error(Puppet::Error, /be an integer /)
+      end
+    end
+  end
+
+  describe 'with priority=100' do
+    let(:params) { default_params.merge({ :priority => 100 }) }
+    it { is_expected.to contain_file('/etc/apt/apt.conf.d/100teddybear').that_notifies('Class[Apt::Update]') }
+  end
+
+  describe 'with ensure=absent' do
+    let(:params) { default_params.merge({ :ensure => 'absent' }) }
+    it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Class[Apt::Update]').with({
+      :ensure => 'absent',
+    })}
+  end
+end
Index: src/puppetcode/environments/test/modules/apt/spec/defines/source_compat_spec.rb
===================================================================
--- src/puppetcode/environments/test/modules/apt/spec/defines/source_compat_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/spec/defines/source_compat_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,158 @@
+require 'spec_helper'
+
+describe 'apt::source', :type => :define do
+  GPG_KEY_ID = '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30'
+
+  let :title do
+    'my_source'
+  end
+
+  context 'mostly defaults' do
+    let :facts do
+      {
+        :lsbdistid       => 'Debian',
+        :lsbdistcodename => 'wheezy',
+        :osfamily        => 'Debian',
+      }
+    end
+
+    let :params do
+      {
+        'include_deb' => false,
+        'include_src' => true,
+        'location'    => 'http://debian.mirror.iweb.ca/debian/',
+      }
+    end
+
+    it { is_expected.to contain_apt__setting('list-my_source').with_content(/# my_source\ndeb-src http:\/\/debian\.mirror\.iweb\.ca\/debian\/ wheezy main\n/)
+    }
+  end
+
+  context 'no defaults' do
+    let :facts do
+      {
+        :lsbdistid       => 'Debian',
+        :lsbdistcodename => 'wheezy',
+        :osfamily        => 'Debian'
+      }
+    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',
+        'trusted_source'    => true,
+      }
+    end
+
+    it { is_expected.to contain_apt__setting('list-my_source').with_content(/# foo\ndeb \[arch=x86_64 trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(/deb-src/)
+    }
+
+    it { is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with({
+      'ensure'   => 'present',
+      'priority' => '10',
+      'origin'   => 'debian.mirror.iweb.ca',
+    })
+    }
+
+    it { is_expected.to contain_exec("Required packages: 'vim' for my_source").that_comes_before('Apt::Setting[list-my_source]').with({
+      'command'     => '/usr/bin/apt-get -y install vim',
+      'logoutput'   => 'on_failure',
+      'refreshonly' => true,
+      'tries'       => '3',
+      'try_sleep'   => '1',
+    })
+    }
+
+    it { is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('Apt::Setting[list-my_source]').with({
+      'ensure' => 'present',
+      'id'  => GPG_KEY_ID,
+      'key_server' => 'pgp.mit.edu',
+      'key_content' => 'GPG key content',
+      'key_source' => 'http://apt.puppetlabs.com/pubkey.gpg',
+    })
+    }
+  end
+
+  context 'trusted_source true' do
+    let :facts do
+      {
+        :lsbdistid       => 'Debian',
+        :lsbdistcodename => 'wheezy',
+        :osfamily        => 'Debian'
+      }
+    end
+    let :params do
+      {
+        'include_src'    => false,
+        'location'       => 'http://debian.mirror.iweb.ca/debian/',
+        'trusted_source' => true,
+      }
+    end
+
+    it { is_expected.to contain_apt__setting('list-my_source').with_content(/# my_source\ndeb \[trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ wheezy main\n/) }
+  end
+
+  context 'architecture equals x86_64' do
+    let :facts do
+      {
+        :lsbdistid       => 'Debian',
+        :lsbdistcodename => 'wheezy',
+        :osfamily        => 'Debian'
+      }
+    end
+    let :params do
+      {
+        'location'     => 'http://debian.mirror.iweb.ca/debian/',
+        'architecture' => 'x86_64',
+      }
+    end
+
+    it { is_expected.to contain_apt__setting('list-my_source').with_content(/# my_source\ndeb \[arch=x86_64\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ wheezy main\n/)
+    }
+  end
+
+  context 'ensure => absent' do
+    let :facts do
+      {
+        :lsbdistid       => 'Debian',
+        :lsbdistcodename => 'wheezy',
+        :osfamily        => 'Debian'
+      }
+    end
+    let :params do
+      {
+        'ensure' => 'absent',
+      }
+    end
+
+    it { is_expected.to contain_apt__setting('list-my_source').with({
+      'ensure' => 'absent'
+    })
+    }
+  end
+
+  describe 'validation' do
+    context 'no release' do
+      let :facts do
+        {
+          :lsbdistid       => 'Debian',
+          :osfamily        => 'Debian'
+        }
+      end
+
+      it do
+        expect { subject.call }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/)
+      end
+    end
+  end
+end
Index: src/puppetcode/environments/test/modules/apt/spec/defines/source_spec.rb
===================================================================
--- src/puppetcode/environments/test/modules/apt/spec/defines/source_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/spec/defines/source_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,391 @@
+require 'spec_helper'
+
+describe 'apt::source' do
+  GPG_KEY_ID = '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30'
+
+  let :pre_condition do
+    'class { "apt": }'
+  end
+
+  let :title do
+    'my_source'
+  end
+
+  context 'defaults' do
+    context 'without location' do
+      let :facts do
+        {
+          :lsbdistid       => 'Debian',
+          :lsbdistcodename => 'wheezy',
+          :osfamily        => 'Debian',
+          :puppetversion   => Puppet.version,
+        }
+      end
+      it do
+        expect {
+          subject.call
+        }.to raise_error(Puppet::Error, /source entry without specifying a location/)
+      end
+    end
+    context 'with location' do
+      let :facts do
+        {
+          :lsbdistid       => 'Debian',
+          :lsbdistcodename => 'wheezy',
+          :osfamily        => 'Debian',
+          :puppetversion   => Puppet.version,
+        }
+      end
+      let(:params) { { :location => 'hello.there', } }
+
+      it { is_expected.to contain_apt__setting('list-my_source').with({
+        :ensure  => 'present',
+      }).without_content(/# my_source\ndeb-src hello.there wheezy main\n/)
+      }
+    end
+  end
+
+  describe 'no defaults' do
+    let :facts do
+      {
+        :lsbdistid       => 'Debian',
+        :lsbdistcodename => 'wheezy',
+        :osfamily        => 'Debian',
+        :puppetversion   => Puppet.version,
+      }
+    end
+
+    context 'with complex pin' do
+      let :params do
+        {
+          :location => 'hello.there',
+          :pin      => { 'release'     => 'wishwash',
+                         'explanation' => 'wishwash',
+                         'priority'    => 1001, },
+        }
+      end
+
+      it { is_expected.to contain_apt__setting('list-my_source').with({
+        :ensure => 'present',
+      }).with_content(/hello.there wheezy main\n/)
+      }
+
+      it { is_expected.to contain_file('/etc/apt/sources.list.d/my_source.list').that_notifies('Class[Apt::Update]')}
+
+      it { is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with({
+        :ensure       => 'present',
+        :priority     => 1001,
+        :explanation  => 'wishwash',
+        :release      => 'wishwash',
+      })
+      }
+    end
+
+    context 'with simple key' do
+      let :params do
+        {
+          :comment           => 'foo',
+          :location          => 'http://debian.mirror.iweb.ca/debian/',
+          :release           => 'sid',
+          :repos             => 'testing',
+          :key               => GPG_KEY_ID,
+          :pin               => '10',
+          :architecture      => 'x86_64',
+          :allow_unsigned    => true,
+        }
+      end
+
+      it { is_expected.to contain_apt__setting('list-my_source').with({
+        :ensure => 'present',
+      }).with_content(/# foo\ndeb \[arch=x86_64 trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(/deb-src/)
+      }
+
+      it { is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with({
+        :ensure   => 'present',
+        :priority => '10',
+        :origin   => 'debian.mirror.iweb.ca',
+      })
+      }
+
+      it { is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('Apt::Setting[list-my_source]').with({
+        :ensure  => 'present',
+        :id      => GPG_KEY_ID,
+      })
+      }
+    end
+
+    context 'with complex key' do
+      let :params do
+        {
+          :comment           => 'foo',
+          :location          => 'http://debian.mirror.iweb.ca/debian/',
+          :release           => 'sid',
+          :repos             => 'testing',
+          :key               => { 'id' => GPG_KEY_ID, 'server' => 'pgp.mit.edu',
+                                  'content' => 'GPG key content',
+                                  'source'  => 'http://apt.puppetlabs.com/pubkey.gpg',},
+          :pin               => '10',
+          :architecture      => 'x86_64',
+          :allow_unsigned    => true,
+        }
+      end
+
+      it { is_expected.to contain_apt__setting('list-my_source').with({
+        :ensure => 'present',
+      }).with_content(/# foo\ndeb \[arch=x86_64 trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(/deb-src/)
+      }
+
+      it { is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with({
+        :ensure   => 'present',
+        :priority => '10',
+        :origin   => 'debian.mirror.iweb.ca',
+      })
+      }
+
+      it { is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('Apt::Setting[list-my_source]').with({
+        :ensure  => 'present',
+        :id      => GPG_KEY_ID,
+        :server  => 'pgp.mit.edu',
+        :content => 'GPG key content',
+        :source  => 'http://apt.puppetlabs.com/pubkey.gpg',
+      })
+      }
+    end
+
+    context 'with simple key' do
+      let :params do
+        {
+          :comment        => 'foo',
+          :location       => 'http://debian.mirror.iweb.ca/debian/',
+          :release        => 'sid',
+          :repos          => 'testing',
+          :key            => GPG_KEY_ID,
+          :pin            => '10',
+          :architecture   => 'x86_64',
+          :allow_unsigned => true,
+        }
+      end
+
+      it { is_expected.to contain_apt__setting('list-my_source').with({
+        :ensure => 'present',
+      }).with_content(/# foo\ndeb \[arch=x86_64 trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(/deb-src/)
+      }
+
+      it { is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with({
+        :ensure   => 'present',
+        :priority => '10',
+        :origin   => 'debian.mirror.iweb.ca',
+      })
+      }
+
+      it { is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('Apt::Setting[list-my_source]').with({
+        :ensure  => 'present',
+        :id      => GPG_KEY_ID,
+      })
+      }
+    end
+  end
+
+  context 'allow_unsigned true' do
+    let :facts do
+      {
+        :lsbdistid       => 'Debian',
+        :lsbdistcodename => 'wheezy',
+        :osfamily        => 'Debian',
+        :puppetversion   => Puppet.version,
+      }
+    end
+    let :params do
+      {
+        :location       => 'hello.there',
+        :allow_unsigned => true,
+      }
+    end
+
+    it { is_expected.to contain_apt__setting('list-my_source').with({
+      :ensure => 'present',
+    }).with_content(/# my_source\ndeb \[trusted=yes\] hello.there wheezy main\n/)
+    }
+  end
+
+  context 'architecture equals x86_64' do
+    let :facts do
+      {
+        :lsbdistid       => 'Debian',
+        :lsbdistcodename => 'wheezy',
+        :osfamily        => 'Debian',
+        :puppetversion   => Puppet.version,
+      }
+    end
+    let :params do
+      {
+        :location     => 'hello.there',
+        :include      => {'deb' => false, 'src' => true,},
+        :architecture => 'x86_64',
+      }
+    end
+
+    it { is_expected.to contain_apt__setting('list-my_source').with({
+      :ensure => 'present',
+    }).with_content(/# my_source\ndeb-src \[arch=x86_64\] hello.there wheezy main\n/)
+    }
+  end
+
+  context 'include_src => true' do
+    let :facts do
+      {
+        :lsbdistid       => 'Debian',
+        :lsbdistcodename => 'wheezy',
+        :osfamily        => 'Debian',
+        :puppetversion   => Puppet.version,
+      }
+    end
+    let :params do
+      {
+        :location    => 'hello.there',
+        :include_src => true,
+      }
+    end
+
+    it { is_expected.to contain_apt__setting('list-my_source').with({
+      :ensure => 'present',
+    }).with_content(/# my_source\ndeb hello.there wheezy main\ndeb-src hello.there wheezy main\n/)
+    }
+  end
+
+  context 'include_deb => false' do
+    let :facts do
+      {
+        :lsbdistid       => 'debian',
+        :lsbdistcodename => 'wheezy',
+        :osfamily        => 'debian',
+        :puppetversion   => Puppet.version,
+      }
+    end
+    let :params do
+      {
+        :location    => 'hello.there',
+        :include_deb => false,
+      }
+    end
+
+    it { is_expected.to contain_apt__setting('list-my_source').with({
+      :ensure => 'present',
+    }).without_content(/deb-src hello.there wheezy main\n/)
+    }
+    it { is_expected.to contain_apt__setting('list-my_source').without_content(/deb hello.there wheezy main\n/) }
+  end
+
+  context 'include_src => true and include_deb => false' do
+    let :facts do
+      {
+        :lsbdistid       => 'debian',
+        :lsbdistcodename => 'wheezy',
+        :osfamily        => 'debian',
+        :puppetversion   => Puppet.version,
+      }
+    end
+    let :params do
+      {
+        :location    => 'hello.there',
+        :include_deb => false,
+        :include_src => true,
+      }
+    end
+
+    it { is_expected.to contain_apt__setting('list-my_source').with({
+      :ensure => 'present',
+    }).with_content(/deb-src hello.there wheezy main\n/)
+    }
+    it { is_expected.to contain_apt__setting('list-my_source').without_content(/deb hello.there wheezy main\n/) }
+  end
+
+  context 'include precedence' do
+    let :facts do
+      {
+        :lsbdistid       => 'debian',
+        :lsbdistcodename => 'wheezy',
+        :osfamily        => 'debian',
+        :puppetversion   => Puppet.version,
+      }
+    end
+    let :params do
+      {
+        :location    => 'hello.there',
+        :include_deb => true,
+        :include_src => false,
+        :include     => { 'deb' => false, 'src' => true },
+      }
+    end
+
+    it { is_expected.to contain_apt__setting('list-my_source').with({
+      :ensure => 'present',
+    }).with_content(/deb-src hello.there wheezy main\n/)
+    }
+    it { is_expected.to contain_apt__setting('list-my_source').without_content(/deb hello.there wheezy main\n/) }
+  end
+
+  context 'ensure => absent' do
+    let :facts do
+      {
+        :lsbdistid       => 'Debian',
+        :lsbdistcodename => 'wheezy',
+        :osfamily        => 'Debian',
+        :puppetversion   => Puppet.version,
+      }
+    end
+    let :params do
+      {
+        :ensure => 'absent',
+      }
+    end
+
+    it { is_expected.to contain_apt__setting('list-my_source').with({
+      :ensure => 'absent'
+    })
+    }
+  end
+
+  describe 'validation' do
+    context 'no release' do
+      let :facts do
+        {
+          :lsbdistid       => 'Debian',
+          :osfamily        => 'Debian',
+          :puppetversion   => Puppet.version,
+        }
+      end
+      let(:params) { { :location => 'hello.there', } }
+
+      it do
+        expect {
+          subject.call
+        }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/)
+      end
+    end
+
+    context 'invalid pin' do
+      let :facts do
+        {
+          :lsbdistid       => 'Debian',
+          :lsbdistcodename => 'wheezy',
+          :osfamily        => 'Debian',
+          :puppetversion   => Puppet.version,
+        }
+      end
+      let :params do
+        {
+          :location => 'hello.there',
+          :pin      => true,
+        }
+      end
+
+      it do
+        expect {
+          subject.call
+        }.to raise_error(Puppet::Error, /invalid value for pin/)
+      end
+    end
+
+  end
+end
Index: src/puppetcode/environments/test/modules/apt/spec/spec.opts
===================================================================
--- src/puppetcode/environments/test/modules/apt/spec/spec.opts	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/spec/spec.opts	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,6 @@
+--format
+s
+--colour
+--loadby
+mtime
+--backtrace
Index: src/puppetcode/environments/test/modules/apt/spec/spec_helper.rb
===================================================================
--- src/puppetcode/environments/test/modules/apt/spec/spec_helper.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/spec/spec_helper.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,8 @@
+#This file is generated by ModuleSync, do not edit.
+require 'puppetlabs_spec_helper/module_spec_helper'
+
+# put local configuration and setup into spec_helper_local
+begin
+  require 'spec_helper_local'
+rescue LoadError
+end
Index: src/puppetcode/environments/test/modules/apt/spec/spec_helper_acceptance.rb
===================================================================
--- src/puppetcode/environments/test/modules/apt/spec/spec_helper_acceptance.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/spec/spec_helper_acceptance.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,24 @@
+require 'beaker-rspec'
+require 'beaker/puppet_install_helper'
+
+run_puppet_install_helper
+
+UNSUPPORTED_PLATFORMS = ['RedHat','Suse','windows','AIX','Solaris']
+
+RSpec.configure do |c|
+  # Project root
+  proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
+
+  # Readable test descriptions
+  c.formatter = :documentation
+
+  # Configure all nodes in nodeset
+  c.before :suite do
+    # Install module and dependencies
+    hosts.each do |host|
+      copy_module_to(host, :source => proj_root, :module_name => 'apt')
+      shell("/bin/touch #{default['puppetpath']}/hiera.yaml")
+      on host, puppet('module install puppetlabs-stdlib --version 4.5.0'), { :acceptable_exit_codes => [0,1] }
+    end
+  end
+end
Index: src/puppetcode/environments/test/modules/apt/spec/unit/facter/apt_has_updates_spec.rb
===================================================================
--- src/puppetcode/environments/test/modules/apt/spec/unit/facter/apt_has_updates_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/spec/unit/facter/apt_has_updates_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,56 @@
+require 'spec_helper'
+
+describe 'apt_has_updates fact' do
+  subject { Facter.fact(:apt_has_updates).value }
+  after(:each) { Facter.clear }
+
+  describe 'on non-Debian distro' do
+    before {
+      Facter.fact(:osfamily).expects(:value).at_least(1).returns 'RedHat'
+    }
+    it { is_expected.to be_nil }
+  end
+
+  describe 'on Debian based distro missing update-notifier-common' do
+    before {
+      Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian'
+      File.stubs(:executable?) # Stub all other calls
+      File.expects(:executable?).with('/usr/lib/update-notifier/apt-check').returns false
+    }
+    it { is_expected.to be_nil }
+  end
+
+  describe 'on Debian based distro with broken packages' do
+    before {
+      Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian'
+      File.stubs(:executable?) # Stub all other calls
+      Facter::Util::Resolution.stubs(:exec) # Catch all other calls
+      File.expects(:executable?).with('/usr/lib/update-notifier/apt-check').returns true
+      Facter::Util::Resolution.expects(:exec).with('/usr/lib/update-notifier/apt-check 2>&1').returns "E: Error: BrokenCount > 0"
+    }
+    it { is_expected.to be_nil }
+  end
+
+  describe 'on Debian based distro with unknown error with semicolons' do
+    before {
+      Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian'
+      File.stubs(:executable?) # Stub all other calls
+      Facter::Util::Resolution.stubs(:exec) # Catch all other calls
+      File.expects(:executable?).with('/usr/lib/update-notifier/apt-check').returns true
+      Facter::Util::Resolution.expects(:exec).with('/usr/lib/update-notifier/apt-check 2>&1').returns "E: Unknown Error: 'This error contains something that could be parsed like 4;3' (10)"
+    }
+    it { is_expected.to be_nil }
+  end
+
+  describe 'on Debian based distro' do
+    before {
+      Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian'
+      File.stubs(:executable?) # Stub all other calls
+      Facter::Util::Resolution.stubs(:exec) # Catch all other calls
+      File.expects(:executable?).with('/usr/lib/update-notifier/apt-check').returns true
+      Facter::Util::Resolution.expects(:exec).with('/usr/lib/update-notifier/apt-check 2>&1').returns "4;3"
+    }
+    it { is_expected.to be true }
+  end
+end
+
Index: src/puppetcode/environments/test/modules/apt/spec/unit/facter/apt_package_updates_spec.rb
===================================================================
--- src/puppetcode/environments/test/modules/apt/spec/unit/facter/apt_package_updates_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/spec/unit/facter/apt_package_updates_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,31 @@
+require 'spec_helper'
+
+describe 'apt_package_updates fact' do
+  subject { Facter.fact(:apt_package_updates).value }
+  after(:each) { Facter.clear }
+
+  describe 'when apt has no updates' do
+    before { 
+      Facter.fact(:apt_has_updates).stubs(:value).returns false
+    }
+    it { is_expected.to be nil }
+  end
+
+  describe 'when apt has updates' do
+    before { 
+      Facter.fact(:osfamily).stubs(:value).returns 'Debian'
+      File.stubs(:executable?) # Stub all other calls
+      Facter::Util::Resolution.stubs(:exec) # Catch all other calls
+      File.expects(:executable?).with('/usr/lib/update-notifier/apt-check').returns true
+      Facter::Util::Resolution.expects(:exec).with('/usr/lib/update-notifier/apt-check 2>&1').returns "1;2"
+      Facter::Util::Resolution.expects(:exec).with('/usr/lib/update-notifier/apt-check -p 2>&1').returns "puppet-common\nlinux-generic\nlinux-image-generic"
+    }
+    it {
+      if Facter.version < '2.0.0'
+        is_expected.to eq('puppet-common,linux-generic,linux-image-generic')
+      else
+        is_expected.to eq(['puppet-common', 'linux-generic', 'linux-image-generic'])
+      end
+    }
+  end
+end
Index: src/puppetcode/environments/test/modules/apt/spec/unit/facter/apt_reboot_required_spec.rb
===================================================================
--- src/puppetcode/environments/test/modules/apt/spec/unit/facter/apt_reboot_required_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/spec/unit/facter/apt_reboot_required_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,25 @@
+require 'spec_helper'
+
+describe 'apt_reboot_required fact' do
+  subject { Facter.fact(:apt_reboot_required).value }
+  after(:each) { Facter.clear }
+
+  describe 'if a reboot is required' do
+    before {
+      Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian'
+      File.stubs(:file?).returns true
+      File.expects(:file?).at_least(1).with('/var/run/reboot-required').returns true
+    }
+    it { is_expected.to eq true }
+  end
+
+  describe 'if a reboot is not required' do
+    before {
+      Facter.fact(:osfamily).expects(:value).at_least(1).returns 'Debian'
+      File.stubs(:file?).returns true
+      File.expects(:file?).at_least(1).with('/var/run/reboot-required').returns false
+    }
+    it { is_expected.to eq false }
+  end
+
+end
Index: src/puppetcode/environments/test/modules/apt/spec/unit/facter/apt_security_updates_spec.rb
===================================================================
--- src/puppetcode/environments/test/modules/apt/spec/unit/facter/apt_security_updates_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/spec/unit/facter/apt_security_updates_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,25 @@
+require 'spec_helper'
+
+describe 'apt_security_updates fact' do
+  subject { Facter.fact(:apt_security_updates).value }
+  after(:each) { Facter.clear }
+
+  describe 'when apt has no updates' do
+    before { 
+      Facter.fact(:apt_has_updates).stubs(:value).returns false
+    }
+    it { is_expected.to be nil }
+  end
+
+  describe 'when apt has security updates' do
+    before { 
+      Facter.fact(:osfamily).stubs(:value).returns 'Debian'
+      File.stubs(:executable?) # Stub all other calls
+      Facter::Util::Resolution.stubs(:exec) # Catch all other calls
+      File.expects(:executable?).with('/usr/lib/update-notifier/apt-check').returns true
+      Facter::Util::Resolution.expects(:exec).with('/usr/lib/update-notifier/apt-check 2>&1').returns "14;7"
+    }
+    it { is_expected.to eq(7) }
+  end
+
+end
Index: src/puppetcode/environments/test/modules/apt/spec/unit/facter/apt_update_last_success_spec.rb
===================================================================
--- src/puppetcode/environments/test/modules/apt/spec/unit/facter/apt_update_last_success_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/spec/unit/facter/apt_update_last_success_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,28 @@
+require 'spec_helper'
+
+describe 'apt_update_last_success fact' do
+  subject { Facter.fact(:apt_update_last_success).value }
+  after(:each) { Facter.clear }
+
+  describe 'on Debian based distro which has not yet created the update-success-stamp file' do
+    before {
+      Facter.fact(:osfamily).stubs(:value).returns 'Debian'
+      File.stubs(:exists?).returns false
+    }
+    it 'should have a value of -1' do
+      is_expected.to eq(-1)
+    end
+  end
+
+  describe 'on Debian based distro which has created the update-success-stamp' do
+    before {
+      Facter.fact(:osfamily).stubs(:value).returns 'Debian'
+      File.stubs(:exists?).returns true
+      File.stubs(:mtime).returns 1407660561
+    }
+    it 'should have the value of the mtime of the file' do
+      is_expected.to eq(1407660561)
+    end
+  end
+
+end
Index: src/puppetcode/environments/test/modules/apt/spec/unit/facter/apt_updates_spec.rb
===================================================================
--- src/puppetcode/environments/test/modules/apt/spec/unit/facter/apt_updates_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/spec/unit/facter/apt_updates_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,25 @@
+require 'spec_helper'
+
+describe 'apt_updates fact' do
+  subject { Facter.fact(:apt_updates).value }
+  after(:each) { Facter.clear }
+
+  describe 'when apt has no updates' do
+    before { 
+      Facter.fact(:apt_has_updates).stubs(:value).returns false
+    }
+    it { is_expected.to be nil }
+  end
+
+  describe 'when apt has updates' do
+    before { 
+      Facter.fact(:osfamily).stubs(:value).returns 'Debian'
+      File.stubs(:executable?) # Stub all other calls
+      Facter::Util::Resolution.stubs(:exec) # Catch all other calls
+      File.expects(:executable?).with('/usr/lib/update-notifier/apt-check').returns true
+      Facter::Util::Resolution.expects(:exec).with('/usr/lib/update-notifier/apt-check 2>&1').returns "14;7"
+    }
+    it { is_expected.to eq(14) }
+  end
+
+end
Index: src/puppetcode/environments/test/modules/apt/spec/unit/puppet/type/apt_key_spec.rb
===================================================================
--- src/puppetcode/environments/test/modules/apt/spec/unit/puppet/type/apt_key_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/spec/unit/puppet/type/apt_key_spec.rb	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,181 @@
+require 'spec_helper'
+require 'puppet'
+
+describe Puppet::Type::type(:apt_key) do
+  context 'only namevar 32bit key id' do
+    let(:resource) { Puppet::Type.type(:apt_key).new(
+      :id => '4BD6EC30'
+    )}
+    it 'id is set' do
+      expect(resource[:id]).to eq '4BD6EC30'
+    end
+
+    it 'name is set to id' do
+      expect(resource[:name]).to eq '4BD6EC30'
+    end
+
+    it 'keyserver is default' do
+      expect(resource[:server]).to eq :'keyserver.ubuntu.com'
+    end
+
+    it 'source is not set' do
+      expect(resource[:source]).to eq nil
+    end
+
+    it 'content is not set' do
+      expect(resource[:content]).to eq nil
+    end
+  end
+
+  context 'with a lowercase 32bit key id' do
+    let(:resource) { Puppet::Type.type(:apt_key).new(
+      :id => '4bd6ec30'
+    )}
+    it 'id is set' do
+      expect(resource[:id]).to eq '4BD6EC30'
+    end
+  end
+
+  context 'with a 64bit key id' do
+    let(:resource) { Puppet::Type.type(:apt_key).new(
+      :id => 'FFFFFFFF4BD6EC30'
+    )}
+    it 'id is set' do
+      expect(resource[:id]).to eq 'FFFFFFFF4BD6EC30'
+    end
+  end
+
+  context 'with a 0x formatted key id' do
+    let(:resource) { Puppet::Type.type(:apt_key).new(
+      :id => '0x4BD6EC30'
+    )}
+    it 'id is set' do
+      expect(resource[:id]).to eq '4BD6EC30'
+    end
+  end
+
+  context 'with a 0x formatted lowercase key id' do
+    let(:resource) { Puppet::Type.type(:apt_key).new(
+      :id => '0x4bd6ec30'
+    )}
+    it 'id is set' do
+      expect(resource[:id]).to eq '4BD6EC30'
+    end
+  end
+
+  context 'with a 0x formatted 64bit key id' do
+    let(:resource) { Puppet::Type.type(:apt_key).new(
+      :id => '0xFFFFFFFF4BD6EC30'
+    )}
+    it 'id is set' do
+      expect(resource[:id]).to eq 'FFFFFFFF4BD6EC30'
+    end
+  end
+
+  context 'with source' do
+    let(:resource) { Puppet::Type.type(:apt_key).new(
+      :id => '4BD6EC30',
+      :source => 'http://apt.puppetlabs.com/pubkey.gpg'
+    )}
+
+    it 'source is set to the URL' do
+      expect(resource[:source]).to eq 'http://apt.puppetlabs.com/pubkey.gpg'
+    end
+  end
+
+  context 'with content' do
+    let(:resource) { Puppet::Type.type(:apt_key).new(
+      :id => '4BD6EC30',
+      :content => 'http://apt.puppetlabs.com/pubkey.gpg'
+    )}
+
+    it 'content is set to the string' do
+      expect(resource[:content]).to eq 'http://apt.puppetlabs.com/pubkey.gpg'
+    end
+  end
+
+  context 'with keyserver' do
+    let(:resource) { Puppet::Type.type(:apt_key).new(
+      :id => '4BD6EC30',
+      :server => 'http://keyring.debian.org'
+    )}
+
+    it 'keyserver is set to Debian' do
+      expect(resource[:server]).to eq 'http://keyring.debian.org'
+    end
+  end
+
+  context 'validation' do
+    it 'raises an error if content and source are set' do
+      expect { Puppet::Type.type(:apt_key).new(
+        :id      => '4BD6EC30',
+        :source  => 'http://apt.puppetlabs.com/pubkey.gpg',
+        :content => 'Completely invalid as a GPG key'
+      )}.to raise_error(/content and source are mutually exclusive/)
+    end
+
+    it 'raises an error if a weird length key is used' do
+      expect { Puppet::Type.type(:apt_key).new(
+        :id      => 'F4BD6EC30',
+        :source  => 'http://apt.puppetlabs.com/pubkey.gpg',
+        :content => 'Completely invalid as a GPG key'
+      )}.to raise_error(/Valid values match/)
+    end
+
+    it 'raises an error when an invalid URI scheme is used in source' do
+      expect { Puppet::Type.type(:apt_key).new(
+        :id      => '4BD6EC30',
+        :source  => 'hkp://pgp.mit.edu'
+      )}.to raise_error(/Valid values match/)
+    end
+
+    it 'allows the http URI scheme in source' do
+      expect { Puppet::Type.type(:apt_key).new(
+        :id      => '4BD6EC30',
+        :source  => 'http://pgp.mit.edu'
+      )}.to_not raise_error
+    end
+
+    it 'allows the https URI scheme in source' do
+      expect { Puppet::Type.type(:apt_key).new(
+        :id      => '4BD6EC30',
+        :source  => 'https://pgp.mit.edu'
+      )}.to_not raise_error
+    end
+
+    it 'allows the https URI with username and password' do
+      expect { Puppet::Type.type(:apt_key).new(
+          :id      => '4BD6EC30',
+          :source  => 'https://testme:Password2@pgp.mit.edu'
+      )}.to_not raise_error
+    end
+
+    it 'allows the ftp URI scheme in source' do
+      expect { Puppet::Type.type(:apt_key).new(
+        :id      => '4BD6EC30',
+        :source  => 'ftp://pgp.mit.edu'
+      )}.to_not raise_error
+    end
+
+    it 'allows an absolute path in source' do
+      expect { Puppet::Type.type(:apt_key).new(
+        :id      => '4BD6EC30',
+        :source  => '/path/to/a/file'
+      )}.to_not raise_error
+    end
+
+    it 'allows 5-digit ports' do
+      expect { Puppet::Type.type(:apt_key).new(
+        :id      => '4BD6EC30',
+        :source  => 'http://pgp.mit.edu:12345/key'
+      )}.to_not raise_error
+    end
+
+    it 'allows 5-digit ports when using key servers' do
+      expect { Puppet::Type.type(:apt_key).new(
+        :id      => '4BD6EC30',
+        :server  => 'http://pgp.mit.edu:12345'
+      )}.to_not raise_error
+    end
+  end
+end
