14a5139c3ba4d465b52c37f8bc3d98c8d9e03923
[puppet-modules/puppetlabs-apt.git] / spec / defines / ppa_spec.rb
1 require 'spec_helper'
2 describe 'apt::ppa' 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_not 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   end
29
30   describe 'apt included, no proxy' do
31     let :pre_condition do
32       'class { "apt": }'
33     end
34     let :facts do
35       {
36         :lsbdistrelease  => '14.04',
37         :lsbdistcodename => 'trusty',
38         :operatingsystem => 'Ubuntu',
39         :lsbdistid       => 'Ubuntu',
40         :osfamily        => 'Debian',
41       }
42     end
43     let :params do
44       {
45         :options => '',
46         :package_manage => true,
47       }
48     end
49     let(:title) { 'ppa:foo' }
50     it { is_expected.to contain_package('software-properties-common') }
51     it { is_expected.to contain_exec('add-apt-repository-ppa:foo').that_notifies('Exec[apt_update]').with({
52       :environment => [],
53       :command     => '/usr/bin/add-apt-repository  ppa:foo',
54       :unless      => '/usr/bin/test -s /etc/apt/sources.list.d/foo-trusty.list',
55       :user        => 'root',
56       :logoutput   => 'on_failure',
57     })
58     }
59   end
60
61   describe 'apt included, proxy host' do
62     let :pre_condition do
63       'class { "apt":
64         proxy => { "host" => "localhost" },
65       }'
66     end
67     let :facts do
68       {
69         :lsbdistrelease  => '14.04',
70         :lsbdistcodename => 'trusty',
71         :operatingsystem => 'Ubuntu',
72         :lsbdistid       => 'Ubuntu',
73         :osfamily        => 'Debian',
74       }
75     end
76     let :params do
77       {
78         'options' => '',
79         'package_manage' => true,
80       }
81     end
82     let(:title) { 'ppa:foo' }
83     it { is_expected.to contain_package('software-properties-common') }
84     it { is_expected.to contain_exec('add-apt-repository-ppa:foo').that_notifies('Exec[apt_update]').with({
85       :environment => ['http_proxy=http://localhost:8080'],
86       :command     => '/usr/bin/add-apt-repository  ppa:foo',
87       :unless      => '/usr/bin/test -s /etc/apt/sources.list.d/foo-trusty.list',
88       :user        => 'root',
89       :logoutput   => 'on_failure',
90     })
91     }
92   end
93
94   describe 'apt included, proxy host and port' do
95     let :pre_condition do
96       'class { "apt":
97         proxy => { "host" => "localhost", "port" => 8180 },
98       }'
99     end
100     let :facts do
101       {
102         :lsbdistrelease  => '14.04',
103         :lsbdistcodename => 'trusty',
104         :operatingsystem => 'Ubuntu',
105         :lsbdistid       => 'Ubuntu',
106         :osfamily        => 'Debian',
107       }
108     end
109     let :params do
110       {
111         :options => '',
112         :package_manage => true,
113       }
114     end
115     let(:title) { 'ppa:foo' }
116     it { is_expected.to contain_package('software-properties-common') }
117     it { is_expected.to contain_exec('add-apt-repository-ppa:foo').that_notifies('Exec[apt_update]').with({
118       :environment => ['http_proxy=http://localhost:8180'],
119       :command     => '/usr/bin/add-apt-repository  ppa:foo',
120       :unless      => '/usr/bin/test -s /etc/apt/sources.list.d/foo-trusty.list',
121       :user        => 'root',
122       :logoutput   => 'on_failure',
123     })
124     }
125   end
126
127   describe 'apt included, proxy host and port and https' do
128     let :pre_condition do
129       'class { "apt":
130         proxy => { "host" => "localhost", "port" => 8180, "https" => true },
131       }'
132     end
133     let :facts do
134       {
135         :lsbdistrelease  => '14.04',
136         :lsbdistcodename => 'trusty',
137         :operatingsystem => 'Ubuntu',
138         :lsbdistid       => 'Ubuntu',
139         :osfamily        => 'Debian',
140       }
141     end
142     let :params do
143       {
144         :options => '',
145         :package_manage => true,
146       }
147     end
148     let(:title) { 'ppa:foo' }
149     it { is_expected.to contain_package('software-properties-common') }
150     it { is_expected.to contain_exec('add-apt-repository-ppa:foo').that_notifies('Exec[apt_update]').with({
151       :environment => ['http_proxy=http://localhost:8180', 'https_proxy=https://localhost:8180'],
152       :command     => '/usr/bin/add-apt-repository  ppa:foo',
153       :unless      => '/usr/bin/test -s /etc/apt/sources.list.d/foo-trusty.list',
154       :user        => 'root',
155       :logoutput   => 'on_failure',
156     })
157     }
158   end
159
160   describe 'ensure absent' do
161     let :pre_condition do
162       'class { "apt": }'
163     end
164     let :facts do
165       {
166         :lsbdistrelease  => '14.04',
167         :lsbdistcodename => 'trusty',
168         :operatingsystem => 'Ubuntu',
169         :lsbdistid       => 'Ubuntu',
170         :osfamily        => 'Debian',
171       }
172     end
173     let(:title) { 'ppa:foo' }
174     let :params do
175       {
176         :ensure => 'absent'
177       }
178     end
179     it { is_expected.to contain_file('/etc/apt/sources.list.d/foo-trusty.list').that_notifies('Exec[apt_update]').with({
180       :ensure => 'absent',
181     })
182     }
183   end
184
185   context 'validation' do
186     describe 'no release' do
187       let :facts do
188         {
189           :lsbdistrelease  => '14.04',
190           :operatingsystem => 'Ubuntu',
191           :lsbdistid       => 'Ubuntu',
192           :osfamily        => 'Debian',
193         }
194       end
195       let(:title) { 'ppa:foo' }
196       it do
197         expect {
198           is_expected.to compile
199         }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/)
200       end
201     end
202
203     describe 'not ubuntu' do
204       let :facts do
205         {
206           :lsbdistrelease  => '14.04',
207           :lsbdistcodename => 'trusty',
208           :operatingsystem => 'Debian',
209           :lsbdistid       => 'Ubuntu',
210           :osfamily        => 'Debian',
211         }
212       end
213       let(:title) { 'ppa:foo' }
214       it do
215         expect {
216           is_expected.to compile
217         }.to raise_error(Puppet::Error, /apt::ppa is currently supported on Ubuntu only./)
218       end
219     end
220   end
221 end