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