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