+ expect(subject).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 {
+ expect(subject).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 {
+ expect(subject).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 {
+ expect(subject).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 {
+ expect(subject).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 {
+ expect(subject).to contain_apt__setting('conf-proxy').with(ensure: 'absent',
+ priority: '01')
+ }
+ end
+ end
+
+ context 'with lots of non-defaults - one' do
+ let :params do
+ {
+ update: { 'frequency' => 'always', 'timeout' => 1, 'tries' => 3 },
+ purge: { 'sources.list' => false, 'sources.list.d' => false,
+ 'preferences' => false, 'preferences.d' => false,
+ 'apt.conf.d' => false }
+ }
+ end
+
+ it {
+ expect(subject).to contain_file('sources.list').with(content: nil)
+ }
+
+ it {
+ expect(subject).to contain_file('sources.list.d').with(purge: false,
+ recurse: false)
+ }
+
+ it {
+ expect(subject).to contain_file('preferences').with(ensure: 'file')
+ }
+
+ it {
+ expect(subject).to contain_file('preferences.d').with(purge: false,
+ recurse: false)
+ }
+
+ it {
+ expect(subject).to contain_file('apt.conf.d').with(purge: false,
+ recurse: false)
+ }
+
+ it {
+ expect(subject).to contain_exec('apt_update').with(refreshonly: false,
+ timeout: 1,
+ tries: 3)
+ }
+ end
+
+ context 'with lots of non-defaults - two' do
+ let :params do
+ {
+ update: { 'frequency' => 'always', 'timeout' => 1, 'tries' => 3 },
+ purge: { 'sources.list' => true, 'sources.list.d' => true,
+ 'preferences' => true, 'preferences.d' => true,
+ 'apt.conf.d' => true }
+ }
+ end
+
+ it {
+ expect(subject).to contain_file('sources.list').with(content: "# Repos managed by puppet.\n")
+ }
+
+ it {
+ expect(subject).to contain_file('sources.list.d').with(purge: true,
+ recurse: true)
+ }
+
+ it {
+ expect(subject).to contain_file('preferences').with(ensure: 'absent')
+ }
+
+ it {
+ expect(subject).to contain_file('preferences.d').with(purge: true,
+ recurse: true)
+ }
+
+ it {
+ expect(subject).to contain_file('apt.conf.d').with(purge: true,
+ recurse: true)
+ }
+
+ it {
+ expect(subject).to contain_exec('apt_update').with(refreshonly: false,
+ timeout: 1,
+ tries: 3)
+ }
+ end
+
+ context 'with defaults for sources_list_force' do
+ let :params do
+ {
+ update: { 'frequency' => 'always', 'timeout' => 1, 'tries' => 3 },
+ purge: { 'sources.list' => true },
+ sources_list_force: false
+ }
+ end
+
+ it {
+ expect(subject).to contain_file('sources.list').with(content: "# Repos managed by puppet.\n")
+ }
+ end
+
+ context 'with non defaults for sources_list_force' do
+ let :params do
+ {
+ update: { 'frequency' => 'always', 'timeout' => 1, 'tries' => 3 },
+ purge: { 'sources.list' => true },
+ sources_list_force: true
+ }
+ end
+
+ it {
+ expect(subject).to contain_file('sources.list').with(ensure: 'absent')
+ }
+ end
+
+ context 'with entries for /etc/apt/auth.conf' do
+ facts_hash = {
+ 'Ubuntu 18.04' => {
+ os: {
+ family: 'Debian',
+ name: 'Ubuntu',
+ release: {
+ major: '18',
+ full: '18.04'
+ },
+ distro: {
+ codename: 'bionic',
+ id: 'Ubuntu'
+ }
+ }
+ },
+ 'Debian 9.0' => {
+ os: {
+ family: 'Debian',
+ name: 'Debian',
+ release: {
+ major: '9',
+ full: '9.0'
+ },
+ distro: {
+ codename: 'stretch',
+ id: 'Debian'
+ }
+ }
+ },
+ 'Debian 10.0' => {
+ os: {
+ family: 'Debian',
+ name: 'Debian',
+ release: {
+ major: '10',
+ full: '10.0'
+ },
+ distro: {
+ codename: 'buster',
+ id: 'Debian'
+ }
+ }