2 describe 'apt', :type => :class do
3 let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
6 it { should contain_file('sources.list').that_notifies('Exec[apt_update]').only_with({
8 'path' => '/etc/apt/sources.list',
12 'notify' => 'Exec[apt_update]',
15 it { should contain_file('sources.list.d').that_notifies('Exec[apt_update]').only_with({
16 'ensure' => 'directory',
17 'path' => '/etc/apt/sources.list.d',
22 'notify' => 'Exec[apt_update]',
25 it { should contain_file('preferences.d').only_with({
26 'ensure' => 'directory',
27 'path' => '/etc/apt/preferences.d',
34 it { should contain_file('01proxy').that_notifies('Exec[apt_update]').only_with({
36 'path' => '/etc/apt/apt.conf.d/01proxy',
37 'notify' => 'Exec[apt_update]',
40 it { should contain_file('old-proxy-file').that_notifies('Exec[apt_update]').only_with({
42 'path' => '/etc/apt/apt.conf.d/proxy',
43 'notify' => 'Exec[apt_update]',
46 it { should contain_exec('apt_update').with({
47 'refreshonly' => 'true',
51 context 'lots of non-defaults' do
54 :always_apt_update => true,
55 :disable_keys => true,
57 :proxy_port => '9876',
58 :purge_sources_list => true,
59 :purge_sources_list_d => true,
60 :purge_preferences => true,
61 :purge_preferences_d => true,
62 :update_timeout => '1',
64 :fancy_progress => true,
68 it { should contain_file('sources.list').with({
69 'content' => "# Repos managed by puppet.\n"
72 it { should contain_file('sources.list.d').with({
77 it { should contain_file('apt-preferences').only_with({
79 'path' => '/etc/apt/preferences',
82 it { should contain_file('preferences.d').with({
87 it { should contain_file('99progressbar').only_with({
88 'ensure' => 'present',
89 'content' => 'Dpkg::Progress-Fancy "1";',
90 'path' => '/etc/apt/apt.conf.d/99progressbar',
93 it { should contain_file('99unauth').only_with({
94 'ensure' => 'present',
95 'content' => "APT::Get::AllowUnauthenticated 1;\n",
96 'path' => '/etc/apt/apt.conf.d/99unauth',
99 it { should contain_file('01proxy').that_notifies('Exec[apt_update]').only_with({
100 'ensure' => 'present',
101 'path' => '/etc/apt/apt.conf.d/01proxy',
102 'content' => "Acquire::http::Proxy \"http://foo:9876\";\n",
103 'notify' => 'Exec[apt_update]',
109 it { should contain_exec('apt_update').with({
110 'refreshonly' => 'false',
117 context 'more non-default' do
120 :fancy_progress => false,
121 :disable_keys => false,
125 it { should contain_file('99progressbar').only_with({
126 'ensure' => 'absent',
127 'path' => '/etc/apt/apt.conf.d/99progressbar',
130 it { should contain_file('99unauth').only_with({
131 'ensure' => 'absent',
132 'path' => '/etc/apt/apt.conf.d/99unauth',
137 context 'with sources defined on valid osfamily' do
139 { :osfamily => 'Debian',
140 :lsbdistcodename => 'precise',
141 :lsbdistid => 'Debian',
144 let(:params) { { :sources => {
145 'debian_unstable' => {
146 'location' => 'http://debian.mirror.iweb.ca/debian/',
147 'release' => 'unstable',
148 'repos' => 'main contrib non-free',
149 'required_packages' => 'debian-keyring debian-archive-keyring',
151 'key_server' => 'subkeys.pgp.net',
153 'include_src' => true
156 'location' => 'http://apt.puppetlabs.com',
159 'key_server' => 'pgp.mit.edu',
164 should contain_file('debian_unstable.list').with({
165 'ensure' => 'present',
166 'path' => '/etc/apt/sources.list.d/debian_unstable.list',
170 'notify' => 'Exec[apt_update]',
174 it { should contain_file('debian_unstable.list').with_content(/^deb http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }
175 it { should contain_file('debian_unstable.list').with_content(/^deb-src http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }
178 should contain_file('puppetlabs.list').with({
179 'ensure' => 'present',
180 'path' => '/etc/apt/sources.list.d/puppetlabs.list',
184 'notify' => 'Exec[apt_update]',
188 it { should contain_file('puppetlabs.list').with_content(/^deb http:\/\/apt.puppetlabs.com precise main$/) }
189 it { should contain_file('puppetlabs.list').with_content(/^deb-src http:\/\/apt.puppetlabs.com precise main$/) }
192 describe 'failing tests' do
193 context 'bad purge_sources_list' do
196 'purge_sources_list' => 'foo'
202 }.to raise_error(Puppet::Error)
206 context 'bad purge_sources_list_d' do
209 'purge_sources_list_d' => 'foo'
215 }.to raise_error(Puppet::Error)
219 context 'bad purge_preferences' do
222 'purge_preferences' => 'foo'
228 }.to raise_error(Puppet::Error)
232 context 'bad purge_preferences_d' do
235 'purge_preferences_d' => 'foo'
241 }.to raise_error(Puppet::Error)
245 context 'with unsupported osfamily' do
247 { :osfamily => 'Darwin', }
253 }.to raise_error(Puppet::Error, /This module only works on Debian or derivatives like Ubuntu/)