apt_spec.rb 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. require 'spec_helper'
  2. describe 'apt', :type => :class do
  3. let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
  4. context 'defaults' do
  5. it { should contain_file('sources.list').that_notifies('Exec[apt_update]').only_with({
  6. 'ensure' => 'present',
  7. 'path' => '/etc/apt/sources.list',
  8. 'owner' => 'root',
  9. 'group' => 'root',
  10. 'mode' => '0644',
  11. 'notify' => 'Exec[apt_update]',
  12. })}
  13. it { should contain_file('sources.list.d').that_notifies('Exec[apt_update]').only_with({
  14. 'ensure' => 'directory',
  15. 'path' => '/etc/apt/sources.list.d',
  16. 'owner' => 'root',
  17. 'group' => 'root',
  18. 'purge' => false,
  19. 'recurse' => false,
  20. 'notify' => 'Exec[apt_update]',
  21. })}
  22. it { should contain_file('preferences.d').only_with({
  23. 'ensure' => 'directory',
  24. 'path' => '/etc/apt/preferences.d',
  25. 'owner' => 'root',
  26. 'group' => 'root',
  27. 'purge' => false,
  28. 'recurse' => false,
  29. })}
  30. it 'should lay down /etc/apt/apt.conf.d/15update-stamp' do
  31. should contain_file('/etc/apt/apt.conf.d/15update-stamp').with({
  32. 'group' => 'root',
  33. 'mode' => '0644',
  34. 'owner' => 'root',
  35. }).with_content(/APT::Update::Post-Invoke-Success \{"touch \/var\/lib\/apt\/periodic\/update-success-stamp 2>\/dev\/null \|\| true";\};/)
  36. end
  37. it { should contain_exec('apt_update').with({
  38. 'refreshonly' => 'true',
  39. })}
  40. end
  41. context 'lots of non-defaults' do
  42. let :params do
  43. {
  44. :always_apt_update => true,
  45. :purge_sources_list => true,
  46. :purge_sources_list_d => true,
  47. :purge_preferences => true,
  48. :purge_preferences_d => true,
  49. :update_timeout => '1',
  50. :update_tries => '3',
  51. }
  52. end
  53. it { should contain_file('sources.list').with({
  54. 'content' => "# Repos managed by puppet.\n"
  55. })}
  56. it { should contain_file('sources.list.d').with({
  57. 'purge' => 'true',
  58. 'recurse' => 'true',
  59. })}
  60. it { should contain_file('apt-preferences').only_with({
  61. 'ensure' => 'absent',
  62. 'path' => '/etc/apt/preferences',
  63. })}
  64. it { should contain_file('preferences.d').with({
  65. 'purge' => 'true',
  66. 'recurse' => 'true',
  67. })}
  68. it { should contain_exec('apt_update').with({
  69. 'refreshonly' => 'false',
  70. 'timeout' => '1',
  71. 'tries' => '3',
  72. })}
  73. end
  74. context 'with sources defined on valid osfamily' do
  75. let :facts do
  76. { :osfamily => 'Debian',
  77. :lsbdistcodename => 'precise',
  78. :lsbdistid => 'Debian',
  79. }
  80. end
  81. let(:params) { { :sources => {
  82. 'debian_unstable' => {
  83. 'location' => 'http://debian.mirror.iweb.ca/debian/',
  84. 'release' => 'unstable',
  85. 'repos' => 'main contrib non-free',
  86. 'required_packages' => 'debian-keyring debian-archive-keyring',
  87. 'key' => '55BE302B',
  88. 'key_server' => 'subkeys.pgp.net',
  89. 'pin' => '-10',
  90. 'include_src' => true
  91. },
  92. 'puppetlabs' => {
  93. 'location' => 'http://apt.puppetlabs.com',
  94. 'repos' => 'main',
  95. 'key' => '4BD6EC30',
  96. 'key_server' => 'pgp.mit.edu',
  97. }
  98. } } }
  99. it {
  100. should contain_file('debian_unstable.list').with({
  101. 'ensure' => 'present',
  102. 'path' => '/etc/apt/sources.list.d/debian_unstable.list',
  103. 'owner' => 'root',
  104. 'group' => 'root',
  105. 'mode' => '0644',
  106. 'notify' => 'Exec[apt_update]',
  107. })
  108. }
  109. it { should contain_file('debian_unstable.list').with_content(/^deb http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }
  110. it { should contain_file('debian_unstable.list').with_content(/^deb-src http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }
  111. it {
  112. should contain_file('puppetlabs.list').with({
  113. 'ensure' => 'present',
  114. 'path' => '/etc/apt/sources.list.d/puppetlabs.list',
  115. 'owner' => 'root',
  116. 'group' => 'root',
  117. 'mode' => '0644',
  118. 'notify' => 'Exec[apt_update]',
  119. })
  120. }
  121. it { should contain_file('puppetlabs.list').with_content(/^deb http:\/\/apt.puppetlabs.com precise main$/) }
  122. it { should contain_file('puppetlabs.list').with_content(/^deb-src http:\/\/apt.puppetlabs.com precise main$/) }
  123. end
  124. describe 'failing tests' do
  125. context 'bad purge_sources_list' do
  126. let :params do
  127. {
  128. 'purge_sources_list' => 'foo'
  129. }
  130. end
  131. it do
  132. expect {
  133. should compile
  134. }.to raise_error(Puppet::Error)
  135. end
  136. end
  137. context 'bad purge_sources_list_d' do
  138. let :params do
  139. {
  140. 'purge_sources_list_d' => 'foo'
  141. }
  142. end
  143. it do
  144. expect {
  145. should compile
  146. }.to raise_error(Puppet::Error)
  147. end
  148. end
  149. context 'bad purge_preferences' do
  150. let :params do
  151. {
  152. 'purge_preferences' => 'foo'
  153. }
  154. end
  155. it do
  156. expect {
  157. should compile
  158. }.to raise_error(Puppet::Error)
  159. end
  160. end
  161. context 'bad purge_preferences_d' do
  162. let :params do
  163. {
  164. 'purge_preferences_d' => 'foo'
  165. }
  166. end
  167. it do
  168. expect {
  169. should compile
  170. }.to raise_error(Puppet::Error)
  171. end
  172. end
  173. context 'with unsupported osfamily' do
  174. let :facts do
  175. { :osfamily => 'Darwin', }
  176. end
  177. it do
  178. expect {
  179. should compile
  180. }.to raise_error(Puppet::Error, /This module only works on Debian or derivatives like Ubuntu/)
  181. end
  182. end
  183. end
  184. end