dde015abad483c8de23c1e3b3605c8904edcaa9e
[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     end
65     let :facts do
66       {
67         :lsbdistrelease  => '14.04',
68         :lsbdistcodename => 'trusty',
69         :operatingsystem => 'Ubuntu',
70         :lsbdistid       => 'Ubuntu',
71         :osfamily        => 'Debian',
72       }
73     end
74     let :params do
75       {
76         'options' => '',
77         'package_manage' => true,
78         'proxy' => { 'host' => 'localhost', }
79       }
80     end
81     let(:title) { 'ppa:foo' }
82     it { is_expected.to contain_package('software-properties-common') }
83     it { is_expected.to contain_exec('add-apt-repository-ppa:foo').that_notifies('Exec[apt_update]').with({
84       :environment => ['http_proxy=http://localhost:8080', 'https_proxy=http://localhost:8080'],
85       :command     => '/usr/bin/add-apt-repository  ppa:foo',
86       :unless      => '/usr/bin/test -s /etc/apt/sources.list.d/foo-trusty.list',
87       :user        => 'root',
88       :logoutput   => 'on_failure',
89     })
90     }
91   end
92
93   describe 'apt included, proxy host and port' do
94     let :pre_condition do
95       'class { "apt": }'
96     end
97     let :facts do
98       {
99         :lsbdistrelease  => '14.04',
100         :lsbdistcodename => 'trusty',
101         :operatingsystem => 'Ubuntu',
102         :lsbdistid       => 'Ubuntu',
103         :osfamily        => 'Debian',
104       }
105     end
106     let :params do
107       {
108         :options => '',
109         :package_manage => true,
110         :proxy => { 'host' => 'localhost', 'port' => 8180, }
111       }
112     end
113     let(:title) { 'ppa:foo' }
114     it { is_expected.to contain_package('software-properties-common') }
115     it { is_expected.to contain_exec('add-apt-repository-ppa:foo').that_notifies('Exec[apt_update]').with({
116       :environment => ['http_proxy=http://localhost:8180', 'https_proxy=http://localhost:8180'],
117       :command     => '/usr/bin/add-apt-repository  ppa:foo',
118       :unless      => '/usr/bin/test -s /etc/apt/sources.list.d/foo-trusty.list',
119       :user        => 'root',
120       :logoutput   => 'on_failure',
121     })
122     }
123   end
124
125   describe 'ensure absent' do
126     let :pre_condition do
127       'class { "apt": }'
128     end
129     let :facts do
130       {
131         :lsbdistrelease  => '14.04',
132         :lsbdistcodename => 'trusty',
133         :operatingsystem => 'Ubuntu',
134         :lsbdistid       => 'Ubuntu',
135         :osfamily        => 'Debian',
136       }
137     end
138     let(:title) { 'ppa:foo' }
139     let :params do
140       {
141         :ensure => 'absent'
142       }
143     end
144     it { is_expected.to contain_file('/etc/apt/sources.list.d/foo-trusty.list').that_notifies('Exec[apt_update]').with({
145       :ensure => 'absent',
146     })
147     }
148   end
149
150   context 'validation' do
151     describe 'no release' do
152       let :facts do
153         {
154           :lsbdistrelease  => '14.04',
155           :operatingsystem => 'Ubuntu',
156           :lsbdistid       => 'Ubuntu',
157           :osfamily        => 'Debian',
158         }
159       end
160       let(:title) { 'ppa:foo' }
161       it do
162         expect {
163           is_expected.to compile
164         }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/)
165       end
166     end
167
168     describe 'not ubuntu' do
169       let :facts do
170         {
171           :lsbdistrelease  => '14.04',
172           :lsbdistcodename => 'trusty',
173           :operatingsystem => 'Debian',
174           :lsbdistid       => 'Ubuntu',
175           :osfamily        => 'Debian',
176         }
177       end
178       let(:title) { 'ppa:foo' }
179       it do
180         expect {
181           is_expected.to compile
182         }.to raise_error(Puppet::Error, /apt::ppa is currently supported on Ubuntu only./)
183       end
184     end
185   end
186 end