Get rid of unattended upgrades and cleanup unused templates
[puppet-modules/puppetlabs-apt.git] / spec / defines / ppa_spec.rb
1 require 'spec_helper'
2 describe 'apt::ppa', :type => :define do
3
4   describe 'defaults' do
5     let :pre_condition do
6       'class { "apt": }'
7     end
8     let :facts do
9       {
10         :lsbdistrelease  => '11.04',
11         :lsbdistcodename => 'natty',
12         :operatingsystem => 'Ubuntu',
13         :osfamily        => 'Debian',
14         :lsbdistid       => 'Ubuntu',
15       }
16     end
17
18     let(:title) { 'ppa:needs/such.substitution/wow' }
19     it { is_expected.to contain_package('python-software-properties') }
20     it { is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow').that_notifies('Exec[apt_update]').with({
21       'environment' => [],
22       'command'     => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow',
23       'unless'      => '/usr/bin/test -s /etc/apt/sources.list.d/needs-such_substitution-wow-natty.list',
24       'user'        => 'root',
25       'logoutput'   => 'on_failure',
26     })
27     }
28
29     it { is_expected.to contain_file('/etc/apt/sources.list.d/needs-such_substitution-wow-natty.list').that_requires('Exec[add-apt-repository-ppa:needs/such.substitution/wow]').with({
30       'ensure' => 'file',
31     })
32     }
33   end
34
35   describe 'apt included, no proxy' do
36     let :pre_condition do
37       'class { "apt": }'
38     end
39     let :facts do
40       {
41         :lsbdistrelease  => '14.04',
42         :lsbdistcodename => 'trusty',
43         :operatingsystem => 'Ubuntu',
44         :lsbdistid       => 'Ubuntu',
45         :osfamily        => 'Debian',
46       }
47     end
48     let :params do
49       {
50         'options' => '',
51       }
52     end
53     let(:title) { 'ppa:foo' }
54     it { is_expected.to contain_package('software-properties-common') }
55     it { is_expected.to contain_exec('add-apt-repository-ppa:foo').that_notifies('Exec[apt_update]').with({
56       'environment' => [],
57       'command'     => '/usr/bin/add-apt-repository  ppa:foo',
58       'unless'      => '/usr/bin/test -s /etc/apt/sources.list.d/foo-trusty.list',
59       'user'        => 'root',
60       'logoutput'   => 'on_failure',
61     })
62     }
63
64     it { is_expected.to contain_file('/etc/apt/sources.list.d/foo-trusty.list').that_requires('Exec[add-apt-repository-ppa:foo]').with({
65       'ensure' => 'file',
66     })
67     }
68   end
69
70   describe 'ensure absent' do
71     let :facts do
72       {
73         :lsbdistrelease  => '14.04',
74         :lsbdistcodename => 'trusty',
75         :operatingsystem => 'Ubuntu',
76         :lsbdistid       => 'Ubuntu',
77         :osfamily        => 'Debian',
78       }
79     end
80     let(:title) { 'ppa:foo' }
81     let :params do
82       {
83         'ensure' => 'absent'
84       }
85     end
86     it { is_expected.to contain_file('/etc/apt/sources.list.d/foo-trusty.list').that_notifies('Exec[apt_update]').with({
87       'ensure' => 'absent',
88     })
89     }
90   end
91
92   context 'validation' do
93     describe 'no release' do
94       let :facts do
95         {
96           :lsbdistrelease  => '14.04',
97           :operatingsystem => 'Ubuntu',
98           :lsbdistid       => 'Ubuntu',
99           :osfamily        => 'Debian',
100         }
101       end
102       let(:title) { 'ppa:foo' }
103       it do
104         expect {
105           should compile
106         }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/)
107       end
108     end
109
110     describe 'not ubuntu' do
111       let :facts do
112         {
113           :lsbdistrelease  => '14.04',
114           :lsbdistcodename => 'trusty',
115           :operatingsystem => 'Debian',
116           :lsbdistid       => 'Ubuntu',
117           :osfamily        => 'Debian',
118         }
119       end
120       let(:title) { 'ppa:foo' }
121       it do
122         expect {
123           should compile
124         }.to raise_error(Puppet::Error, /apt::ppa is currently supported on Ubuntu only./)
125       end
126     end
127   end
128 end