Merge pull request #345 from mhaskel/merge_1.5.x_changes
[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       }
16     end
17
18     let :params do
19       {
20         'include_deb' => false,
21       }
22     end
23
24     it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({
25       'ensure' => 'present',
26       'path'   => '/etc/apt/sources.list.d/my_source.list',
27       'owner'  => 'root',
28       'group'  => 'root',
29       'mode'   => '0644',
30     }).with_content(/#file generated by puppet\n# my_source\ndeb-src  wheezy main\n/)
31     }
32   end
33
34   context 'no defaults' do
35     let :facts do
36       {
37         :lsbdistid       => 'Debian',
38         :lsbdistcodename => 'wheezy',
39       }
40     end
41     let :params do
42       {
43         'comment'           => 'foo',
44         'location'          => 'http://debian.mirror.iweb.ca/debian/',
45         'release'           => 'sid',
46         'repos'             => 'testing',
47         'include_src'       => false,
48         'required_packages' => 'vim',
49         'key'               => GPG_KEY_ID,
50         'key_server'        => 'pgp.mit.edu',
51         'key_content'       => 'GPG key content',
52         'key_source'        => 'http://apt.puppetlabs.com/pubkey.gpg',
53         'pin'               => '10',
54         'architecture'      => 'x86_64',
55       }
56     end
57
58     it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({
59       'ensure' => 'present',
60       'path'   => '/etc/apt/sources.list.d/my_source.list',
61       'owner'  => 'root',
62       'group'  => 'root',
63       'mode'   => '0644',
64     }).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/)
65     }
66
67     it { is_expected.to contain_apt__pin('my_source').that_comes_before('File[my_source.list]').with({
68       'ensure'   => 'present',
69       'priority' => '10',
70       'origin'   => 'debian.mirror.iweb.ca',
71     })
72     }
73
74     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({
75       'command'     => '/usr/bin/apt-get -y install vim',
76       'logoutput'   => 'on_failure',
77       'refreshonly' => true,
78       'tries'       => '3',
79       'try_sleep'   => '1',
80     })
81     }
82
83     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({
84       'ensure' => 'present',
85         'key'  => GPG_KEY_ID,
86         'key_server' => 'pgp.mit.edu',
87         'key_content' => 'GPG key content',
88         'key_source' => 'http://apt.puppetlabs.com/pubkey.gpg',
89     })
90     }
91   end
92
93   context 'ensure => absent' do
94     let :facts do
95       {
96         :lsbdistid       => 'Debian',
97         :lsbdistcodename => 'wheezy',
98       }
99     end
100     let :params do
101       {
102         'ensure' => 'absent',
103       }
104     end
105
106     it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({
107       'ensure' => 'absent'
108     })
109     }
110   end
111
112   describe 'validation' do
113     context 'no release' do
114       let :facts do
115         {
116           :lsbdistid       => 'Debian',
117         }
118       end
119
120       it do
121         expect {
122           should compile
123         }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/)
124       end
125     end
126   end
127 end