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"
78 if param_hash[:comment]
79 content << "# #{comment}"
81 content << "# #{title}"
83 if param_hash[:architecture]
84 arch = "[arch=#{param_hash[:architecture]}] "
86 content << "\ndeb #{arch}#{param_hash[:location]} #{param_hash[:release]} #{param_hash[:repos]}\n"
88 if param_hash[:include_src]
89 content << "deb-src #{arch}#{param_hash[:location]} #{param_hash[:release]} #{param_hash[:repos]}\n"
94 it { should contain_apt__params }
96 it { should contain_file("#{title}.list").with({
97 'ensure' => param_hash[:ensure],
102 'content' => content,
108 should contain_apt__pin(title).with({
109 "priority" => param_hash[:pin],
110 "before" => "File[#{title}.list]"
113 should_not contain_apt__pin(title).with({
114 "priority" => param_hash[:pin],
115 "before" => "File[#{title}.list]"
121 should contain_exec("apt_update").with({
122 "command" => "/usr/bin/apt-get update",
123 "refreshonly" => true
128 if param_hash[:required_packages]
129 should contain_exec("Required packages: '#{param_hash[:required_packages]}' for #{title}").with({
130 "command" => "/usr/bin/apt-get -y install #{param_hash[:required_packages]}",
131 "subscribe" => "File[#{title}.list]",
132 "refreshonly" => true,
133 "before" => 'Exec[apt_update]',
136 should_not contain_exec("Required packages: '#{param_hash[:required_packages]}' for #{title}").with({
137 "command" => "/usr/bin/apt-get -y install #{param_hash[:required_packages]}",
138 "subscribe" => "File[#{title}.list]",
139 "refreshonly" => true
145 key_server = param_hash[:key_server] || nil
146 key_content = param_hash[:key_content] || nil
147 key_source = param_hash[:key_source] || nil
149 should contain_apt__key("Add key: #{param_hash[:key]} from Apt::Source #{title}").with({
150 "key" => param_hash[:key],
151 "ensure" => :present,
152 "key_server" => key_server,
153 "key_content" => key_content,
154 "key_source" => key_source,
155 "before" => "File[#{title}.list]"
158 should_not contain_apt__key("Add key: #{param_hash[:key]} from Apt::Source #{title}").with({
159 "key" => param_hash[:key],
160 "ensure" => :present,
161 "key_server" => param_hash[:key_server],
162 "key_content" => param_hash[:key_content],
163 "key_source" => param_hash[:key_source],
164 "before" => "File[#{title}.list]"
170 describe "without release should raise a Puppet::Error" do
171 let(:default_params) { Hash.new }
172 let(:facts) { Hash.new }
173 it { expect { should raise_error(Puppet::Error) } }
174 let(:facts) { { :lsbdistcodename => 'lucid', :lsbdistid => 'Ubuntu' } }
175 it { should contain_apt__source(title) }