X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=spec%2Fclasses%2Fapt_spec.rb;h=03b638ca7fbd1406ae1888578d8c2317d58e3738;hb=6cb996e8b5294d48de7dd455127104574950ba57;hp=03ca86f52f6c3d4e7f974531907829d48269c230;hpb=2e8b93fc83efbf0a6d3c7b8106cc0b54bb249827;p=puppet-modules%2Fpuppetlabs-apt.git diff --git a/spec/classes/apt_spec.rb b/spec/classes/apt_spec.rb index 03ca86f..03b638c 100644 --- a/spec/classes/apt_spec.rb +++ b/spec/classes/apt_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' sources_list = { ensure: 'file', @@ -39,10 +41,18 @@ apt_conf_d = { ensure: 'directory', describe 'apt' do let(:facts) do { - os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } }, - lsbdistid: 'Debian', - osfamily: 'Debian', - lsbdistcodename: 'jessie', + os: { + family: 'Debian', + name: 'Debian', + release: { + major: '8', + full: '8.0', + }, + distro: { + codename: 'jessie', + id: 'Debian', + }, + }, } end @@ -91,7 +101,69 @@ describe 'apt' do 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}, + %r{Acquire::https::proxy }, + ) + } + end + + context 'when host=localhost and per-host[proxyscope]=proxyhost' do + let(:params) { { proxy: { 'host' => 'localhost', 'perhost' => [{ 'scope' => 'proxyscope', 'host' => 'proxyhost' }] } } } + + it { + is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content( + %r{Acquire::http::proxy::proxyscope "http://proxyhost:8080/";}, + ) + } + end + + context 'when host=localhost and per-host[proxyscope]=proxyhost:8081' do + let(:params) { { proxy: { 'host' => 'localhost', 'perhost' => [{ 'scope' => 'proxyscope', 'host' => 'proxyhost', 'port' => 8081 }] } } } + + it { + is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content( + %r{Acquire::http::proxy::proxyscope "http://proxyhost:8081/";}, + ) + } + end + + context 'when host=localhost and per-host[proxyscope]=[https]proxyhost' do + let(:params) { { proxy: { 'host' => 'localhost', 'perhost' => [{ 'scope' => 'proxyscope', 'host' => 'proxyhost', 'https' => true }] } } } + + it { + 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 @@ -103,7 +175,7 @@ describe 'apt' do 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}, + %r{Acquire::https::proxy }, ) } end @@ -271,49 +343,102 @@ describe 'apt' do context 'with entries for /etc/apt/auth.conf' do facts_hash = { 'Ubuntu 14.04' => { - os: { family: 'Debian', name: 'Ubuntu', release: { major: '14', full: '14.04' } }, - osfamily: 'Debian', - lsbdistcodename: 'trusty', - lsbdistid: 'Ubuntu', - lsbdistrelease: '14.04', + os: { + family: 'Debian', + name: 'Ubuntu', + release: { + major: '14', + full: '14.04', + }, + distro: { + codename: 'trusty', + id: 'Ubuntu', + }, + }, }, 'Ubuntu 16.04' => { - os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } }, - osfamily: 'Debian', - lsbdistcodename: 'xenial', - lsbdistid: 'Ubuntu', - lsbdistrelease: '16.04', + os: { + family: 'Debian', + name: 'Ubuntu', + release: { + major: '16', + full: '16.04', + }, + distro: { + codename: 'xenial', + id: 'Ubuntu', + }, + }, }, 'Ubuntu 18.04' => { - os: { family: 'Debian', name: 'Ubuntu', release: { major: '18', full: '18.04' } }, - osfamily: 'Debian', - lsbdistcodename: 'bionic', - lsbdistid: 'Ubuntu', - lsbdistrelease: '18.04', + os: { + family: 'Debian', + name: 'Ubuntu', + release: { + major: '18', + full: '18.04', + }, + distro: { + codename: 'bionic', + id: 'Ubuntu', + }, + }, }, 'Debian 7.0' => { - os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, - lsbdistid: 'Debian', - osfamily: 'Debian', - lsbdistcodename: 'wheezy', + os: { + family: 'Debian', + name: 'Debian', + release: { + major: '7', + full: '7.0', + }, + distro: { + codename: 'wheezy', + id: 'Debian', + }, + }, }, 'Debian 8.0' => { - os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } }, - lsbdistid: 'Debian', - osfamily: 'Debian', - lsbdistcodename: 'jessie', + os: { + family: 'Debian', + name: 'Debian', + release: { + major: '8', + full: '8.0', + }, + distro: { + codename: 'jessie', + id: 'Debian', + }, + }, }, 'Debian 9.0' => { - os: { family: 'Debian', name: 'Debian', release: { major: '9', full: '9.0' } }, - lsbdistid: 'Debian', - osfamily: 'Debian', - lsbdistcodename: 'stretch', + 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' } }, - lsbdistid: 'Debian', - osfamily: 'Debian', - lsbdistcodename: 'buster', + os: { + family: 'Debian', + name: 'Debian', + release: { + major: '10', + full: '10.0', + }, + distro: { + codename: 'buster', + id: 'Debian', + }, + }, }, } @@ -403,14 +528,21 @@ machine apt.example.com login aptlogin password supersecret end end - context 'with sources defined on valid osfamily' do + context 'with sources defined on valid os.family' do let :facts do { - os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } }, - osfamily: 'Debian', - lsbdistcodename: 'xenial', - lsbdistid: 'Ubuntu', - lsbdistrelease: '16.04', + os: { + family: 'Debian', + name: 'Ubuntu', + release: { + major: '16', + full: '16.04', + }, + distro: { + codename: 'xenial', + id: 'Ubuntu', + }, + }, } end let(:params) do @@ -445,13 +577,21 @@ machine apt.example.com login aptlogin password supersecret it { is_expected.to contain_file('/etc/apt/sources.list.d/puppetlabs.list').with_content(%r{^deb http://apt.puppetlabs.com xenial main$}) } end - context 'with confs defined on valid osfamily' do + context 'with confs defined on valid os.family' do let :facts do { - os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } }, - osfamily: 'Debian', - lsbdistcodename: 'xenial', - lsbdistid: 'Ubuntu', + os: { + family: 'Debian', + name: 'Ubuntu', + release: { + major: '16', + full: '16.04', + }, + distro: { + codename: 'xenial', + id: 'Ubuntu', + }, + }, } end let(:params) do @@ -474,13 +614,21 @@ machine apt.example.com login aptlogin password supersecret } end - context 'with keys defined on valid osfamily' do + context 'with keys defined on valid os.family' do let :facts do { - os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } }, - osfamily: 'Debian', - lsbdistcodename: 'xenial', - lsbdistid: 'Ubuntu', + os: { + family: 'Debian', + name: 'Ubuntu', + release: { + major: '16', + full: '16.04', + }, + distro: { + codename: 'xenial', + id: 'Ubuntu', + }, + }, } end let(:params) do @@ -503,14 +651,21 @@ machine apt.example.com login aptlogin password supersecret } end - context 'with ppas defined on valid osfamily' do + context 'with ppas defined on valid os.family' do let :facts do { - os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } }, - osfamily: 'Debian', - lsbdistcodename: 'xenial', - lsbdistid: 'Ubuntu', - lsbdistrelease: '16.04', + os: { + family: 'Debian', + name: 'Ubuntu', + release: { + major: '16', + full: '16.04', + }, + distro: { + codename: 'xenial', + id: 'Ubuntu', + }, + }, } end let(:params) do @@ -524,13 +679,21 @@ machine apt.example.com login aptlogin password supersecret it { is_expected.to contain_apt__ppa('ppa:nginx/stable') } end - context 'with settings defined on valid osfamily' do + context 'with settings defined on valid os.family' do let :facts do { - os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } }, - osfamily: 'Debian', - lsbdistcodename: 'xenial', - lsbdistid: 'Ubuntu', + os: { + family: 'Debian', + name: 'Ubuntu', + release: { + major: '16', + full: '16.04', + }, + distro: { + codename: 'xenial', + id: 'Ubuntu', + }, + }, } end let(:params) do @@ -544,13 +707,21 @@ machine apt.example.com login aptlogin password supersecret it { is_expected.to contain_apt__setting('pref-banana') } end - context 'with pins defined on valid osfamily' do + context 'with pins defined on valid os.family' do let :facts do { - os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } }, - osfamily: 'Debian', - lsbdistcodename: 'xenial', - lsbdistid: 'Ubuntu', + os: { + family: 'Debian', + name: 'Ubuntu', + release: { + major: '16', + full: '16.04', + }, + distro: { + codename: 'xenial', + id: 'Ubuntu', + }, + }, } end let(:params) do