| 1 | require 'spec_helper'
|
|---|
| 2 |
|
|---|
| 3 | describe 'apt::setting' do
|
|---|
| 4 | let(:pre_condition) { 'class { "apt": }' }
|
|---|
| 5 | let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :puppetversion => Puppet.version, } }
|
|---|
| 6 | let(:title) { 'conf-teddybear' }
|
|---|
| 7 |
|
|---|
| 8 | let(:default_params) { { :content => 'di' } }
|
|---|
| 9 |
|
|---|
| 10 | describe 'when using the defaults' do
|
|---|
| 11 | context 'without source or content' do
|
|---|
| 12 | it do
|
|---|
| 13 | expect { subject.call }.to raise_error(Puppet::Error, /needs either of /)
|
|---|
| 14 | end
|
|---|
| 15 | end
|
|---|
| 16 |
|
|---|
| 17 | context 'with title=conf-teddybear ' do
|
|---|
| 18 | let(:params) { default_params }
|
|---|
| 19 | it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Class[Apt::Update]') }
|
|---|
| 20 | end
|
|---|
| 21 |
|
|---|
| 22 | context 'with title=pref-teddybear' do
|
|---|
| 23 | let(:title) { 'pref-teddybear' }
|
|---|
| 24 | let(:params) { default_params }
|
|---|
| 25 | it { is_expected.to contain_file('/etc/apt/preferences.d/teddybear.pref').that_notifies('Class[Apt::Update]') }
|
|---|
| 26 | end
|
|---|
| 27 |
|
|---|
| 28 | context 'with title=list-teddybear' do
|
|---|
| 29 | let(:title) { 'list-teddybear' }
|
|---|
| 30 | let(:params) { default_params }
|
|---|
| 31 | it { is_expected.to contain_file('/etc/apt/sources.list.d/teddybear.list').that_notifies('Class[Apt::Update]') }
|
|---|
| 32 | end
|
|---|
| 33 |
|
|---|
| 34 | context 'with source' do
|
|---|
| 35 | let(:params) { { :source => 'puppet:///la/die/dah' } }
|
|---|
| 36 | it {
|
|---|
| 37 | is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Class[Apt::Update]').with({
|
|---|
| 38 | :ensure => 'file',
|
|---|
| 39 | :owner => 'root',
|
|---|
| 40 | :group => 'root',
|
|---|
| 41 | :mode => '0644',
|
|---|
| 42 | :source => "#{params[:source]}",
|
|---|
| 43 | })}
|
|---|
| 44 | end
|
|---|
| 45 |
|
|---|
| 46 | context 'with content' do
|
|---|
| 47 | let(:params) { default_params }
|
|---|
| 48 | it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Class[Apt::Update]').with({
|
|---|
| 49 | :ensure => 'file',
|
|---|
| 50 | :owner => 'root',
|
|---|
| 51 | :group => 'root',
|
|---|
| 52 | :mode => '0644',
|
|---|
| 53 | :content => "#{params[:content]}",
|
|---|
| 54 | })}
|
|---|
| 55 | end
|
|---|
| 56 | end
|
|---|
| 57 |
|
|---|
| 58 | describe 'settings requiring settings, MODULES-769' do
|
|---|
| 59 | let(:pre_condition) do
|
|---|
| 60 | 'class { "apt": }
|
|---|
| 61 | apt::setting { "list-teddybear": content => "foo" }
|
|---|
| 62 | '
|
|---|
| 63 | end
|
|---|
| 64 | let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :puppetversion => Puppet.version, } }
|
|---|
| 65 | let(:title) { 'conf-teddybear' }
|
|---|
| 66 | let(:default_params) { { :content => 'di' } }
|
|---|
| 67 |
|
|---|
| 68 | let(:params) { default_params.merge({ :require => 'Apt::Setting[list-teddybear]' }) }
|
|---|
| 69 |
|
|---|
| 70 | it { is_expected.to compile.with_all_deps }
|
|---|
| 71 | end
|
|---|
| 72 |
|
|---|
| 73 | describe 'when trying to pull one over' do
|
|---|
| 74 | context 'with source and content' do
|
|---|
| 75 | let(:params) { default_params.merge({ :source => 'la' }) }
|
|---|
| 76 | it do
|
|---|
| 77 | expect { subject.call }.to raise_error(Puppet::Error, /cannot have both /)
|
|---|
| 78 | end
|
|---|
| 79 | end
|
|---|
| 80 |
|
|---|
| 81 | context 'with title=ext-teddybear' do
|
|---|
| 82 | let(:title) { 'ext-teddybear' }
|
|---|
| 83 | let(:params) { default_params }
|
|---|
| 84 | it do
|
|---|
| 85 | expect { subject.call }.to raise_error(Puppet::Error, /must start with /)
|
|---|
| 86 | end
|
|---|
| 87 | end
|
|---|
| 88 |
|
|---|
| 89 | context 'with ensure=banana' do
|
|---|
| 90 | let(:params) { default_params.merge({ :ensure => 'banana' }) }
|
|---|
| 91 | it do
|
|---|
| 92 | expect { subject.call }.to raise_error(Puppet::Error, /"banana" does not /)
|
|---|
| 93 | end
|
|---|
| 94 | end
|
|---|
| 95 |
|
|---|
| 96 | context 'with priority=1.2' do
|
|---|
| 97 | let(:params) { default_params.merge({ :priority => 1.2 }) }
|
|---|
| 98 | it do
|
|---|
| 99 | expect { subject.call }.to raise_error(Puppet::Error, /be an integer /)
|
|---|
| 100 | end
|
|---|
| 101 | end
|
|---|
| 102 | end
|
|---|
| 103 |
|
|---|
| 104 | describe 'with priority=100' do
|
|---|
| 105 | let(:params) { default_params.merge({ :priority => 100 }) }
|
|---|
| 106 | it { is_expected.to contain_file('/etc/apt/apt.conf.d/100teddybear').that_notifies('Class[Apt::Update]') }
|
|---|
| 107 | end
|
|---|
| 108 |
|
|---|
| 109 | describe 'with ensure=absent' do
|
|---|
| 110 | let(:params) { default_params.merge({ :ensure => 'absent' }) }
|
|---|
| 111 | it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Class[Apt::Update]').with({
|
|---|
| 112 | :ensure => 'absent',
|
|---|
| 113 | })}
|
|---|
| 114 | end
|
|---|
| 115 | end
|
|---|