- add bits for updating apt
[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       }
58     end
59
60     it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({
61       'ensure' => 'present',
62       'path'   => '/etc/apt/sources.list.d/my_source.list',
63       'owner'  => 'root',
64       'group'  => 'root',
65       'mode'   => '0644',
66     }).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/)
67     }
68
69     it { is_expected.to contain_apt__pin('my_source').that_comes_before('File[my_source.list]').with({
70       'ensure'   => 'present',
71       'priority' => '10',
72       'origin'   => 'debian.mirror.iweb.ca',
73     })
74     }
75
76     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({
77       'command'     => '/usr/bin/apt-get -y install vim',
78       'logoutput'   => 'on_failure',
79       'refreshonly' => true,
80       'tries'       => '3',
81       'try_sleep'   => '1',
82     })
83     }
84
85     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({
86       'ensure' => 'present',
87         'key'  => GPG_KEY_ID,
88         'key_server' => 'pgp.mit.edu',
89         'key_content' => 'GPG key content',
90         'key_source' => 'http://apt.puppetlabs.com/pubkey.gpg',
91     })
92     }
93   end
94
95   context 'ensure => absent' do
96     let :facts do
97       {
98         :lsbdistid       => 'Debian',
99         :lsbdistcodename => 'wheezy',
100         :osfamily        => 'Debian'
101       }
102     end
103     let :params do
104       {
105         'ensure' => 'absent',
106       }
107     end
108
109     it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({
110       'ensure' => 'absent'
111     })
112     }
113   end
114
115   describe 'validation' do
116     context 'no release' do
117       let :facts do
118         {
119           :lsbdistid       => 'Debian',
120           :osfamily        => 'Debian'
121         }
122       end
123
124       it do
125         expect {
126           should compile
127         }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/)
128       end
129     end
130   end
131 end