Cleanup for `apt::source`
[puppet-modules/puppetlabs-apt.git] / spec / defines / source_spec.rb
1 require 'spec_helper'
2
3 describe 'apt::source', :type => :define 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_file('my_source.list').that_notifies('Exec[apt_update]').with({
31       'ensure' => 'present',
32       'path'   => '/etc/apt/sources.list.d/my_source.list',
33       'owner'  => 'root',
34       'group'  => 'root',
35       'mode'   => '0644',
36     }).with_content(/# my_source\ndeb-src  wheezy main\n/)
37     }
38   end
39
40   context 'no defaults' do
41     let :facts do
42       {
43         :lsbdistid       => 'Debian',
44         :lsbdistcodename => 'wheezy',
45         :osfamily        => 'Debian'
46       }
47     end
48     let :params do
49       {
50         'comment'           => 'foo',
51         'location'          => 'http://debian.mirror.iweb.ca/debian/',
52         'release'           => 'sid',
53         'repos'             => 'testing',
54         'include_src'       => false,
55         'key'               => GPG_KEY_ID,
56         'key_server'        => 'pgp.mit.edu',
57         'key_content'       => 'GPG key content',
58         'key_source'        => 'http://apt.puppetlabs.com/pubkey.gpg',
59         'pin'               => '10',
60         'architecture'      => 'x86_64',
61         'trusted_source'    => true,
62       }
63     end
64
65     it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({
66       'ensure' => 'present',
67       'path'   => '/etc/apt/sources.list.d/my_source.list',
68       'owner'  => 'root',
69       'group'  => 'root',
70       'mode'   => '0644',
71     }).with_content(/# foo\ndeb \[arch=x86_64 trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(/deb-src/)
72     }
73
74     it { is_expected.to contain_apt__pin('my_source').that_comes_before('File[my_source.list]').with({
75       'ensure'   => 'present',
76       'priority' => '10',
77       'origin'   => 'debian.mirror.iweb.ca',
78     })
79     }
80
81     it { is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('File[my_source.list]').with({
82       'ensure' => 'present',
83         'key'  => GPG_KEY_ID,
84         'key_server' => 'pgp.mit.edu',
85         'key_content' => 'GPG key content',
86         'key_source' => 'http://apt.puppetlabs.com/pubkey.gpg',
87     })
88     }
89   end
90
91   context 'trusted_source true' do
92     let :facts do
93       {
94         :lsbdistid       => 'Debian',
95         :lsbdistcodename => 'wheezy',
96         :osfamily        => 'Debian'
97       }
98     end
99     let :params do
100       {
101         'include_src'    => false,
102         'trusted_source' => true,
103       }
104     end
105
106     it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({
107       'ensure' => 'present',
108       'path'   => '/etc/apt/sources.list.d/my_source.list',
109       'owner'  => 'root',
110       'group'  => 'root',
111       'mode'   => '0644',
112     }).with_content(/# my_source\ndeb \[trusted=yes\]  wheezy main\n/)
113     }
114   end
115
116   context 'architecture equals x86_64' do
117     let :facts do
118       {
119         :lsbdistid       => 'Debian',
120         :lsbdistcodename => 'wheezy',
121         :osfamily        => 'Debian'
122       }
123     end
124     let :params do
125       {
126         'include_deb'  => false,
127         'include_src'  => true,
128         'architecture' => 'x86_64',
129       }
130     end
131
132     it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({
133       'ensure' => 'present',
134       'path'   => '/etc/apt/sources.list.d/my_source.list',
135       'owner'  => 'root',
136       'group'  => 'root',
137       'mode'   => '0644',
138     }).with_content(/# my_source\ndeb-src \[arch=x86_64 \]  wheezy main\n/)
139     }
140   end
141  
142   context 'ensure => absent' do
143     let :facts do
144       {
145         :lsbdistid       => 'Debian',
146         :lsbdistcodename => 'wheezy',
147         :osfamily        => 'Debian'
148       }
149     end
150     let :params do
151       {
152         'ensure' => 'absent',
153       }
154     end
155
156     it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({
157       'ensure' => 'absent'
158     })
159     }
160   end
161
162   describe 'validation' do
163     context 'no release' do
164       let :facts do
165         {
166           :lsbdistid       => 'Debian',
167           :osfamily        => 'Debian'
168         }
169       end
170
171       it do
172         expect {
173           should compile
174         }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/)
175       end
176     end
177   end
178 end