ppa_spec.rb 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 'apt included, proxy' do
  65. let :pre_condition do
  66. 'class { "apt": proxy_host => "example.com" }'
  67. end
  68. let :facts do
  69. {
  70. :lsbdistrelease => '14.04',
  71. :lsbdistcodename => 'trusty',
  72. :operatingsystem => 'Ubuntu',
  73. :lsbdistid => 'Ubuntu',
  74. :osfamily => 'Debian',
  75. }
  76. end
  77. let :params do
  78. {
  79. 'release' => 'lucid',
  80. }
  81. end
  82. let(:title) { 'ppa:foo' }
  83. it { is_expected.to contain_package('software-properties-common') }
  84. it { is_expected.to contain_exec('add-apt-repository-ppa:foo').that_notifies('Exec[apt_update]').with({
  85. 'environment' => ['http_proxy=http://example.com:8080', 'https_proxy=http://example.com:8080'],
  86. 'command' => '/usr/bin/add-apt-repository -y ppa:foo',
  87. 'unless' => '/usr/bin/test -s /etc/apt/sources.list.d/foo-lucid.list',
  88. 'user' => 'root',
  89. 'logoutput' => 'on_failure',
  90. })
  91. }
  92. it { is_expected.to contain_file('/etc/apt/sources.list.d/foo-lucid.list').that_requires('Exec[add-apt-repository-ppa:foo]').with({
  93. 'ensure' => 'file',
  94. })
  95. }
  96. end
  97. describe 'ensure absent' do
  98. let :facts do
  99. {
  100. :lsbdistrelease => '14.04',
  101. :lsbdistcodename => 'trusty',
  102. :operatingsystem => 'Ubuntu',
  103. :lsbdistid => 'Ubuntu',
  104. :osfamily => 'Debian',
  105. }
  106. end
  107. let(:title) { 'ppa:foo' }
  108. let :params do
  109. {
  110. 'ensure' => 'absent'
  111. }
  112. end
  113. it { is_expected.to contain_file('/etc/apt/sources.list.d/foo-trusty.list').that_notifies('Exec[apt_update]').with({
  114. 'ensure' => 'absent',
  115. })
  116. }
  117. end
  118. context 'validation' do
  119. describe 'no release' do
  120. let :facts do
  121. {
  122. :lsbdistrelease => '14.04',
  123. :operatingsystem => 'Ubuntu',
  124. :lsbdistid => 'Ubuntu',
  125. :osfamily => 'Debian',
  126. }
  127. end
  128. let(:title) { 'ppa:foo' }
  129. it do
  130. expect {
  131. should compile
  132. }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/)
  133. end
  134. end
  135. describe 'not ubuntu' do
  136. let :facts do
  137. {
  138. :lsbdistrelease => '14.04',
  139. :lsbdistcodename => 'trusty',
  140. :operatingsystem => 'Debian',
  141. :lsbdistid => 'Ubuntu',
  142. :osfamily => 'Debian',
  143. }
  144. end
  145. let(:title) { 'ppa:foo' }
  146. it do
  147. expect {
  148. should compile
  149. }.to raise_error(Puppet::Error, /apt::ppa is currently supported on Ubuntu only./)
  150. end
  151. end
  152. end
  153. end