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