3 describe 'apt::source', :type => :define do
4 let(:facts) { { :lsbdistid => 'Debian' } }
5 GPG_KEY_ID = '4BD6EC30'
11 let :default_params do
18 :required_packages => false,
21 :key_content => false,
29 :location => 'http://example.com',
30 :release => 'precise',
32 :include_src => false,
33 :required_packages => 'apache',
35 :key_server => 'keyserver.debian.com',
37 :key_content => 'ABCD1234'
41 :key_server => 'keyserver.debian.com',
45 :location => 'http://example.com',
46 :release => 'precise',
56 :architecture => 'amd64',
59 describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
61 default_params.merge(param_set)
65 {:lsbdistcodename => 'karmic', :lsbdistid => 'Ubuntu'}
73 "/etc/apt/sources.list.d/#{title}.list"
77 content = "#file generated by puppet\n# #{title}"
78 if param_hash[:architecture]
79 arch = "[arch=#{param_hash[:architecture]}] "
81 content << "\ndeb #{arch}#{param_hash[:location]} #{param_hash[:release]} #{param_hash[:repos]}\n"
83 if param_hash[:include_src]
84 content << "deb-src #{arch}#{param_hash[:location]} #{param_hash[:release]} #{param_hash[:repos]}\n"
89 it { should contain_apt__params }
91 it { should contain_file("#{title}.list").with({
92 'ensure' => param_hash[:ensure],
103 should contain_apt__pin(title).with({
104 "priority" => param_hash[:pin],
105 "before" => "File[#{title}.list]"
108 should_not contain_apt__pin(title).with({
109 "priority" => param_hash[:pin],
110 "before" => "File[#{title}.list]"
116 should contain_exec("apt_update").with({
117 "command" => "/usr/bin/apt-get update",
118 "refreshonly" => true
123 if param_hash[:required_packages]
124 should contain_exec("Required packages: '#{param_hash[:required_packages]}' for #{title}").with({
125 "command" => "/usr/bin/apt-get -y install #{param_hash[:required_packages]}",
126 "subscribe" => "File[#{title}.list]",
127 "refreshonly" => true,
128 "before" => 'Exec[apt_update]',
131 should_not 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
140 key_server = param_hash[:key_server] || nil
141 key_content = param_hash[:key_content] || nil
142 key_source = param_hash[:key_source] || nil
144 should contain_apt__key("Add key: #{param_hash[:key]} from Apt::Source #{title}").with({
145 "key" => param_hash[:key],
146 "ensure" => :present,
147 "key_server" => key_server,
148 "key_content" => key_content,
149 "key_source" => key_source,
150 "before" => "File[#{title}.list]"
153 should_not contain_apt__key("Add key: #{param_hash[:key]} from Apt::Source #{title}").with({
154 "key" => param_hash[:key],
155 "ensure" => :present,
156 "key_server" => param_hash[:key_server],
157 "key_content" => param_hash[:key_content],
158 "key_source" => param_hash[:key_source],
159 "before" => "File[#{title}.list]"
165 describe "without release should raise a Puppet::Error" do
166 let(:default_params) { Hash.new }
167 let(:facts) { Hash.new }
168 it { expect { should raise_error(Puppet::Error) } }
169 let(:facts) { { :lsbdistcodename => 'lucid', :lsbdistid => 'Ubuntu' } }
170 it { should contain_apt__source(title) }