apt::key: Rename $key to $id to match apt_key.
[puppet-modules/puppetlabs-apt.git] / spec / defines / source_spec.rb
1 require 'spec_helper'
2
3 describe 'apt::source' do
4   GPG_KEY_ID = '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30'
5
6   let :pre_condition do
7     'class { "apt": }'
8   end
9
10   let :title do
11     'my_source'
12   end
13
14   context 'mostly defaults' do
15     let :facts do
16       {
17         :lsbdistid       => 'Debian',
18         :lsbdistcodename => 'wheezy',
19         :osfamily        => 'Debian'
20       }
21     end
22
23     let :params do
24       {
25         :include_deb => false,
26         :include_src => true,
27       }
28     end
29
30     it { is_expected.to contain_apt__setting('list-my_source').with({
31       :ensure => 'present',
32     }).with_content(/# my_source\ndeb-src  wheezy main\n/)
33
34     }
35   end
36
37   describe 'no defaults' do
38     let :facts do
39       {
40         :lsbdistid       => 'Debian',
41         :lsbdistcodename => 'wheezy',
42         :osfamily        => 'Debian'
43       }
44     end
45     context 'with simple key' do
46       let :params do
47         {
48           :comment           => 'foo',
49           :location          => 'http://debian.mirror.iweb.ca/debian/',
50           :release           => 'sid',
51           :repos             => 'testing',
52           :include_src       => false,
53           :key               => GPG_KEY_ID,
54           :pin               => '10',
55           :architecture      => 'x86_64',
56           :trusted_source    => true,
57         }
58       end
59
60       it { is_expected.to contain_apt__setting('list-my_source').with({
61         :ensure => 'present',
62       }).with_content(/# foo\ndeb \[arch=x86_64 trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(/deb-src/)
63       }
64
65       it { is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with({
66         :ensure   => 'present',
67         :priority => '10',
68         :origin   => 'debian.mirror.iweb.ca',
69       })
70       }
71
72       it { is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('Apt::Setting[list-my_source]').with({
73         :ensure  => 'present',
74         :id      => GPG_KEY_ID,
75       })
76       }
77     end
78
79     context 'with complex key' do
80       let :params do
81         {
82           :comment           => 'foo',
83           :location          => 'http://debian.mirror.iweb.ca/debian/',
84           :release           => 'sid',
85           :repos             => 'testing',
86           :include_src       => false,
87           :key               => { 'id' => GPG_KEY_ID, 'server' => 'pgp.mit.edu',
88                                   'content' => 'GPG key content',
89                                   'source'  => 'http://apt.puppetlabs.com/pubkey.gpg',},
90           :pin               => '10',
91           :architecture      => 'x86_64',
92           :trusted_source    => true,
93         }
94       end
95
96       it { is_expected.to contain_apt__setting('list-my_source').with({
97         :ensure => 'present',
98       }).with_content(/# foo\ndeb \[arch=x86_64 trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(/deb-src/)
99       }
100
101       it { is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with({
102         :ensure   => 'present',
103         :priority => '10',
104         :origin   => 'debian.mirror.iweb.ca',
105       })
106       }
107
108       it { is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('Apt::Setting[list-my_source]').with({
109         :ensure  => 'present',
110         :id      => GPG_KEY_ID,
111         :server  => 'pgp.mit.edu',
112         :content => 'GPG key content',
113         :source  => 'http://apt.puppetlabs.com/pubkey.gpg',
114       })
115       }
116     end
117
118     context 'with simple key' do
119       let :params do
120         {
121           :comment        => 'foo',
122           :location       => 'http://debian.mirror.iweb.ca/debian/',
123           :release        => 'sid',
124           :repos          => 'testing',
125           :include_src    => false,
126           :key            => GPG_KEY_ID,
127           :pin            => '10',
128           :architecture   => 'x86_64',
129           :trusted_source => true,
130         }
131       end
132
133       it { is_expected.to contain_apt__setting('list-my_source').with({
134         :ensure => 'present',
135       }).with_content(/# foo\ndeb \[arch=x86_64 trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(/deb-src/)
136       }
137
138       it { is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with({
139         :ensure   => 'present',
140         :priority => '10',
141         :origin   => 'debian.mirror.iweb.ca',
142       })
143       }
144
145       it { is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('Apt::Setting[list-my_source]').with({
146         :ensure  => 'present',
147         :id      => GPG_KEY_ID,
148       })
149       }
150     end
151   end
152
153   context 'trusted_source true' do
154     let :facts do
155       {
156         :lsbdistid       => 'Debian',
157         :lsbdistcodename => 'wheezy',
158         :osfamily        => 'Debian'
159       }
160     end
161     let :params do
162       {
163         :include_src    => false,
164         :trusted_source => true,
165       }
166     end
167
168     it { is_expected.to contain_apt__setting('list-my_source').with({
169       :ensure => 'present',
170     }).with_content(/# my_source\ndeb \[trusted=yes\]  wheezy main\n/)
171     }
172   end
173
174   context 'architecture equals x86_64' do
175     let :facts do
176       {
177         :lsbdistid       => 'Debian',
178         :lsbdistcodename => 'wheezy',
179         :osfamily        => 'Debian'
180       }
181     end
182     let :params do
183       {
184         :include_deb  => false,
185         :include_src  => true,
186         :architecture => 'x86_64',
187       }
188     end
189
190     it { is_expected.to contain_apt__setting('list-my_source').with({
191       :ensure => 'present',
192     }).with_content(/# my_source\ndeb-src \[arch=x86_64 \]  wheezy main\n/)
193     }
194   end
195
196   context 'ensure => absent' do
197     let :facts do
198       {
199         :lsbdistid       => 'Debian',
200         :lsbdistcodename => 'wheezy',
201         :osfamily        => 'Debian'
202       }
203     end
204     let :params do
205       {
206         :ensure => 'absent',
207       }
208     end
209
210     it { is_expected.to contain_apt__setting('list-my_source').with({
211       :ensure => 'absent'
212     })
213     }
214   end
215
216   describe 'validation' do
217     context 'no release' do
218       let :facts do
219         {
220           :lsbdistid       => 'Debian',
221           :osfamily        => 'Debian'
222         }
223       end
224
225       it do
226         expect {
227           is_expected.to compile
228         }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/)
229       end
230     end
231   end
232 end