ab86b93b2e35d0b145f1e601cebd139e7e066a9c
[puppet-modules/puppetlabs-apt.git] / spec / defines / ppa_spec.rb
1 require 'spec_helper'
2 describe 'apt::ppa', :type => :define do
3   ['ppa:dans_ppa', 'dans_ppa','ppa:dans-daily/ubuntu'].each do |t|
4     describe "with title #{t}" do
5       let :pre_condition do
6         'class { "apt": }'
7       end
8       let :facts do
9         {:lsbdistcodename => 'natty'}
10       end
11       let :title do
12         t
13       end
14       let :release do
15         "natty"
16       end
17       let :filename do
18         t.sub(/^ppa:/,'').gsub('/','-') << "-" << "#{release}.list"
19       end
20
21       it { should contain_package("python-software-properties") }
22
23       it { should contain_exec("apt_update").with(
24         'command'     => '/usr/bin/apt-get update',
25         'refreshonly' => true
26         )
27       }
28
29       it { should contain_exec("add-apt-repository-#{t}").with(
30         'command' => "/usr/bin/add-apt-repository #{t}",
31         'creates' => "/etc/apt/sources.list.d/#{filename}",
32         'require' => "Package[python-software-properties]",
33         'notify'  => "Exec[apt_update]"
34         )
35       }
36
37       it { should create_file("/etc/apt/sources.list.d/#{filename}").with(
38         'ensure'  => 'file',
39         'require' => "Exec[add-apt-repository-#{t}]"
40         )
41       }
42     end
43   end
44
45   describe "it should not error if package['python-software-properties'] is already defined" do
46     let :pre_condition do
47        'class {"apt": }' +
48        'package { "python-software-properties": }->Apt::Ppa["ppa"]'
49     end
50     let :facts do
51       {:lsbdistcodename => 'natty'}
52     end
53     let(:title) { "ppa" }
54     let(:release) { "natty" }
55     it { should contain_package("python-software-properties") }
56   end
57
58   describe "without Class[apt] should raise a Puppet::Error" do
59     let(:release) { "natty" }
60     let(:title) { "ppa" }
61     it { expect { should contain_apt__ppa(title) }.to raise_error(Puppet::Error) }
62   end
63
64   describe "without release should raise a Puppet::Error" do
65     let(:title) { "ppa:" }
66     it { expect { should contain_apt__ppa(:release) }.to raise_error(Puppet::Error) }
67   end
68 end