3 describe 'apt::source', :type => :define do
4 let(:facts) { { :lsbdistid => 'Debian' } }
5 GPG_KEY_ID = '4BD6EC30'
11 let :default_params do
19 :required_packages => false,
22 :key_content => false,
30 :location => 'http://example.com',
31 :release => 'precise',
33 :include_src => false,
34 :required_packages => 'apache',
36 :key_server => 'keyserver.debian.com',
38 :key_content => 'ABCD1234'
42 :key_server => 'keyserver.debian.com',
46 :location => 'http://example.com',
47 :release => 'precise',
57 :architecture => 'amd64',
60 describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
62 default_params.merge(param_set)
66 {:lsbdistcodename => 'karmic', :lsbdistid => 'Ubuntu'}
74 "/etc/apt/sources.list.d/#{title}.list"
78 content = "#file generated by puppet\n"
79 if param_hash[:comment]
80 content << "# #{comment}"
82 content << "# #{title}"
84 if param_hash[:architecture]
85 arch = "[arch=#{param_hash[:architecture]}] "
87 if param_hash[:include_deb]
88 content << "\ndeb #{arch}#{param_hash[:location]} #{param_hash[:release]} #{param_hash[:repos]}\n"
90 if param_hash[:include_src]
91 content << "deb-src #{arch}#{param_hash[:location]} #{param_hash[:release]} #{param_hash[:repos]}\n"
96 it { should contain_apt__params }
98 it { should contain_file("#{title}.list").with({
99 'ensure' => param_hash[:ensure],
104 'content' => content,
110 should contain_apt__pin(title).with({
111 "priority" => param_hash[:pin],
112 "before" => "File[#{title}.list]"
115 should_not contain_apt__pin(title).with({
116 "priority" => param_hash[:pin],
117 "before" => "File[#{title}.list]"
123 should contain_exec("apt_update").with({
124 "command" => "/usr/bin/apt-get update",
125 "refreshonly" => true
130 if param_hash[:required_packages]
131 should contain_exec("Required packages: '#{param_hash[:required_packages]}' for #{title}").with({
132 "command" => "/usr/bin/apt-get -y install #{param_hash[:required_packages]}",
133 "subscribe" => "File[#{title}.list]",
134 "refreshonly" => true,
135 "before" => 'Exec[apt_update]',
138 should_not contain_exec("Required packages: '#{param_hash[:required_packages]}' for #{title}").with({
139 "command" => "/usr/bin/apt-get -y install #{param_hash[:required_packages]}",
140 "subscribe" => "File[#{title}.list]",
141 "refreshonly" => true
147 key_server = param_hash[:key_server] || nil
148 key_content = param_hash[:key_content] || nil
149 key_source = param_hash[:key_source] || nil
151 should contain_apt__key("Add key: #{param_hash[:key]} from Apt::Source #{title}").with({
152 "key" => param_hash[:key],
153 "ensure" => :present,
154 "key_server" => key_server,
155 "key_content" => key_content,
156 "key_source" => key_source,
157 "before" => "File[#{title}.list]"
160 should_not contain_apt__key("Add key: #{param_hash[:key]} from Apt::Source #{title}").with({
161 "key" => param_hash[:key],
162 "ensure" => :present,
163 "key_server" => param_hash[:key_server],
164 "key_content" => param_hash[:key_content],
165 "key_source" => param_hash[:key_source],
166 "before" => "File[#{title}.list]"
172 describe "without release should raise a Puppet::Error" do
173 let(:default_params) { Hash.new }
174 let(:facts) { Hash.new }
175 it { expect { should raise_error(Puppet::Error) } }
176 let(:facts) { { :lsbdistcodename => 'lucid', :lsbdistid => 'Ubuntu' } }
177 it { should contain_apt__source(title) }