ppa_spec.rb 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. require 'spec_helper'
  2. describe 'apt::ppa', :type => :define do
  3. describe 'defaults' do
  4. let :pre_condition do
  5. 'class { "apt": }'
  6. end
  7. let :facts do
  8. {
  9. :lsbdistrelease => '11.04',
  10. :lsbdistcodename => 'natty',
  11. :operatingsystem => 'Ubuntu',
  12. :osfamily => 'Debian',
  13. :lsbdistid => 'Ubuntu',
  14. }
  15. end
  16. let(:title) { 'ppa:needs/such.substitution/wow' }
  17. it { is_expected.to contain_package('python-software-properties') }
  18. it { is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow').that_notifies('Exec[apt_update]').with({
  19. 'environment' => [],
  20. 'command' => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow',
  21. 'unless' => '/usr/bin/test -s /etc/apt/sources.list.d/needs-such_substitution-wow-natty.list',
  22. 'user' => 'root',
  23. 'logoutput' => 'on_failure',
  24. })
  25. }
  26. it { is_expected.to contain_file('/etc/apt/sources.list.d/needs-such_substitution-wow-natty.list').that_requires('Exec[add-apt-repository-ppa:needs/such.substitution/wow]').with({
  27. 'ensure' => 'file',
  28. })
  29. }
  30. end
  31. describe 'apt included, no proxy' do
  32. let :pre_condition do
  33. 'class { "apt": }'
  34. end
  35. let :facts do
  36. {
  37. :lsbdistrelease => '14.04',
  38. :lsbdistcodename => 'trusty',
  39. :operatingsystem => 'Ubuntu',
  40. :lsbdistid => 'Ubuntu',
  41. :osfamily => 'Debian',
  42. }
  43. end
  44. let :params do
  45. {
  46. 'options' => '',
  47. }
  48. end
  49. let(:title) { 'ppa:foo' }
  50. it { is_expected.to contain_package('software-properties-common') }
  51. it { is_expected.to contain_exec('add-apt-repository-ppa:foo').that_notifies('Exec[apt_update]').with({
  52. 'environment' => [],
  53. 'command' => '/usr/bin/add-apt-repository ppa:foo',
  54. 'unless' => '/usr/bin/test -s /etc/apt/sources.list.d/foo-trusty.list',
  55. 'user' => 'root',
  56. 'logoutput' => 'on_failure',
  57. })
  58. }
  59. it { is_expected.to contain_file('/etc/apt/sources.list.d/foo-trusty.list').that_requires('Exec[add-apt-repository-ppa:foo]').with({
  60. 'ensure' => 'file',
  61. })
  62. }
  63. end
  64. describe 'ensure absent' do
  65. let :facts do
  66. {
  67. :lsbdistrelease => '14.04',
  68. :lsbdistcodename => 'trusty',
  69. :operatingsystem => 'Ubuntu',
  70. :lsbdistid => 'Ubuntu',
  71. :osfamily => 'Debian',
  72. }
  73. end
  74. let(:title) { 'ppa:foo' }
  75. let :params do
  76. {
  77. 'ensure' => 'absent'
  78. }
  79. end
  80. it { is_expected.to contain_file('/etc/apt/sources.list.d/foo-trusty.list').that_notifies('Exec[apt_update]').with({
  81. 'ensure' => 'absent',
  82. })
  83. }
  84. end
  85. context 'validation' do
  86. describe 'no release' do
  87. let :facts do
  88. {
  89. :lsbdistrelease => '14.04',
  90. :operatingsystem => 'Ubuntu',
  91. :lsbdistid => 'Ubuntu',
  92. :osfamily => 'Debian',
  93. }
  94. end
  95. let(:title) { 'ppa:foo' }
  96. it do
  97. expect {
  98. should compile
  99. }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/)
  100. end
  101. end
  102. describe 'not ubuntu' do
  103. let :facts do
  104. {
  105. :lsbdistrelease => '14.04',
  106. :lsbdistcodename => 'trusty',
  107. :operatingsystem => 'Debian',
  108. :lsbdistid => 'Ubuntu',
  109. :osfamily => 'Debian',
  110. }
  111. end
  112. let(:title) { 'ppa:foo' }
  113. it do
  114. expect {
  115. should compile
  116. }.to raise_error(Puppet::Error, /apt::ppa is currently supported on Ubuntu only./)
  117. end
  118. end
  119. end
  120. end