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