-describe 'apt', :type => :class do
- let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
-
- context 'defaults' do
- it { is_expected.to contain_file('sources.list').that_notifies('Exec[apt_update]').only_with({
- 'ensure' => 'present',
- 'path' => '/etc/apt/sources.list',
- 'owner' => 'root',
- 'group' => 'root',
- 'mode' => '0644',
- 'notify' => 'Exec[apt_update]',
- })}
-
- it { is_expected.to contain_file('sources.list.d').that_notifies('Exec[apt_update]').only_with({
- 'ensure' => 'directory',
- 'path' => '/etc/apt/sources.list.d',
- 'owner' => 'root',
- 'group' => 'root',
- 'purge' => false,
- 'recurse' => false,
- 'notify' => 'Exec[apt_update]',
- })}
-
- it { is_expected.to contain_file('preferences.d').only_with({
- 'ensure' => 'directory',
- 'path' => '/etc/apt/preferences.d',
- 'owner' => 'root',
- 'group' => 'root',
- 'purge' => false,
- 'recurse' => false,
- })}
-
- 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',
- })}
+
+sources_list = { ensure: 'file',
+ path: '/etc/apt/sources.list',
+ owner: 'root',
+ group: 'root',
+ notify: 'Class[Apt::Update]' }
+
+sources_list_d = { ensure: 'directory',
+ path: '/etc/apt/sources.list.d',
+ owner: 'root',
+ group: 'root',
+ purge: false,
+ recurse: false,
+ notify: 'Class[Apt::Update]' }
+
+preferences = { ensure: 'file',
+ path: '/etc/apt/preferences',
+ owner: 'root',
+ group: 'root',
+ notify: 'Class[Apt::Update]' }
+
+preferences_d = { ensure: 'directory',
+ path: '/etc/apt/preferences.d',
+ owner: 'root',
+ group: 'root',
+ purge: false,
+ recurse: false,
+ notify: 'Class[Apt::Update]' }
+
+apt_conf_d = { ensure: 'directory',
+ path: '/etc/apt/apt.conf.d',
+ owner: 'root',
+ group: 'root',
+ purge: false,
+ recurse: false,
+ notify: 'Class[Apt::Update]' }
+
+describe 'apt' do
+ let(:facts) do
+ {
+ os: {
+ family: 'Debian',
+ name: 'Debian',
+ release: {
+ major: '8',
+ full: '8.0',
+ },
+ distro: {
+ codename: 'jessie',
+ id: 'Debian',
+ },
+ },
+ }
+ end
+
+ context 'with defaults' do
+ it {
+ is_expected.to contain_file('sources.list').that_notifies('Class[Apt::Update]').only_with(sources_list)
+ }
+
+ it {
+ is_expected.to contain_file('sources.list.d').that_notifies('Class[Apt::Update]').only_with(sources_list_d)
+ }
+
+ it {
+ is_expected.to contain_file('preferences').that_notifies('Class[Apt::Update]').only_with(preferences)
+ }
+
+ it {
+ is_expected.to contain_file('preferences.d').that_notifies('Class[Apt::Update]').only_with(preferences_d)
+ }
+
+ it {
+ is_expected.to contain_file('apt.conf.d').that_notifies('Class[Apt::Update]').only_with(apt_conf_d)
+ }
+
+ it { is_expected.to contain_file('/etc/apt/auth.conf').with_ensure('absent') }
+
+ it 'lays down /etc/apt/apt.conf.d/15update-stamp' do
+ is_expected.to contain_file('/etc/apt/apt.conf.d/15update-stamp').with(group: 'root',
+ owner: 'root').with_content(
+ %r{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 'when host=localhost' do
+ let(:params) { { proxy: { 'host' => 'localhost' } } }
+
+ it {
+ is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
+ %r{Acquire::http::proxy "http://localhost:8080/";},
+ ).without_content(
+ %r{Acquire::https::proxy},
+ )
+ }
+ end
+
+ context 'when 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(
+ %r{Acquire::http::proxy "http://localhost:8180/";},
+ ).without_content(
+ %r{Acquire::https::proxy},
+ )
+ }
+ end
+
+ context 'when 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(
+ %r{Acquire::http::proxy "http://localhost:8080/";},
+ ).with_content(
+ %r{Acquire::https::proxy "https://localhost:8080/";},
+ )
+ }
+ end
+
+ context 'when host=localhost and direct=true' do
+ let(:params) { { proxy: { 'host' => 'localhost', 'direct' => true } } }
+
+ it {
+ is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
+ %r{Acquire::http::proxy "http://localhost:8080/";},
+ ).with_content(
+ %r{Acquire::https::proxy "DIRECT";},
+ )
+ }
+ end
+
+ context 'when host=localhost and https=true and direct=true' do
+ let(:params) { { proxy: { 'host' => 'localhost', 'https' => true, 'direct' => true } } }
+
+ it {
+ is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
+ %r{Acquire::http::proxy "http://localhost:8080/";},
+ ).with_content(
+ %r{Acquire::https::proxy "https://localhost:8080/";},
+ )
+ }
+ it {
+ is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
+ %r{Acquire::http::proxy "http://localhost:8080/";},
+ ).without_content(
+ %r{Acquire::https::proxy "DIRECT";},
+ )
+ }
+ end
+
+ context 'when ensure=absent' do
+ let(:params) { { proxy: { 'ensure' => 'absent' } } }
+
+ it {
+ is_expected.to contain_apt__setting('conf-proxy').with(ensure: 'absent',
+ priority: '01')
+ }
+ end