2 describe 'apt::source', :type => :define do
13 :required_packages => false,
15 :key_server => 'keyserver.ubuntu.com',
23 :location => 'somewhere',
24 :release => 'precise',
26 :include_src => false,
27 :required_packages => 'apache',
29 :key_server => 'keyserver.debian.com',
31 :key_content => 'ABCD1234'
35 :key_server => 'keyserver.debian.com',
36 :key_content => false,
39 describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
41 default_params.merge(param_set)
45 {:lsbdistcodename => 'karmic'}
53 "/etc/apt/sources.list.d/#{title}.list"
57 content = "# #{title}"
58 content << "\ndeb #{param_hash[:location]} #{param_hash[:release]} #{param_hash[:repos]}\n"
59 if param_hash[:include_src]
60 content << "deb-src #{param_hash[:location]} #{param_hash[:release]} #{param_hash[:repos]}\n"
65 it { should contain_apt__params }
67 it { should contain_file("#{title}.list").with({
79 should contain_apt__pin(param_hash[:release]).with({
80 "priority" => param_hash[:pin],
81 "before" => "File[#{title}.list]"
84 should_not contain_apt__pin(param_hash[:release]).with({
85 "priority" => param_hash[:pin],
86 "before" => "File[#{title}.list]"
92 should contain_exec("#{title} apt update").with({
93 "command" => "/usr/bin/apt-get update",
94 "subscribe" => "File[#{title}.list]",
100 if param_hash[:required_packages]
101 should contain_exec("Required packages: '#{param_hash[:required_packages]}' for #{title}").with({
102 "command" => "/usr/bin/apt-get -y install #{param_hash[:required_packages]}",
103 "subscribe" => "File[#{title}.list]",
104 "refreshonly" => true
107 should_not contain_exec("Required packages: '#{param_hash[:required_packages]}' for #{title}").with({
108 "command" => "/usr/bin/apt-get -y install #{param_hash[:required_packages]}",
109 "subscribe" => "File[#{title}.list]",
110 "refreshonly" => true
117 if param_hash[:key_content]
118 should contain_exec("Add key: #{param_hash[:key]} from content for #{title}").with({
119 "command" => "/bin/echo '#{param_hash[:key_content]}' | /usr/bin/apt-key add -",
120 "unless" => "/usr/bin/apt-key list | /bin/grep '#{param_hash[:key]}'",
121 "before" => "File[#{title}.list]"
124 should_not contain_exec("Add key: #{param_hash[:key]} from content for #{title}").with({
125 "command" => "/bin/echo '#{param_hash[:key_content]}' | /usr/bin/apt-key add -",
126 "unless" => "/usr/bin/apt-key list | /bin/grep '#{param_hash[:key]}'",
127 "before" => "File[#{title}.list]"
131 should_not contain_exec("Add key: #{param_hash[:key]} from content for #{title}").with({
132 "command" => "/bin/echo '#{param_hash[:key_content]}' | /usr/bin/apt-key add -",
133 "unless" => "/usr/bin/apt-key list | /bin/grep '#{param_hash[:key]}'",
134 "before" => "File[#{title}.list]"
141 if param_hash[:key_content]
142 should_not contain_exec("Add key: #{param_hash[:key]} from #{param_hash[:key_server]} for #{title}").with({
143 "command" => "/usr/bin/apt-key adv --keyserver #{param_hash[:key_server]} --recv-keys #{param_hash[:key]}",
144 "unless" => "/usr/bin/apt-key list | /bin/grep #{param_hash[:key]}",
145 "before" => "File[#{title}.list]"
148 should contain_exec("Add key: #{param_hash[:key]} from #{param_hash[:key_server]} for #{title}").with({
149 "command" => "/usr/bin/apt-key adv --keyserver #{param_hash[:key_server]} --recv-keys #{param_hash[:key]}",
150 "unless" => "/usr/bin/apt-key list | /bin/grep #{param_hash[:key]}",
151 "before" => "File[#{title}.list]"
155 should_not contain_exec("Add key: #{param_hash[:key]} from #{param_hash[:key_server]} for #{title}").with({
156 "command" => "/usr/bin/apt-key adv --keyserver #{param_hash[:key_server]} --recv-keys #{param_hash[:key]}",
157 "unless" => "/usr/bin/apt-key list | /bin/grep #{param_hash[:key]}",
158 "before" => "File[#{title}.list]"
164 describe "without release should raise a Puppet::Error" do
165 it { expect { should contain_apt__source(:release) }.to raise_error(Puppet::Error) }