force_spec.rb 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. require 'spec_helper'
  2. describe 'apt::force', :type => :define do
  3. let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
  4. let :pre_condition do
  5. 'include apt::params'
  6. end
  7. let :title do
  8. 'my_package'
  9. end
  10. let :default_params do
  11. {
  12. :release => false,
  13. :version => false,
  14. :cfg_files => 'none',
  15. :cfg_missing => false,
  16. }
  17. end
  18. describe "when using default parameters" do
  19. it { should contain_exec("/usr/bin/apt-get -y install #{title}").with(
  20. :unless => "/usr/bin/dpkg -s #{title} | grep -q 'Status: install'",
  21. :logoutput => 'on_failure',
  22. :timeout => '300'
  23. ) }
  24. end
  25. describe "when specifying release parameter" do
  26. let :params do
  27. default_params.merge(:release => 'testing')
  28. end
  29. it { should contain_exec("/usr/bin/apt-get -y -t #{params[:release]} install #{title}").with(
  30. :unless => "/usr/bin/test \$(/usr/bin/apt-cache policy -t #{params[:release]} #{title} | /bin/grep -E 'Installed|Candidate' | /usr/bin/uniq -s 14 | /usr/bin/wc -l) -eq 1"
  31. ) }
  32. end
  33. describe "when specifying version parameter" do
  34. let :params do
  35. default_params.merge(:version => '1')
  36. end
  37. it { should contain_exec("/usr/bin/apt-get -y install #{title}=#{params[:version]}").with(
  38. :unless => "/usr/bin/dpkg -s #{title} | grep -q 'Version: #{params[:version]}'"
  39. ) }
  40. end
  41. describe "when specifying cfg_files parameter" do
  42. let :params do
  43. default_params.merge(:cfg_files => 'unchanged')
  44. end
  45. it { should contain_exec('/usr/bin/apt-get -y -o Dpkg::Options::="--force-confdef" install my_package').with(
  46. :unless => "/usr/bin/dpkg -s #{title} | grep -q 'Status: install'"
  47. ) }
  48. end
  49. describe "when specifying cfg_missing parameter" do
  50. let :params do
  51. default_params.merge(:cfg_missing => true)
  52. end
  53. it { should contain_exec('/usr/bin/apt-get -y -o Dpkg::Options::="--force-confmiss" install my_package').with(
  54. :unless => "/usr/bin/dpkg -s #{title} | grep -q 'Status: install'"
  55. ) }
  56. end
  57. describe "when specifying cfg_files and cfg_missing parameter" do
  58. let :params do
  59. default_params.merge(
  60. :cfg_files => 'unchanged',
  61. :cfg_missing => true
  62. )
  63. end
  64. it { should contain_exec('/usr/bin/apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confmiss" install my_package').with(
  65. :unless => "/usr/bin/dpkg -s #{title} | grep -q 'Status: install'"
  66. ) }
  67. end
  68. describe "when specifying release and version parameters" do
  69. let :params do
  70. default_params.merge(
  71. :release => 'testing',
  72. :version => '1'
  73. )
  74. end
  75. it { should contain_exec("/usr/bin/apt-get -y -t #{params[:release]} install #{title}=1").with(
  76. :unless => "/usr/bin/apt-cache policy -t #{params[:release]} #{title} | /bin/grep -q 'Installed: #{params[:version]}'"
  77. ) }
  78. end
  79. describe "when specifying release, version, cfg_files and cfg_missing parameters" do
  80. let :params do
  81. default_params.merge(
  82. :release => 'testing',
  83. :version => '1',
  84. :cfg_files => 'unchanged',
  85. :cfg_missing => true
  86. )
  87. end
  88. it { should contain_exec('/usr/bin/apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confmiss" -t testing install my_package=1').with(
  89. :unless => "/usr/bin/apt-cache policy -t #{params[:release]} #{title} | /bin/grep -q 'Installed: #{params[:version]}'"
  90. ) }
  91. end
  92. end