+ let :facts do
+ {
+ os: {
+ family: 'Debian',
+ name: 'Debian',
+ release: {
+ major: '8',
+ full: '8.0',
+ },
+ distro: {
+ codename: 'jessie',
+ id: 'Debian',
+ },
+ },
+ }
+ end
+
+ context 'with defaults' do
+ context 'without location' do
+ it do
+ is_expected.to raise_error(Puppet::Error, %r{source entry without specifying a location})
+ end
+ end
+ context 'with location' do
+ let(:params) { { location: 'hello.there' } }
+
+ it {
+ is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').without_content(%r{# my_source\ndeb-src hello.there wheezy main\n})
+ is_expected.not_to contain_package('apt-transport-https')
+ }
+ end
+ end
+
+ describe 'no defaults' do
+ 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(%r{hello.there jessie 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(%r{# foo\ndeb \[arch=x86_64 trusted=yes\] http://debian.mirror.iweb.ca/debian/ sid testing\n})
+ .without_content(%r{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: {
+ 'ensure' => 'refreshed',
+ 'id' => GPG_KEY_ID,
+ 'server' => 'pgp.mit.edu',
+ 'content' => 'GPG key content',
+ 'source' => 'http://apt.puppetlabs.com/pubkey.gpg',
+ 'weak_ssl' => true,
+ },
+ pin: '10',
+ architecture: 'x86_64',
+ allow_unsigned: true,
+ }
+ end
+
+ it {
+ is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# foo\ndeb \[arch=x86_64 trusted=yes\] http://debian.mirror.iweb.ca/debian/ sid testing\n})
+ .without_content(%r{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: 'refreshed',
+ id: GPG_KEY_ID,
+ server: 'pgp.mit.edu',
+ content: 'GPG key content',
+ source: 'http://apt.puppetlabs.com/pubkey.gpg',
+ weak_ssl: true)
+ }
+ end
+ end
+
+ context 'with allow_unsigned true' do
+ 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(%r{# my_source\ndeb \[trusted=yes\] hello.there jessie main\n})
+ }
+ end
+
+ context 'with keyring set' do
+ let :params do
+ {
+ location: 'hello.there',
+ keyring: '/usr/share/keyrings/foo-archive-keyring.gpg',
+ }
+ end
+
+ it {
+ is_expected.to contain_apt__setting('list-my_source')
+ .with(ensure: 'present')
+ .with_content(%r{# my_source\ndeb \[signed-by=/usr/share/keyrings/foo-archive-keyring.gpg\] hello.there jessie main\n})
+ }
+ end
+
+ context 'with keyring, architecture and allow_unsigned set' do
+ let :params do
+ {
+ location: 'hello.there',
+ architecture: 'amd64',
+ allow_unsigned: true,
+ keyring: '/usr/share/keyrings/foo-archive-keyring.gpg',
+ }
+ end
+
+ it {
+ is_expected.to contain_apt__setting('list-my_source')
+ .with(ensure: 'present')
+ .with_content(%r{# my_source\ndeb \[arch=amd64 trusted=yes signed-by=/usr/share/keyrings/foo-archive-keyring.gpg\] hello.there jessie main\n})
+ }
+ end
+
+ context 'with a https location, install apt-transport-https' do
+ let :params do
+ {
+ location: 'HTTPS://foo.bar',
+ allow_unsigned: false,
+ }
+ end
+
+ it {
+ is_expected.to contain_package('apt-transport-https')
+ }
+ end
+
+ context 'with a https location and custom release, install apt-transport-https' do