summaryrefslogtreecommitdiff
path: root/code/environments/production/modules/apt/spec/defines
diff options
context:
space:
mode:
Diffstat (limited to 'code/environments/production/modules/apt/spec/defines')
-rw-r--r--code/environments/production/modules/apt/spec/defines/conf_spec.rb90
-rw-r--r--code/environments/production/modules/apt/spec/defines/key_compat_spec.rb360
-rw-r--r--code/environments/production/modules/apt/spec/defines/key_spec.rb367
-rw-r--r--code/environments/production/modules/apt/spec/defines/pin_spec.rb148
-rw-r--r--code/environments/production/modules/apt/spec/defines/ppa_spec.rb379
-rw-r--r--code/environments/production/modules/apt/spec/defines/setting_spec.rb145
-rw-r--r--code/environments/production/modules/apt/spec/defines/source_compat_spec.rb154
-rw-r--r--code/environments/production/modules/apt/spec/defines/source_spec.rb452
8 files changed, 2095 insertions, 0 deletions
diff --git a/code/environments/production/modules/apt/spec/defines/conf_spec.rb b/code/environments/production/modules/apt/spec/defines/conf_spec.rb
new file mode 100644
index 0000000..d79cb22
--- /dev/null
+++ b/code/environments/production/modules/apt/spec/defines/conf_spec.rb
@@ -0,0 +1,90 @@
+require 'spec_helper'
+describe 'apt::conf', type: :define do
+ let :pre_condition do
+ 'class { "apt": }'
+ end
+ let(:facts) do
+ {
+ os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
+ lsbdistid: 'Debian',
+ osfamily: 'Debian',
+ lsbdistcodename: 'wheezy',
+ puppetversion: Puppet.version,
+ }
+ end
+ 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' => %r{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
+ is_expected.to raise_error(%r{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
diff --git a/code/environments/production/modules/apt/spec/defines/key_compat_spec.rb b/code/environments/production/modules/apt/spec/defines/key_compat_spec.rb
new file mode 100644
index 0000000..43ccbbc
--- /dev/null
+++ b/code/environments/production/modules/apt/spec/defines/key_compat_spec.rb
@@ -0,0 +1,360 @@
+require 'spec_helper'
+
+def contains_apt_key_example(title)
+ { id: title,
+ ensure: 'present',
+ source: 'http://apt.puppetlabs.com/pubkey.gpg',
+ server: 'pgp.mit.edu',
+ content: params[:content],
+ options: 'debug' }
+end
+
+def apt_key_example(title)
+ { id: title,
+ ensure: 'present',
+ source: nil,
+ server: 'keyserver.ubuntu.com',
+ content: nil,
+ keyserver_options: nil }
+end
+
+describe 'apt::key', type: :define do
+ GPG_KEY_ID = '6F6B15509CF8E59E6E469F327F438280EF8D349F'.freeze
+
+ let(:facts) do
+ {
+ os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
+ lsbdistid: 'Debian',
+ osfamily: 'Debian',
+ puppetversion: Puppet.version,
+ }
+ end
+
+ let :title do
+ GPG_KEY_ID
+ end
+
+ let :pre_condition do
+ 'include apt'
+ end
+
+ describe 'normal operation' do
+ describe 'default options' do
+ it {
+ is_expected.to contain_apt_key(title).with(id: title,
+ ensure: 'present',
+ source: nil,
+ server: 'keyserver.ubuntu.com',
+ content: nil)
+ }
+ 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)
+ 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)
+ 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(contains_apt_key_example(title))
+ end
+ it 'contains the apt_key present anchor' do
+ is_expected.to contain_anchor("apt_key #{title} present")
+ end
+ end
+
+ context 'when domain has 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 'with 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 'with url and 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 'when domain begins with a dash' do
+ let(:params) do
+ {
+ server: '-pgp.mit.edu',
+ }
+ end
+
+ it 'fails' do
+ is_expected .to raise_error(%r{expects a match})
+ end
+ end
+
+ context 'when domain begins with dot' do
+ let(:params) do
+ {
+ server: '.pgp.mit.edu',
+ }
+ end
+
+ it 'fails' do
+ is_expected .to raise_error(%r{expects a match})
+ end
+ end
+
+ context 'when domain ends with dot' do
+ let(:params) do
+ {
+ server: 'pgp.mit.edu.',
+ }
+ end
+
+ it 'fails' do
+ is_expected .to raise_error(%r{expects a match})
+ end
+ end
+ context 'when url character limit is exceeded' do
+ let :params do
+ {
+ server: 'hkp://pgpiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.mit.edu',
+ }
+ end
+
+ it 'fails' do
+ is_expected.to raise_error(%r{expects a match})
+ end
+ end
+ context 'with incorrect port number url' do
+ let :params do
+ {
+ server: 'hkp://pgp.mit.edu:8008080',
+ }
+ end
+
+ it 'fails' do
+ is_expected.to raise_error(%r{expects a match})
+ end
+ end
+ context 'with incorrect protocol for url' do
+ let :params do
+ {
+ server: 'abc://pgp.mit.edu:80',
+ }
+ end
+
+ it 'fails' do
+ is_expected.to raise_error(%r{expects a match})
+ end
+ end
+ context 'with missing port number url' do
+ let :params do
+ {
+ server: 'hkp://pgp.mit.edu:',
+ }
+ end
+
+ it 'fails' do
+ is_expected.to raise_error(%r{expects a match})
+ end
+ end
+ context 'with url ending with a dot' do
+ let :params do
+ {
+ server: 'hkp://pgp.mit.edu.',
+ }
+ end
+
+ it 'fails' do
+ is_expected.to raise_error(%r{expects a match})
+ end
+ end
+ context 'with url begin with a dash' do
+ let(:params) do
+ {
+ server: 'hkp://-pgp.mit.edu',
+ }
+ end
+
+ it 'fails' do
+ is_expected.to raise_error(%r{expects a match})
+ end
+ end
+ context 'with invalid key' do
+ let :title do
+ 'Out of rum. Why? Why are we out of rum?'
+ end
+
+ it 'fails' do
+ is_expected.to raise_error(%r{expects a match})
+ end
+ end
+
+ context 'with invalid source' do
+ let :params do
+ {
+ source: 'afp://puppetlabs.com/key.gpg',
+ }
+ end
+
+ it 'fails' do
+ is_expected.to raise_error(%r{expects a match})
+ end
+ end
+
+ context 'with invalid content' do
+ let :params do
+ {
+ content: [],
+ }
+ end
+
+ it 'fails' do
+ is_expected.to raise_error(%r{expects a})
+ end
+ end
+
+ context 'with invalid server' do
+ let :params do
+ {
+ server: 'two bottles of rum',
+ }
+ end
+
+ it 'fails' do
+ is_expected.to raise_error(%r{expects a match})
+ end
+ end
+
+ context 'with invalid keyserver_options' do
+ let :params do
+ {
+ options: {},
+ }
+ end
+
+ it 'fails' do
+ is_expected.to raise_error(%r{expects a})
+ end
+ end
+
+ context 'with invalid ensure' do
+ let :params do
+ {
+ ensure: 'foo',
+ }
+ end
+
+ it 'fails' do
+ is_expected.to raise_error(%r{Enum\['absent', 'present'\]})
+ end
+ end
+
+ describe 'duplication - two apt::key resources for same key, different titles' do
+ let :pre_condition do
+ "#{super()}\napt::key { 'duplicate': id => '#{title}', }"
+ end
+
+ it 'contains the duplicate apt::key resource' do
+ is_expected.to contain_apt__key('duplicate').with(id: title,
+ ensure: 'present')
+ end
+
+ it 'contains the original apt::key resource' do
+ is_expected.to contain_apt__key(title).with(id: title,
+ ensure: 'present')
+ end
+
+ it 'contains the native apt_key' do
+ is_expected.to contain_apt_key('duplicate').with(apt_key_example(title))
+ end
+
+ it 'does not contain the original apt_key' do
+ is_expected.not_to contain_apt_key(title)
+ end
+ end
+
+ describe 'duplication - two apt::key resources, different ensure' do
+ let :pre_condition do
+ "#{super()}\napt::key { 'duplicate': id => '#{title}', ensure => 'absent', }"
+ end
+
+ it 'informs the user of the impossibility' do
+ is_expected.to raise_error(%r{already ensured as absent})
+ end
+ end
+ end
+end
diff --git a/code/environments/production/modules/apt/spec/defines/key_spec.rb b/code/environments/production/modules/apt/spec/defines/key_spec.rb
new file mode 100644
index 0000000..6a5a89f
--- /dev/null
+++ b/code/environments/production/modules/apt/spec/defines/key_spec.rb
@@ -0,0 +1,367 @@
+require 'spec_helper'
+
+GPG_KEY_ID = '6F6B15509CF8E59E6E469F327F438280EF8D349F'.freeze
+
+title_key_example = { id: GPG_KEY_ID,
+ ensure: 'present',
+ source: nil,
+ server: 'keyserver.ubuntu.com',
+ content: nil,
+ options: nil }
+
+def default_apt_key_example(title)
+ { id: title,
+ ensure: 'present',
+ source: nil,
+ server: 'keyserver.ubuntu.com',
+ content: nil,
+ options: nil }
+end
+
+def bunch_things_apt_key_example(title, params)
+ { id: title,
+ ensure: 'present',
+ source: 'http://apt.puppetlabs.com/pubkey.gpg',
+ server: 'pgp.mit.edu',
+ content: params[:content],
+ options: 'debug' }
+end
+
+def absent_apt_key(title)
+ { id: title,
+ ensure: 'absent',
+ source: nil,
+ server: 'keyserver.ubuntu.com',
+ content: nil,
+ keyserver: nil }
+end
+
+describe 'apt::key' do
+ let :pre_condition do
+ 'class { "apt": }'
+ end
+
+ let(:facts) do
+ {
+ os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
+ lsbdistid: 'Debian',
+ osfamily: 'Debian',
+ lsbdistcodename: 'wheezy',
+ puppetversion: Puppet.version,
+ }
+ end
+
+ 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(default_apt_key_example(title))
+ 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(title_key_example)
+ 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(absent_apt_key(title))
+ 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(bunch_things_apt_key_example(title, params))
+ end
+ it 'contains the apt_key present anchor' do
+ is_expected.to contain_anchor("apt_key #{title} present")
+ end
+ end
+
+ context 'when 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 'with 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 'when 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 'when domain begin with dash' do
+ let(:params) do
+ {
+ server: '-pgp.mit.edu',
+ }
+ end
+
+ it 'fails' do
+ is_expected .to raise_error(%r{expects a match})
+ end
+ end
+
+ context 'when domain begin with dot' do
+ let(:params) do
+ {
+ server: '.pgp.mit.edu',
+ }
+ end
+
+ it 'fails' do
+ is_expected .to raise_error(%r{expects a match})
+ end
+ end
+
+ context 'when domain end with dot' do
+ let(:params) do
+ {
+ server: 'pgp.mit.edu.',
+ }
+ end
+
+ it 'fails' do
+ is_expected .to raise_error(%r{expects a match})
+ end
+ end
+ context 'when character url exceeded' do
+ let :params do
+ {
+ server: 'hkp://pgpiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.mit.edu',
+ }
+ end
+
+ it 'fails' do
+ is_expected.to raise_error(%r{expects a match})
+ end
+ end
+ context 'with incorrect port number url' do
+ let :params do
+ {
+ server: 'hkp://pgp.mit.edu:8008080',
+ }
+ end
+
+ it 'fails' do
+ is_expected.to raise_error(%r{expects a match})
+ end
+ end
+ context 'with incorrect protocol for url' do
+ let :params do
+ {
+ server: 'abc://pgp.mit.edu:80',
+ }
+ end
+
+ it 'fails' do
+ is_expected.to raise_error(%r{expects a match})
+ end
+ end
+ context 'with missing port number url' do
+ let :params do
+ {
+ server: 'hkp://pgp.mit.edu:',
+ }
+ end
+
+ it 'fails' do
+ is_expected.to raise_error(%r{expects a match})
+ end
+ end
+ context 'with url ending with a dot' do
+ let :params do
+ {
+ server: 'hkp://pgp.mit.edu.',
+ }
+ end
+
+ it 'fails' do
+ is_expected.to raise_error(%r{expects a match})
+ end
+ end
+ context 'when url begins with a dash' do
+ let(:params) do
+ {
+ server: 'hkp://-pgp.mit.edu',
+ }
+ end
+
+ it 'fails' do
+ is_expected.to raise_error(%r{expects a match})
+ end
+ end
+ context 'with invalid key' do
+ let :title do
+ 'Out of rum. Why? Why are we out of rum?'
+ end
+
+ it 'fails' do
+ is_expected.to raise_error(%r{expects a match})
+ end
+ end
+
+ context 'with invalid source' do
+ let :params do
+ {
+ source: 'afp://puppetlabs.com/key.gpg',
+ }
+ end
+
+ it 'fails' do
+ is_expected.to raise_error(%r{expects a match})
+ end
+ end
+
+ context 'with invalid content' do
+ let :params do
+ {
+ content: [],
+ }
+ end
+
+ it 'fails' do
+ is_expected.to raise_error(%r{expects a})
+ end
+ end
+
+ context 'with invalid server' do
+ let :params do
+ {
+ server: 'two bottles of rum',
+ }
+ end
+
+ it 'fails' do
+ is_expected.to raise_error(%r{expects a match})
+ end
+ end
+
+ context 'with invalid options' do
+ let :params do
+ {
+ options: {},
+ }
+ end
+
+ it 'fails' do
+ is_expected.to raise_error(%r{expects a})
+ end
+ end
+
+ context 'with invalid ensure' do
+ %w[foo aabsent absenta apresent presenta].each do |param|
+ let :params do
+ {
+ ensure: param,
+ }
+ end
+
+ it 'fails' do
+ is_expected.to raise_error(%r{for Enum\['absent', 'present'\], got})
+ end
+ end
+ end
+
+ describe 'duplication - 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 resource - duplicate' do
+ is_expected.to contain_apt__key('duplicate').with(id: title,
+ ensure: 'present')
+ end
+ it 'contains two apt::key resource - title' do
+ is_expected.to contain_apt__key(title).with(id: title,
+ ensure: 'present')
+ end
+
+ it 'contains only a single apt_key - duplicate' do
+ is_expected.to contain_apt_key('duplicate').with(default_apt_key_example(title))
+ end
+ it 'contains only a single apt_key - no title' do
+ is_expected.not_to contain_apt_key(title)
+ end
+ end
+
+ describe 'duplication - 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
+ is_expected.to raise_error(%r{already ensured as absent})
+ end
+ end
+ end
+end
diff --git a/code/environments/production/modules/apt/spec/defines/pin_spec.rb b/code/environments/production/modules/apt/spec/defines/pin_spec.rb
new file mode 100644
index 0000000..2329e9a
--- /dev/null
+++ b/code/environments/production/modules/apt/spec/defines/pin_spec.rb
@@ -0,0 +1,148 @@
+require 'spec_helper'
+describe 'apt::pin', type: :define do
+ let :pre_condition do
+ 'class { "apt": }'
+ end
+ let(:facts) do
+ {
+ os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
+ lsbdistid: 'Debian',
+ osfamily: 'Debian',
+ lsbdistcodename: 'wheezy',
+ puppetversion: Puppet.version,
+ }
+ end
+ let(:title) { 'my_pin' }
+
+ context 'with defaults' do
+ it { is_expected.to contain_apt__setting('pref-my_pin').with_content(%r{Explanation: : my_pin\nPackage: \*\nPin: release a=my_pin\nPin-Priority: 0\n}) }
+ end
+
+ context 'with set version' do
+ let :params do
+ {
+ 'packages' => 'vim',
+ 'version' => '1',
+ }
+ end
+
+ it { is_expected.to contain_apt__setting('pref-my_pin').with_content(%r{Explanation: : my_pin\nPackage: vim\nPin: version 1\nPin-Priority: 0\n}) }
+ end
+
+ context 'with set origin' do
+ let :params do
+ {
+ 'packages' => 'vim',
+ 'origin' => 'test',
+ }
+ end
+
+ it { is_expected.to contain_apt__setting('pref-my_pin').with_content(%r{Explanation: : my_pin\nPackage: vim\nPin: origin test\nPin-Priority: 0\n}) }
+ end
+
+ context 'without 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(%r{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 'with ensure absent' do
+ let :params do
+ {
+ 'ensure' => 'absent',
+ }
+ end
+
+ it {
+ is_expected.to contain_apt__setting('pref-my_pin').with('ensure' => 'absent')
+ }
+ end
+
+ context 'with bad characters' do
+ let(:title) { 'such bad && wow!' }
+
+ it { is_expected.to contain_apt__setting('pref-such__bad____wow_') }
+ end
+
+ describe 'validation' do
+ context 'with invalid order' do
+ let :params do
+ {
+ 'order' => 'foo',
+ }
+ end
+
+ it do
+ is_expected.to raise_error(Puppet::Error, %r{expects an Integer value, got String})
+ end
+ end
+
+ context 'with packages == * and version' do
+ let :params do
+ {
+ 'version' => '1',
+ }
+ end
+
+ it do
+ is_expected.to raise_error(Puppet::Error, %r{parameter version cannot be used in general form})
+ end
+ end
+
+ context 'with packages == * and release and origin' do
+ let :params do
+ {
+ 'origin' => 'test',
+ 'release' => 'foo',
+ }
+ end
+
+ it do
+ is_expected.to raise_error(Puppet::Error, %r{parameters release and origin are mutually exclusive})
+ end
+ end
+
+ context 'with specific release and origin' do
+ let :params do
+ {
+ 'release' => 'foo',
+ 'origin' => 'test',
+ 'packages' => 'vim',
+ }
+ end
+
+ it do
+ is_expected.to raise_error(Puppet::Error, %r{parameters release, origin, and version are mutually exclusive})
+ end
+ end
+
+ context 'with specific version and origin' do
+ let :params do
+ {
+ 'version' => '1',
+ 'origin' => 'test',
+ 'packages' => 'vim',
+ }
+ end
+
+ it do
+ is_expected.to raise_error(Puppet::Error, %r{parameters release, origin, and version are mutually exclusive})
+ end
+ end
+ end
+end
diff --git a/code/environments/production/modules/apt/spec/defines/ppa_spec.rb b/code/environments/production/modules/apt/spec/defines/ppa_spec.rb
new file mode 100644
index 0000000..b534186
--- /dev/null
+++ b/code/environments/production/modules/apt/spec/defines/ppa_spec.rb
@@ -0,0 +1,379 @@
+require 'spec_helper'
+describe 'apt::ppa' do
+ let :pre_condition do
+ 'class { "apt": }'
+ end
+
+ describe 'defaults' do
+ let :facts do
+ {
+ os: { family: 'Debian', name: 'Ubuntu', release: { major: '11', full: '11.04' } },
+ 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.not_to 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', # rubocop:disable Metrics/LineLength
+ unless: '/usr/bin/test -f /etc/apt/sources.list.d/needs-such_substitution-wow_type-natty.list', # rubocop:disable Metrics/LineLength
+ user: 'root',
+ logoutput: 'on_failure')
+ }
+ end
+
+ describe 'Ubuntu 15.10 sources.list filename' do
+ let :facts do
+ {
+ os: { family: 'Debian', name: 'Ubuntu', release: { major: '15', full: '15.10' } },
+ 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 -f /etc/apt/sources.list.d/user-ubuntu-foo-wily.list',
+ user: 'root',
+ logoutput: 'on_failure')
+ }
+ 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
+ {
+ os: { family: 'Debian', name: 'Ubuntu', release: { major: '11', full: '11.04' } },
+ 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', # rubocop:disable Metrics/LineLength
+ 'unless' => '/usr/bin/test -f /etc/apt/sources.list.d/needs-such_substitution-wow-natty.list', # rubocop:disable Metrics/LineLength
+ '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
+ {
+ os: { family: 'Debian', name: 'Ubuntu', release: { major: '11', full: '11.04' } },
+ 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 -f /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
+ {
+ os: { family: 'Debian', name: 'Ubuntu', release: { major: '11', full: '11.04' } },
+ 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.not_to 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', # rubocop:disable Metrics/LineLength
+ 'unless' => '/usr/bin/test -f /etc/apt/sources.list.d/needs-such_substitution-wow-natty.list', # rubocop:disable Metrics/LineLength
+ '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
+ {
+ os: { family: 'Debian', name: 'Ubuntu', release: { major: '14', full: '14.04' } },
+ 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 -f /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
+ {
+ os: { family: 'Debian', name: 'Ubuntu', release: { major: '14', full: '14.04' } },
+ 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 -f /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
+ {
+ os: { family: 'Debian', name: 'Ubuntu', release: { major: '14', full: '14.04' } },
+ 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 -f /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
+ {
+ os: { family: 'Debian', name: 'Ubuntu', release: { major: '14', full: '14.04' } },
+ 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 -f /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
+ {
+ os: { family: 'Debian', name: 'Ubuntu', release: { major: '14', full: '14.04' } },
+ 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 'with validation' do
+ describe 'no release' do
+ let :facts do
+ {
+ os: { family: 'Debian', name: 'Ubuntu', release: { major: '14', full: '14.04' } },
+ lsbdistrelease: '14.04',
+ operatingsystem: 'Ubuntu',
+ lsbdistid: 'Ubuntu',
+ osfamily: 'Debian',
+ lsbdistcodeanme: nil,
+ puppetversion: Puppet.version,
+ }
+ end
+ let(:title) { 'ppa:user/foo' }
+
+ it do
+ is_expected.to raise_error(Puppet::Error, %r{lsbdistcodename fact not available: release parameter required})
+ end
+ end
+
+ describe 'not ubuntu' do
+ let :facts do
+ {
+ os: { family: 'Debian', name: 'Debian', release: { major: '6', full: '6.0.7' } },
+ lsbdistrelease: '6.0.7',
+ lsbdistcodename: 'wheezy',
+ operatingsystem: 'Debian',
+ lsbdistid: 'debian',
+ osfamily: 'Debian',
+ puppetversion: Puppet.version,
+ }
+ end
+ let(:title) { 'ppa:user/foo' }
+
+ it do
+ is_expected.to raise_error(Puppet::Error, %r{not currently supported on Debian})
+ end
+ end
+ end
+end
diff --git a/code/environments/production/modules/apt/spec/defines/setting_spec.rb b/code/environments/production/modules/apt/spec/defines/setting_spec.rb
new file mode 100644
index 0000000..1a94de7
--- /dev/null
+++ b/code/environments/production/modules/apt/spec/defines/setting_spec.rb
@@ -0,0 +1,145 @@
+require 'spec_helper'
+
+describe 'apt::setting' do
+ let(:pre_condition) { 'class { "apt": }' }
+ let :facts do
+ {
+ os: { distro: { codename: 'wheezy' }, family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
+ lsbdistrelease: '7.0',
+ lsbdistcodename: 'wheezy',
+ operatingsystem: 'Debian',
+ osfamily: 'Debian',
+ lsbdistid: 'Debian',
+ puppetversion: Puppet.version,
+ }
+ end
+ let(:title) { 'conf-teddybear' }
+
+ let(:default_params) { { content: 'di' } }
+
+ describe 'when using the defaults' do
+ context 'without source or content' do
+ it do
+ is_expected.to raise_error(Puppet::Error, %r{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].to_s)
+ }
+ 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].to_s)
+ }
+ end
+ end
+
+ describe 'settings requiring settings, MODULES-769' do
+ let(:pre_condition) do
+ 'class { "apt": }
+ apt::setting { "list-teddybear": content => "foo" }
+ '
+ end
+ let(:facts) do
+ {
+ os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
+ lsbdistid: 'Debian',
+ osfamily: 'Debian',
+ lsbdistcodename: 'wheezy',
+ puppetversion: Puppet.version,
+ }
+ end
+ 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
+ is_expected.to raise_error(Puppet::Error, %r{cannot have both })
+ end
+ end
+
+ context 'with title=ext-teddybear' do
+ let(:title) { 'ext-teddybear' }
+ let(:params) { default_params }
+
+ it do
+ is_expected.to raise_error(Puppet::Error, %r{must start with either})
+ end
+ end
+
+ context 'with ensure=banana' do
+ let(:params) { default_params.merge(ensure: 'banana') }
+
+ it do
+ is_expected.to raise_error(Puppet::Error, %r{Enum\['absent', 'file', 'present'\]})
+ end
+ end
+
+ context 'with priority=1.2' do
+ let(:params) { default_params.merge(priority: 1.2) }
+
+ if Puppet::Util::Package.versioncmp(Puppet.version, '4.0') >= 0 || ENV['FUTURE_PARSER'] == 'yes'
+ it { is_expected.to compile.and_raise_error(%r{expects a value of type}) }
+ else
+ it { is_expected.to compile.and_raise_error(%r{priority must be an integer or a zero-padded 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
diff --git a/code/environments/production/modules/apt/spec/defines/source_compat_spec.rb b/code/environments/production/modules/apt/spec/defines/source_compat_spec.rb
new file mode 100644
index 0000000..f89f4be
--- /dev/null
+++ b/code/environments/production/modules/apt/spec/defines/source_compat_spec.rb
@@ -0,0 +1,154 @@
+require 'spec_helper'
+
+describe 'apt::source', type: :define do
+ GPG_KEY_ID = '6F6B15509CF8E59E6E469F327F438280EF8D349F'.freeze
+
+ let :title do
+ 'my_source'
+ end
+
+ context 'with mostly defaults' do
+ let :facts do
+ {
+ os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
+ lsbdistid: 'Debian',
+ lsbdistcodename: 'wheezy',
+ osfamily: 'Debian',
+ puppetversion: Puppet.version,
+ }
+ end
+
+ let :params do
+ {
+ 'include' => { 'deb' => false, 'src' => true },
+ 'location' => 'http://debian.mirror.iweb.ca/debian/',
+ }
+ end
+
+ it {
+ is_expected.to contain_apt__setting('list-my_source').with_content(%r{# my_source\ndeb-src http://debian.mirror.iweb.ca/debian/ wheezy main\n})
+ }
+ end
+
+ context 'with no defaults' do
+ let :facts do
+ {
+ os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
+ lsbdistid: 'Debian',
+ lsbdistcodename: 'wheezy',
+ osfamily: 'Debian',
+ puppetversion: Puppet.version,
+ }
+ end
+ let :params do
+ {
+ 'comment' => 'foo',
+ 'location' => 'http://debian.mirror.iweb.ca/debian/',
+ 'release' => 'sid',
+ 'repos' => 'testing',
+ 'include' => { 'src' => false },
+ 'key' => GPG_KEY_ID,
+ 'pin' => '10',
+ 'architecture' => 'x86_64',
+ 'allow_unsigned' => true,
+ }
+ end
+
+ it {
+ is_expected.to contain_apt__setting('list-my_source').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 'when allow_unsigned true' do
+ let :facts do
+ {
+ os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
+ lsbdistid: 'Debian',
+ lsbdistcodename: 'wheezy',
+ osfamily: 'Debian',
+ puppetversion: Puppet.version,
+ }
+ end
+ let :params do
+ {
+ 'include' => { 'src' => false },
+ 'location' => 'http://debian.mirror.iweb.ca/debian/',
+ 'allow_unsigned' => true,
+ }
+ end
+
+ it { is_expected.to contain_apt__setting('list-my_source').with_content(%r{# my_source\ndeb \[trusted=yes\] http://debian.mirror.iweb.ca/debian/ wheezy main\n}) }
+ end
+
+ context 'with architecture equals x86_64' do
+ let :facts do
+ {
+ os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
+ lsbdistid: 'Debian',
+ lsbdistcodename: 'wheezy',
+ osfamily: 'Debian',
+ puppetversion: Puppet.version,
+ }
+ 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(%r{# my_source\ndeb \[arch=x86_64\] http://debian.mirror.iweb.ca/debian/ wheezy main\n})
+ }
+ end
+
+ context 'with ensure => absent' do
+ let :facts do
+ {
+ os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
+ 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 'with no release' do
+ let :facts do
+ {
+ os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
+ lsbdistid: 'Debian',
+ osfamily: 'Debian',
+ puppetversion: Puppet.version,
+ }
+ end
+
+ it do
+ is_expected.to raise_error(Puppet::Error, %r{lsbdistcodename fact not available: release parameter required})
+ end
+ end
+ end
+end
diff --git a/code/environments/production/modules/apt/spec/defines/source_spec.rb b/code/environments/production/modules/apt/spec/defines/source_spec.rb
new file mode 100644
index 0000000..a9077e9
--- /dev/null
+++ b/code/environments/production/modules/apt/spec/defines/source_spec.rb
@@ -0,0 +1,452 @@
+require 'spec_helper'
+
+describe 'apt::source' do
+ GPG_KEY_ID = '6F6B15509CF8E59E6E469F327F438280EF8D349F'.freeze
+
+ let :pre_condition do
+ 'class { "apt": }'
+ end
+
+ let :title do
+ 'my_source'
+ end
+
+ context 'with defaults' do
+ context 'without location' do
+ let :facts do
+ {
+ os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
+ osfamily: 'Debian',
+ lsbdistcodename: 'wheezy',
+ puppetversion: Puppet.version,
+ }
+ end
+
+ it do
+ is_expected.to raise_error(Puppet::Error, %r{source entry without specifying a location})
+ end
+ end
+ context 'with location' do
+ let :facts do
+ {
+ os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
+ 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(%r{# my_source\ndeb-src hello.there wheezy main\n})
+ }
+ end
+ end
+
+ describe 'no defaults' do
+ let :facts do
+ {
+ os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
+ lsbdistid: 'Debian',
+ lsbdistcodename: 'wheezy',
+ osfamily: 'Debian',
+ operatingsystem: 'Debian',
+ lsbdistrelease: '7.0',
+ 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(%r{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(%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: { '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(%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,
+ 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(%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
+ end
+
+ context 'with allow_unsigned true' do
+ let :facts do
+ {
+ os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
+ 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(%r{# my_source\ndeb \[trusted=yes\] hello.there wheezy main\n})
+ }
+ end
+
+ context 'with architecture equals x86_64' do
+ let :facts do
+ {
+ os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
+ 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(%r{# my_source\ndeb-src \[arch=x86_64\] hello.there wheezy main\n})
+ }
+ end
+
+ context 'with architecture fact and unset architecture parameter' do
+ let :facts do
+ {
+ architecture: 'amd64',
+ os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
+ lsbdistid: 'Debian',
+ lsbdistcodename: 'wheezy',
+ osfamily: 'Debian',
+ puppetversion: Puppet.version,
+ }
+ end
+ let :params do
+ {
+ location: 'hello.there',
+ include: { 'deb' => false, 'src' => true },
+ }
+ end
+
+ it {
+ is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# my_source\ndeb-src hello.there wheezy main\n})
+ }
+ end
+
+ context 'with include_src => true' do
+ let :facts do
+ {
+ os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
+ 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(%r{# my_source\ndeb hello.there wheezy main\ndeb-src hello.there wheezy main\n})
+ }
+ end
+
+ context 'with include deb => false' do
+ let :facts do
+ {
+ os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
+ lsbdistid: 'debian',
+ lsbdistcodename: 'wheezy',
+ osfamily: 'debian',
+ puppetversion: Puppet.version,
+ }
+ end
+ let :params do
+ {
+ include: { 'deb' => false },
+ location: 'hello.there',
+ }
+ end
+
+ it {
+ is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').without_content(%r{deb-src hello.there wheezy main\n})
+ }
+ it { is_expected.to contain_apt__setting('list-my_source').without_content(%r{deb hello.there wheezy main\n}) }
+ end
+
+ context 'with include src => true and include deb => false' do
+ let :facts do
+ {
+ os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
+ lsbdistid: 'debian',
+ lsbdistcodename: 'wheezy',
+ osfamily: 'debian',
+ puppetversion: Puppet.version,
+ }
+ end
+ let :params do
+ {
+ include: { 'deb' => false, 'src' => true },
+ location: 'hello.there',
+ }
+ end
+
+ it {
+ is_expected.to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{deb-src hello.there wheezy main\n})
+ }
+ it { is_expected.to contain_apt__setting('list-my_source').without_content(%r{deb hello.there wheezy main\n}) }
+ end
+
+ context 'with ensure => absent' do
+ let :facts do
+ {
+ os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
+ 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 'with no release' do
+ let :facts do
+ {
+ os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
+ lsbdistid: 'Debian',
+ osfamily: 'Debian',
+ puppetversion: Puppet.version,
+ }
+ end
+ let(:params) { { location: 'hello.there' } }
+
+ it do
+ is_expected.to raise_error(Puppet::Error, %r{lsbdistcodename fact not available: release parameter required})
+ end
+ end
+
+ context 'with release is empty string' do
+ let :facts do
+ {
+ os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
+ lsbdistid: 'Debian',
+ osfamily: 'Debian',
+ puppetversion: Puppet.version,
+ }
+ end
+ let(:params) { { location: 'hello.there', release: '' } }
+
+ it { is_expected.to contain_apt__setting('list-my_source').with_content(%r{hello\.there main}) }
+ end
+
+ context 'with invalid pin' do
+ let :facts do
+ {
+ os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
+ lsbdistid: 'Debian',
+ lsbdistcodename: 'wheezy',
+ osfamily: 'Debian',
+ puppetversion: Puppet.version,
+ }
+ end
+ let :params do
+ {
+ location: 'hello.there',
+ pin: true,
+ }
+ end
+
+ it do
+ is_expected.to raise_error(Puppet::Error, %r{expects a value})
+ end
+ end
+
+ context 'with notify_update = undef (default)' do
+ let :facts do
+ {
+ os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
+ lsbdistid: 'Debian',
+ lsbdistcodename: 'wheezy',
+ osfamily: 'Debian',
+ puppetversion: Puppet.version,
+ }
+ end
+ let :params do
+ {
+ location: 'hello.there',
+ }
+ end
+
+ it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(true) }
+ end
+
+ context 'with notify_update = true' do
+ let :facts do
+ {
+ os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
+ lsbdistid: 'Debian',
+ lsbdistcodename: 'wheezy',
+ osfamily: 'Debian',
+ puppetversion: Puppet.version,
+ }
+ end
+ let :params do
+ {
+ location: 'hello.there',
+ notify_update: true,
+ }
+ end
+
+ it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(true) }
+ end
+
+ context 'with notify_update = false' do
+ let :facts do
+ {
+ os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
+ lsbdistid: 'Debian',
+ lsbdistcodename: 'wheezy',
+ osfamily: 'Debian',
+ puppetversion: Puppet.version,
+ }
+ end
+ let :params do
+ {
+ location: 'hello.there',
+ notify_update: false,
+ }
+ end
+
+ it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(false) }
+ end
+ end
+end