Convert specs to RSpec 3.1.7 syntax with Transpec
[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_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 'ensure absent' 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(:title) { 'ppa:foo' }
75     let :params do
76       {
77         'ensure' => 'absent'
78       }
79     end
80     it { is_expected.to contain_file('/etc/apt/sources.list.d/foo-trusty.list').that_notifies('Exec[apt_update]').with({
81       'ensure' => 'absent',
82     })
83     }
84   end
85
86   context 'validation' do
87     describe 'no release' do
88       let :facts do
89         {
90           :lsbdistrelease  => '14.04',
91           :operatingsystem => 'Ubuntu',
92           :lsbdistid       => 'Ubuntu',
93           :osfamily        => 'Debian',
94         }
95       end
96       let(:title) { 'ppa:foo' }
97       it do
98         expect {
99           is_expected.to compile
100         }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/)
101       end
102     end
103
104     describe 'not ubuntu' do
105       let :facts do
106         {
107           :lsbdistrelease  => '14.04',
108           :lsbdistcodename => 'trusty',
109           :operatingsystem => 'Debian',
110           :lsbdistid       => 'Ubuntu',
111           :osfamily        => 'Debian',
112         }
113       end
114       let(:title) { 'ppa:foo' }
115       it do
116         expect {
117           is_expected.to compile
118         }.to raise_error(Puppet::Error, /apt::ppa is currently supported on Ubuntu only./)
119       end
120     end
121   end
122 end