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