apt::setting: Remove file_perms.
[puppet-modules/puppetlabs-apt.git] / spec / defines / setting_spec.rb
1 require 'spec_helper'
2
3 describe 'apt::setting' do
4   let(:pre_condition) { 'class { "apt": }' }
5   let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
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 { is_expected.to compile }.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('Exec[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/50teddybear').that_notifies('Exec[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('Exec[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('Exec[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('Exec[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 'when trying to pull one over' do
59     context 'with source and content' do
60       let(:params) { default_params.merge({ :source => 'la' }) }
61       it do
62         expect { is_expected.to compile }.to raise_error(Puppet::Error, /cannot have both /)
63       end
64     end
65
66     context 'with title=ext-teddybear' do
67       let(:title) { 'ext-teddybear' }
68       let(:params) { default_params }
69       it do
70         expect { is_expected.to compile }.to raise_error(Puppet::Error, /must start with /)
71       end
72     end
73
74     context 'with ensure=banana' do
75       let(:params) { default_params.merge({ :ensure => 'banana' }) }
76       it do
77         expect { is_expected.to compile }.to raise_error(Puppet::Error, /"banana" does not /)
78       end
79     end
80
81     context 'with priority=1.2' do
82       let(:params) { default_params.merge({ :priority => 1.2 }) }
83       it do
84         expect { is_expected.to compile }.to raise_error(Puppet::Error, /be an integer /)
85       end
86     end
87   end
88
89   describe 'with priority=100' do
90     let(:params) { default_params.merge({ :priority => 100 }) }
91     it { is_expected.to contain_file('/etc/apt/apt.conf.d/100teddybear').that_notifies('Exec[apt_update]') }
92   end
93
94   describe 'with ensure=absent' do
95     let(:params) { default_params.merge({ :ensure => 'absent' }) }
96     it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Exec[apt_update]').with({
97       :ensure => 'absent',
98     })}
99   end
100 end