ppa_spec.rb 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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 'package_name => software-properties-common' do
  32. let :pre_condition do
  33. 'class { "apt": }'
  34. end
  35. let :params do
  36. {
  37. :package_name => 'software-properties-common'
  38. }
  39. end
  40. let :facts do
  41. {
  42. :lsbdistrelease => '11.04',
  43. :lsbdistcodename => 'natty',
  44. :operatingsystem => 'Ubuntu',
  45. :osfamily => 'Debian',
  46. :lsbdistid => 'Ubuntu',
  47. }
  48. end
  49. let(:title) { 'ppa:needs/such.substitution/wow' }
  50. it { is_expected.to contain_package('software-properties-common') }
  51. it { is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow').that_notifies('Exec[apt_update]').with({
  52. 'environment' => [],
  53. 'command' => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow',
  54. 'unless' => '/usr/bin/test -s /etc/apt/sources.list.d/needs-such_substitution-wow-natty.list',
  55. 'user' => 'root',
  56. 'logoutput' => 'on_failure',
  57. })
  58. }
  59. 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({
  60. 'ensure' => 'file',
  61. })
  62. }
  63. end
  64. describe 'package_manage => false' do
  65. let :pre_condition do
  66. 'class { "apt": }'
  67. end
  68. let :facts do
  69. {
  70. :lsbdistrelease => '11.04',
  71. :lsbdistcodename => 'natty',
  72. :operatingsystem => 'Ubuntu',
  73. :osfamily => 'Debian',
  74. :lsbdistid => 'Ubuntu',
  75. }
  76. end
  77. let :params do
  78. {
  79. :package_manage => false,
  80. }
  81. end
  82. let(:title) { 'ppa:needs/such.substitution/wow' }
  83. it { is_expected.to_not contain_package('python-software-properties') }
  84. it { is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow').that_notifies('Exec[apt_update]').with({
  85. 'environment' => [],
  86. 'command' => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow',
  87. 'unless' => '/usr/bin/test -s /etc/apt/sources.list.d/needs-such_substitution-wow-natty.list',
  88. 'user' => 'root',
  89. 'logoutput' => 'on_failure',
  90. })
  91. }
  92. 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({
  93. 'ensure' => 'file',
  94. })
  95. }
  96. end
  97. describe 'apt included, no proxy' do
  98. let :pre_condition do
  99. 'class { "apt": }'
  100. end
  101. let :facts do
  102. {
  103. :lsbdistrelease => '14.04',
  104. :lsbdistcodename => 'trusty',
  105. :operatingsystem => 'Ubuntu',
  106. :lsbdistid => 'Ubuntu',
  107. :osfamily => 'Debian',
  108. }
  109. end
  110. let :params do
  111. {
  112. 'options' => '',
  113. }
  114. end
  115. let(:title) { 'ppa:foo' }
  116. it { is_expected.to contain_package('software-properties-common') }
  117. it { is_expected.to contain_exec('add-apt-repository-ppa:foo').that_notifies('Exec[apt_update]').with({
  118. 'environment' => [],
  119. 'command' => '/usr/bin/add-apt-repository ppa:foo',
  120. 'unless' => '/usr/bin/test -s /etc/apt/sources.list.d/foo-trusty.list',
  121. 'user' => 'root',
  122. 'logoutput' => 'on_failure',
  123. })
  124. }
  125. it { is_expected.to contain_file('/etc/apt/sources.list.d/foo-trusty.list').that_requires('Exec[add-apt-repository-ppa:foo]').with({
  126. 'ensure' => 'file',
  127. })
  128. }
  129. end
  130. describe 'apt included, proxy' do
  131. let :pre_condition do
  132. 'class { "apt": proxy_host => "example.com" }'
  133. end
  134. let :facts do
  135. {
  136. :lsbdistrelease => '14.04',
  137. :lsbdistcodename => 'trusty',
  138. :operatingsystem => 'Ubuntu',
  139. :lsbdistid => 'Ubuntu',
  140. :osfamily => 'Debian',
  141. }
  142. end
  143. let :params do
  144. {
  145. 'release' => 'lucid',
  146. }
  147. end
  148. let(:title) { 'ppa:foo' }
  149. it { is_expected.to contain_package('software-properties-common') }
  150. it { is_expected.to contain_exec('add-apt-repository-ppa:foo').that_notifies('Exec[apt_update]').with({
  151. 'environment' => ['http_proxy=http://example.com:8080', 'https_proxy=http://example.com:8080'],
  152. 'command' => '/usr/bin/add-apt-repository -y ppa:foo',
  153. 'unless' => '/usr/bin/test -s /etc/apt/sources.list.d/foo-lucid.list',
  154. 'user' => 'root',
  155. 'logoutput' => 'on_failure',
  156. })
  157. }
  158. it { is_expected.to contain_file('/etc/apt/sources.list.d/foo-lucid.list').that_requires('Exec[add-apt-repository-ppa:foo]').with({
  159. 'ensure' => 'file',
  160. })
  161. }
  162. end
  163. describe 'ensure absent' do
  164. let :facts do
  165. {
  166. :lsbdistrelease => '14.04',
  167. :lsbdistcodename => 'trusty',
  168. :operatingsystem => 'Ubuntu',
  169. :lsbdistid => 'Ubuntu',
  170. :osfamily => 'Debian',
  171. }
  172. end
  173. let(:title) { 'ppa:foo' }
  174. let :params do
  175. {
  176. 'ensure' => 'absent'
  177. }
  178. end
  179. it { is_expected.to contain_file('/etc/apt/sources.list.d/foo-trusty.list').that_notifies('Exec[apt_update]').with({
  180. 'ensure' => 'absent',
  181. })
  182. }
  183. end
  184. context 'validation' do
  185. describe 'no release' do
  186. let :facts do
  187. {
  188. :lsbdistrelease => '14.04',
  189. :operatingsystem => 'Ubuntu',
  190. :lsbdistid => 'Ubuntu',
  191. :osfamily => 'Debian',
  192. }
  193. end
  194. let(:title) { 'ppa:foo' }
  195. it do
  196. expect {
  197. should compile
  198. }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/)
  199. end
  200. end
  201. describe 'not ubuntu' do
  202. let :facts do
  203. {
  204. :lsbdistrelease => '14.04',
  205. :lsbdistcodename => 'trusty',
  206. :operatingsystem => 'Debian',
  207. :lsbdistid => 'Ubuntu',
  208. :osfamily => 'Debian',
  209. }
  210. end
  211. let(:title) { 'ppa:foo' }
  212. it do
  213. expect {
  214. should compile
  215. }.to raise_error(Puppet::Error, /apt::ppa is currently supported on Ubuntu only./)
  216. end
  217. end
  218. end
  219. end