+ is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
+ %r{Acquire::https::proxy::proxyscope "https://proxyhost:8080/";},
+ )
+ }
+ end
+
+ context 'when host=localhost and per-host[proxyscope]=[direct]' do
+ let(:params) { { proxy: { 'host' => 'localhost', 'perhost' => [{ 'scope' => 'proxyscope', 'direct' => true }] } } }
+
+ it {
+ is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
+ %r{Acquire::http::proxy::proxyscope "DIRECT";},
+ )
+ }
+ end
+
+ context 'when host=localhost and per-host[proxyscope]=[https][direct]' do
+ let(:params) { { proxy: { 'host' => 'localhost', 'perhost' => [{ 'scope' => 'proxyscope', 'https' => true, 'direct' => true }] } } }
+
+ it {
+ is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
+ %r{Acquire::https::proxy::proxyscope "DIRECT";},
+ )
+ }
+ end
+
+ context 'when host=localhost and per-host[proxyscope]=proxyhost and per-host[proxyscope2]=proxyhost2' do
+ let(:params) { { proxy: { 'host' => 'localhost', 'perhost' => [{ 'scope' => 'proxyscope', 'host' => 'proxyhost' }, { 'scope' => 'proxyscope2', 'host' => 'proxyhost2' }] } } }
+
+ it {
+ is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
+ %r{Acquire::http::proxy::proxyscope "http://proxyhost:8080/";},
+ ).with_content(
+ %r{Acquire::http::proxy::proxyscope2 "http://proxyhost2:8080/";},
+ )
+ }
+ 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
+ end
+ context 'with 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,
+ 'apt.conf.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_file('apt.conf.d').with(purge: false,
+ recurse: false)
+ }
+
+ it {
+ is_expected.to contain_exec('apt_update').with(refreshonly: false,
+ timeout: 1,
+ tries: 3)
+ }
+ end
+
+ context 'with lots of non-defaults' 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 {
+ is_expected.to contain_file('sources.list').with(content: "# Repos managed by puppet.\n")
+ }
+
+ it {
+ is_expected.to contain_file('sources.list.d').with(purge: true,
+ recurse: true)
+ }
+
+ it {
+ is_expected.to contain_file('preferences').with(ensure: 'absent')
+ }
+
+ it {
+ is_expected.to contain_file('preferences.d').with(purge: true,
+ recurse: true)
+ }
+
+ it {
+ is_expected.to contain_file('apt.conf.d').with(purge: true,
+ recurse: true)
+ }
+
+ it {
+ is_expected.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 {
+ is_expected.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,