2 describe 'apt::key', :type => :define do
3 let(:facts) { { :lsbdistid => 'Debian' } }
12 :key_server => "keyserver.ubuntu.com",
26 :key_source => 'ftp://ftp.example.org/key',
29 :key_content => 'deadbeef',
34 param_hash = default_params.merge(param_set)
35 param_hash[:key].upcase! if param_hash[:key]
45 str << param_hash[:key].to_s << '/'
46 str << param_hash[:key_content].to_s << '/'
47 str << param_hash[:key_source].to_s << '/'
48 str << param_hash[:key_server].to_s << '/'
49 Digest::SHA1.hexdigest(str)
52 describe "when #{param_set == {} ? "using default" : "specifying"} define parameters" do
55 if [:present, 'present', :absent, 'absent'].include? param_hash[:ensure]
56 should contain_apt__params
61 if [:present, 'present'].include? param_hash[:ensure]
62 should_not contain_exec("apt::key #{param_hash[:key]} absent")
63 should contain_anchor("apt::key #{param_hash[:key]} present")
64 should contain_exec(digest).with({
65 "path" => "/bin:/usr/bin",
66 "unless" => "/usr/bin/apt-key list | /bin/grep '#{param_hash[:key]}'"
68 elsif [:absent, 'absent'].include? param_hash[:ensure]
69 should_not contain_anchor("apt::key #{param_hash[:key]} present")
70 should contain_exec("apt::key #{param_hash[:key]} absent").with({
71 "path" => "/bin:/usr/bin",
72 "onlyif" => "apt-key list | grep '#{param_hash[:key]}'",
73 "command" => "apt-key del '#{param_hash[:key]}'"
76 expect { should raise_error(Puppet::Error) }
81 if [:present, 'present'].include? param_hash[:ensure]
82 if param_hash[:key_content]
83 should contain_exec(digest).with({
84 "command" => "echo '#{param_hash[:key_content]}' | /usr/bin/apt-key add -"
86 elsif param_hash[:key_source]
87 should contain_exec(digest).with({
88 "command" => "wget -q '#{param_hash[:key_source]}' -O- | apt-key add -"
90 elsif param_hash[:key_server]
91 should contain_exec(digest).with({
92 "command" => "apt-key adv --keyserver '#{param_hash[:key_server]}' --recv-keys '#{param_hash[:key]}'"
101 [{ :ensure => 'present' }, { :ensure => 'absent' }].each do |param_set|
102 describe "should correctly handle duplicate definitions" do
104 let :pre_condition do
105 "apt::key { 'duplicate': key => '#{title}'; }"
108 let(:params) { param_set }
111 if param_set[:ensure] == 'present'
112 should contain_anchor("apt::key #{title} present")
113 should contain_apt__key(title)
114 should contain_apt__key("duplicate")
115 elsif param_set[:ensure] == 'absent'
116 expect { should raise_error(Puppet::Error) }