X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=spec%2Fdefines%2Fkey_spec.rb;h=aea197a7b2baf5c4a5668bb95ebe7278d75af404;hb=d0b8ed8f64e413b4d33eaa6b9ce06dd197f1e9b1;hp=88038d27833fd64573a38c4f38f5fe48bd2ef6aa;hpb=8cdaf855a1d0dd24fed02fc3ee9941e0a1e6849b;p=puppet-modules%2Fpuppetlabs-apt.git diff --git a/spec/defines/key_spec.rb b/spec/defines/key_spec.rb index 88038d2..aea197a 100644 --- a/spec/defines/key_spec.rb +++ b/spec/defines/key_spec.rb @@ -30,7 +30,9 @@ describe 'apt::key', :type => :define do ].each do |param_set| let :param_hash do - default_params.merge(param_set) + param_hash = default_params.merge(param_set) + param_hash[:key].upcase! if param_hash[:key] + param_hash end let :params do @@ -57,13 +59,13 @@ describe 'apt::key', :type => :define do it { if [:present, 'present'].include? param_hash[:ensure] should_not contain_exec("apt::key #{param_hash[:key]} absent") - should contain_exec("apt::key #{param_hash[:key]} present") + should contain_anchor("apt::key #{param_hash[:key]} present") should contain_exec(digest).with({ "path" => "/bin:/usr/bin", "unless" => "/usr/bin/apt-key list | /bin/grep '#{param_hash[:key]}'" }) elsif [:absent, 'absent'].include? param_hash[:ensure] - should_not contain_exec("apt::key #{param_hash[:key]} present") + should_not contain_anchor("apt::key #{param_hash[:key]} present") should contain_exec("apt::key #{param_hash[:key]} absent").with({ "path" => "/bin:/usr/bin", "onlyif" => "apt-key list | grep '#{param_hash[:key]}'", @@ -93,22 +95,29 @@ describe 'apt::key', :type => :define do } end + end + [{ :ensure => 'present' }, { :ensure => 'absent' }].each do |param_set| describe "should correctly handle duplicate definitions" do + let :pre_condition do - "apt::key { 'duplicate': key => '#{params[:key]}'; }" + "apt::key { 'duplicate': key => '#{title}'; }" end + let(:params) { param_set } + it { - if [:present, 'present'].include? param_hash[:ensure] - should contain_exec("apt::key #{param_hash[:key]} present") - should contain_apt__key("duplicate") + if param_set[:ensure] == 'present' + should contain_anchor("apt::key #{title} present") should contain_apt__key(title) - elsif [:absent, 'absent'].include? params[:ensure] + should contain_apt__key("duplicate") + elsif param_set[:ensure] == 'absent' expect { should raise_error(Puppet::Error) } end } end end + end +