]> review.fuel-infra Code Review - puppet-modules/puppetlabs-apt.git/blob - spec/defines/source_spec.rb
Allow full length GPG key fingerprints.
[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(/#file generated by puppet\n# 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       }
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\] 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 'ensure => absent' do
97     let :facts do
98       {
99         :lsbdistid       => 'Debian',
100         :lsbdistcodename => 'wheezy',
101         :osfamily        => 'Debian'
102       }
103     end
104     let :params do
105       {
106         'ensure' => 'absent',
107       }
108     end
109
110     it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({
111       'ensure' => 'absent'
112     })
113     }
114   end
115
116   describe 'validation' do
117     context 'no release' do
118       let :facts do
119         {
120           :lsbdistid       => 'Debian',
121           :osfamily        => 'Debian'
122         }
123       end
124
125       it do
126         expect {
127           should compile
128         }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/)
129       end
130     end
131   end
132 end