7b7c54efc452c4744072c901bbdbb722260532ac
[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) { 'teddybear' }
7
8   let(:default_params) { { :setting_type => 'conf', :content => 'di' } }
9
10   describe 'when using the defaults' do
11     context 'without setting_type' do
12       it do
13         expect { is_expected.to compile }.to raise_error(Puppet::Error, /Must pass setting_type /)
14       end
15     end
16
17     context 'without source or content' do
18       let(:params) { { :setting_type => 'conf' } }
19       it do
20         expect { is_expected.to compile }.to raise_error(Puppet::Error, /needs either of /)
21       end
22     end
23
24     context 'with setting_type=conf' do
25       let(:params) { default_params }
26       it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear') }
27     end
28
29     context 'with setting_type=pref' do
30       let(:params) { { :setting_type => 'pref', :content => 'di' } }
31       it { is_expected.to contain_file('/etc/apt/preferences.d/50teddybear') }
32     end
33
34     context 'with setting_type=list' do
35       let(:params) { { :setting_type => 'list', :content => 'di' } }
36       it { is_expected.to contain_file('/etc/apt/sources.list.d/teddybear.list') }
37     end
38
39     context 'with source' do
40       let(:params) { { :setting_type => 'conf', :source => 'puppet:///la/die/dah' } }
41       it {
42         is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').with({
43         :ensure => 'file',
44         :owner  => 'root',
45         :group  => 'root',
46         :mode   => '0644',
47         :source => "#{params[:source]}",
48       })}
49     end
50
51     context 'with content' do
52       let(:params) { default_params }
53       it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').with({
54         :ensure  => 'file',
55         :owner   => 'root',
56         :group   => 'root',
57         :mode    => '0644',
58         :content => "#{params[:content]}",
59       })}
60     end
61   end
62
63   describe 'when trying to pull one over' do
64     context 'with source and content' do
65       let(:params) { default_params.merge({ :source => 'la' }) }
66       it do
67         expect { is_expected.to compile }.to raise_error(Puppet::Error, /cannot have both /)
68       end
69     end
70
71     context 'with setting_type=ext' do
72       let(:params) { default_params.merge({ :setting_type => 'ext' }) }
73       it do
74         expect { is_expected.to compile }.to raise_error(Puppet::Error, /"ext" does not /)
75       end
76     end
77
78     context 'with ensure=banana' do
79       let(:params) { default_params.merge({ :ensure => 'banana' }) }
80       it do
81         expect { is_expected.to compile }.to raise_error(Puppet::Error, /"banana" does not /)
82       end
83     end
84
85     context 'with priority=1.2' do
86       let(:params) { default_params.merge({ :priority => 1.2 }) }
87       it do
88         expect { is_expected.to compile }.to raise_error(Puppet::Error, /be an integer /)
89       end
90     end
91   end
92
93   describe 'with priority=100' do
94     let(:params) { default_params.merge({ :priority => 100 }) }
95     it { is_expected.to contain_file('/etc/apt/apt.conf.d/100teddybear') }
96   end
97
98   describe 'with base_name=puppy' do
99     let(:params) { default_params.merge({ :base_name => 'puppy' }) }
100     it { should contain_file('/etc/apt/apt.conf.d/50puppy') }
101   end
102
103   describe 'with base_name=true' do
104     let(:params) { default_params.merge({ :base_name => true }) }
105       it do
106         expect { should compile }.to raise_error(Puppet::Error, /not a string/)
107       end
108   end
109
110   describe 'with ensure=absent' do
111     let(:params) { default_params.merge({ :ensure => 'absent' }) }
112     it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').with({
113       :ensure => 'absent',
114     })}
115   end
116
117   describe 'with file_perms' do
118     context "{'owner' => 'roosevelt'}" do
119       let(:params) { default_params.merge({ :file_perms => {'owner' => 'roosevelt'} }) }
120       it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').with({
121         :owner => 'roosevelt',
122         :group => 'root',
123         :mode  => '0644',
124       })}
125     end
126
127     context "'group' => 'roosevelt'}" do
128       let(:params) { default_params.merge({ :file_perms => {'group' => 'roosevelt'} }) }
129       it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').with({
130         :owner => 'root',
131         :group => 'roosevelt',
132         :mode  => '0644',
133       })}
134     end
135
136     context "'owner' => 'roosevelt'}" do
137       let(:params) { default_params.merge({ :file_perms => {'mode' => '0600'} }) }
138       it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').with({
139         :owner => 'root',
140         :group => 'root',
141         :mode  => '0600',
142       })}
143     end
144   end
145 end