source_spec.rb 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. require 'spec_helper'
  2. describe 'apt::source', :type => :define do
  3. GPG_KEY_ID = '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30'
  4. let :title do
  5. 'my_source'
  6. end
  7. context 'mostly defaults' do
  8. let :facts do
  9. {
  10. :lsbdistid => 'Debian',
  11. :lsbdistcodename => 'wheezy',
  12. :osfamily => 'Debian'
  13. }
  14. end
  15. let :params do
  16. {
  17. 'include_deb' => false,
  18. }
  19. end
  20. it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({
  21. 'ensure' => 'present',
  22. 'path' => '/etc/apt/sources.list.d/my_source.list',
  23. 'owner' => 'root',
  24. 'group' => 'root',
  25. 'mode' => '0644',
  26. }).with_content(/# my_source\ndeb-src wheezy main\n/)
  27. }
  28. end
  29. context 'no defaults' do
  30. let :facts do
  31. {
  32. :lsbdistid => 'Debian',
  33. :lsbdistcodename => 'wheezy',
  34. :osfamily => 'Debian'
  35. }
  36. end
  37. let :params do
  38. {
  39. 'comment' => 'foo',
  40. 'location' => 'http://debian.mirror.iweb.ca/debian/',
  41. 'release' => 'sid',
  42. 'repos' => 'testing',
  43. 'include_src' => false,
  44. 'required_packages' => 'vim',
  45. 'key' => GPG_KEY_ID,
  46. 'key_server' => 'pgp.mit.edu',
  47. 'key_content' => 'GPG key content',
  48. 'key_source' => 'http://apt.puppetlabs.com/pubkey.gpg',
  49. 'pin' => '10',
  50. 'architecture' => 'x86_64',
  51. 'trusted_source' => true,
  52. }
  53. end
  54. it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({
  55. 'ensure' => 'present',
  56. 'path' => '/etc/apt/sources.list.d/my_source.list',
  57. 'owner' => 'root',
  58. 'group' => 'root',
  59. 'mode' => '0644',
  60. }).with_content(/# foo\ndeb \[arch=x86_64 trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(/deb-src/)
  61. }
  62. it { is_expected.to contain_apt__pin('my_source').that_comes_before('File[my_source.list]').with({
  63. 'ensure' => 'present',
  64. 'priority' => '10',
  65. 'origin' => 'debian.mirror.iweb.ca',
  66. })
  67. }
  68. it { is_expected.to contain_exec("Required packages: 'vim' for my_source").that_comes_before('Exec[apt_update]').that_subscribes_to('File[my_source.list]').with({
  69. 'command' => '/usr/bin/apt-get -y install vim',
  70. 'logoutput' => 'on_failure',
  71. 'refreshonly' => true,
  72. 'tries' => '3',
  73. 'try_sleep' => '1',
  74. })
  75. }
  76. it { is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('File[my_source.list]').with({
  77. 'ensure' => 'present',
  78. 'key' => GPG_KEY_ID,
  79. 'key_server' => 'pgp.mit.edu',
  80. 'key_content' => 'GPG key content',
  81. 'key_source' => 'http://apt.puppetlabs.com/pubkey.gpg',
  82. })
  83. }
  84. end
  85. context 'trusted_source true' do
  86. let :facts do
  87. {
  88. :lsbdistid => 'Debian',
  89. :lsbdistcodename => 'wheezy',
  90. :osfamily => 'Debian'
  91. }
  92. end
  93. let :params do
  94. {
  95. 'include_src' => false,
  96. 'trusted_source' => true,
  97. }
  98. end
  99. it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({
  100. 'ensure' => 'present',
  101. 'path' => '/etc/apt/sources.list.d/my_source.list',
  102. 'owner' => 'root',
  103. 'group' => 'root',
  104. 'mode' => '0644',
  105. }).with_content(/# my_source\ndeb \[trusted=yes\] wheezy main\n/)
  106. }
  107. end
  108. context 'architecture equals x86_64' do
  109. let :facts do
  110. {
  111. :lsbdistid => 'Debian',
  112. :lsbdistcodename => 'wheezy',
  113. :osfamily => 'Debian'
  114. }
  115. end
  116. let :params do
  117. {
  118. 'include_deb' => false,
  119. 'architecture' => 'x86_64',
  120. }
  121. end
  122. it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({
  123. 'ensure' => 'present',
  124. 'path' => '/etc/apt/sources.list.d/my_source.list',
  125. 'owner' => 'root',
  126. 'group' => 'root',
  127. 'mode' => '0644',
  128. }).with_content(/# my_source\ndeb-src \[arch=x86_64 \] wheezy main\n/)
  129. }
  130. end
  131. context 'ensure => absent' do
  132. let :facts do
  133. {
  134. :lsbdistid => 'Debian',
  135. :lsbdistcodename => 'wheezy',
  136. :osfamily => 'Debian'
  137. }
  138. end
  139. let :params do
  140. {
  141. 'ensure' => 'absent',
  142. }
  143. end
  144. it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({
  145. 'ensure' => 'absent'
  146. })
  147. }
  148. end
  149. describe 'validation' do
  150. context 'no release' do
  151. let :facts do
  152. {
  153. :lsbdistid => 'Debian',
  154. :osfamily => 'Debian'
  155. }
  156. end
  157. it do
  158. expect {
  159. should compile
  160. }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/)
  161. end
  162. end
  163. end
  164. end