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