2 describe 'apt::key', :type => :define do
11 :key_server => "keyserver.ubuntu.com",
25 :key_source => 'ftp://ftp.example.org/key',
28 :key_content => 'deadbeef',
33 default_params.merge(param_set)
42 str << param_hash[:key].to_s << '/'
43 str << param_hash[:key_content].to_s << '/'
44 str << param_hash[:key_source].to_s << '/'
45 str << param_hash[:key_server].to_s << '/'
46 Digest::SHA1.hexdigest(str)
49 describe "when #{param_set == {} ? "using default" : "specifying"} define parameters" do
52 if [:present, 'present', :absent, 'absent'].include? param_hash[:ensure]
53 should contain_apt__params
58 if [:present, 'present'].include? param_hash[:ensure]
59 should_not contain_exec("apt::key #{param_hash[:key]} absent")
60 should contain_exec("apt::key #{param_hash[:key]} present")
61 should contain_exec(digest).with({
62 "path" => "/bin:/usr/bin",
63 "unless" => "/usr/bin/apt-key list | /bin/grep '#{param_hash[:key]}'"
65 elsif [:absent, 'absent'].include? param_hash[:ensure]
66 should_not contain_exec("apt::key #{param_hash[:key]} present")
67 should contain_exec("apt::key #{param_hash[:key]} absent").with({
68 "path" => "/bin:/usr/bin",
69 "onlyif" => "apt-key list | grep '#{param_hash[:key]}'",
70 "command" => "apt-key del '#{param_hash[:key]}'"
73 expect { should raise_error(Puppet::Error) }
78 if [:present, 'present'].include? param_hash[:ensure]
79 if param_hash[:key_content]
80 should contain_exec(digest).with({
81 "command" => "echo '#{param_hash[:key_content]}' | /usr/bin/apt-key add -"
83 elsif param_hash[:key_source]
84 should contain_exec(digest).with({
85 "command" => "wget -q '#{param_hash[:key_source]}' -O- | apt-key add -"
87 elsif param_hash[:key_server]
88 should contain_exec(digest).with({
89 "command" => "apt-key adv --keyserver '#{param_hash[:key_server]}' --recv-keys '#{param_hash[:key]}'"
97 describe "should correctly handle duplicate definitions" do
99 "apt::key { 'duplicate': key => '#{params[:key]}'; }"
103 if [:present, 'present'].include? param_hash[:ensure]
104 should contain_exec("apt::key #{param_hash[:key]} present")
105 should contain_apt__key("duplicate")
106 should contain_apt__key(title)
107 elsif [:absent, 'absent'].include? params[:ensure]
108 expect { should raise_error(Puppet::Error) }