(MODULES-1200) Fix inconsistent header across files
[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
7   let :title do
8     'my_source'
9   end
10
11   context 'mostly defaults' do
12     let :facts do
13       {
14         :lsbdistid       => 'Debian',
15         :lsbdistcodename => 'wheezy',
16         :osfamily        => 'Debian'
17       }
18     end
19
20     let :params do
21       {
22         'include_deb' => false,
23       }
24     end
25
26     it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({
27       'ensure' => 'present',
28       'path'   => '/etc/apt/sources.list.d/my_source.list',
29       'owner'  => 'root',
30       'group'  => 'root',
31       'mode'   => '0644',
32     }).with_content(/# my_source\ndeb-src  wheezy main\n/)
33     }
34   end
35
36   context 'no defaults' do
37     let :facts do
38       {
39         :lsbdistid       => 'Debian',
40         :lsbdistcodename => 'wheezy',
41         :osfamily        => 'Debian'
42       }
43     end
44     let :params do
45       {
46         'comment'           => 'foo',
47         'location'          => 'http://debian.mirror.iweb.ca/debian/',
48         'release'           => 'sid',
49         'repos'             => 'testing',
50         'include_src'       => false,
51         'required_packages' => 'vim',
52         'key'               => GPG_KEY_ID,
53         'key_server'        => 'pgp.mit.edu',
54         'key_content'       => 'GPG key content',
55         'key_source'        => 'http://apt.puppetlabs.com/pubkey.gpg',
56         'pin'               => '10',
57         'architecture'      => 'x86_64',
58         'trusted_source'    => true,
59       }
60     end
61
62     it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({
63       'ensure' => 'present',
64       'path'   => '/etc/apt/sources.list.d/my_source.list',
65       'owner'  => 'root',
66       'group'  => 'root',
67       'mode'   => '0644',
68     }).with_content(/# foo\ndeb \[arch=x86_64 trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(/deb-src/)
69     }
70
71     it { is_expected.to contain_apt__pin('my_source').that_comes_before('File[my_source.list]').with({
72       'ensure'   => 'present',
73       'priority' => '10',
74       'origin'   => 'debian.mirror.iweb.ca',
75     })
76     }
77
78     it { is_expected.to contain_exec("Required packages: 'vim' for my_source").that_comes_before('Exec[apt_update]').that_subscribes_to('File[my_source.list]').with({
79       'command'     => '/usr/bin/apt-get -y install vim',
80       'logoutput'   => 'on_failure',
81       'refreshonly' => true,
82       'tries'       => '3',
83       'try_sleep'   => '1',
84     })
85     }
86
87     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({
88       'ensure' => 'present',
89         'key'  => GPG_KEY_ID,
90         'key_server' => 'pgp.mit.edu',
91         'key_content' => 'GPG key content',
92         'key_source' => 'http://apt.puppetlabs.com/pubkey.gpg',
93     })
94     }
95   end
96
97   context 'trusted_source true' do
98     let :facts do
99       {
100         :lsbdistid       => 'Debian',
101         :lsbdistcodename => 'wheezy',
102         :osfamily        => 'Debian'
103       }
104     end
105     let :params do
106       {
107         'include_src'    => false,
108         'trusted_source' => true,
109       }
110     end
111
112     it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({
113       'ensure' => 'present',
114       'path'   => '/etc/apt/sources.list.d/my_source.list',
115       'owner'  => 'root',
116       'group'  => 'root',
117       'mode'   => '0644',
118     }).with_content(/# my_source\ndeb \[trusted=yes\]  wheezy main\n/)
119     }
120   end
121
122   context 'architecture equals x86_64' do
123     let :facts do
124       {
125         :lsbdistid       => 'Debian',
126         :lsbdistcodename => 'wheezy',
127         :osfamily        => 'Debian'
128       }
129     end
130     let :params do
131       {
132         'include_deb'  => false,
133         'architecture' => 'x86_64',
134       }
135     end
136
137     it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({
138       'ensure' => 'present',
139       'path'   => '/etc/apt/sources.list.d/my_source.list',
140       'owner'  => 'root',
141       'group'  => 'root',
142       'mode'   => '0644',
143     }).with_content(/# my_source\ndeb-src \[arch=x86_64 \]  wheezy main\n/)
144     }
145   end
146  
147   context 'ensure => absent' do
148     let :facts do
149       {
150         :lsbdistid       => 'Debian',
151         :lsbdistcodename => 'wheezy',
152         :osfamily        => 'Debian'
153       }
154     end
155     let :params do
156       {
157         'ensure' => 'absent',
158       }
159     end
160
161     it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({
162       'ensure' => 'absent'
163     })
164     }
165   end
166
167   describe 'validation' do
168     context 'no release' do
169       let :facts do
170         {
171           :lsbdistid       => 'Debian',
172           :osfamily        => 'Debian'
173         }
174       end
175
176       it do
177         expect {
178           should compile
179         }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/)
180       end
181     end
182   end
183 end