apt_spec.rb 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. require 'spec_helper'
  2. describe 'apt' do
  3. let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :puppetversion => Puppet.version} }
  4. context 'defaults' do
  5. it { is_expected.to contain_file('sources.list').that_notifies('Class[Apt::Update]').only_with({
  6. :ensure => 'file',
  7. :path => '/etc/apt/sources.list',
  8. :owner => 'root',
  9. :group => 'root',
  10. :mode => '0644',
  11. :notify => 'Class[Apt::Update]',
  12. })}
  13. it { is_expected.to contain_file('sources.list.d').that_notifies('Class[Apt::Update]').only_with({
  14. :ensure => 'directory',
  15. :path => '/etc/apt/sources.list.d',
  16. :owner => 'root',
  17. :group => 'root',
  18. :mode => '0644',
  19. :purge => false,
  20. :recurse => false,
  21. :notify => 'Class[Apt::Update]',
  22. })}
  23. it { is_expected.to contain_file('preferences').that_notifies('Class[Apt::Update]').only_with({
  24. :ensure => 'file',
  25. :path => '/etc/apt/preferences',
  26. :owner => 'root',
  27. :group => 'root',
  28. :mode => '0644',
  29. :notify => 'Class[Apt::Update]',
  30. })}
  31. it { is_expected.to contain_file('preferences.d').that_notifies('Class[Apt::Update]').only_with({
  32. :ensure => 'directory',
  33. :path => '/etc/apt/preferences.d',
  34. :owner => 'root',
  35. :group => 'root',
  36. :mode => '0644',
  37. :purge => false,
  38. :recurse => false,
  39. :notify => 'Class[Apt::Update]',
  40. })}
  41. it 'should lay down /etc/apt/apt.conf.d/15update-stamp' do
  42. is_expected.to contain_file('/etc/apt/apt.conf.d/15update-stamp').with({
  43. :group => 'root',
  44. :mode => '0644',
  45. :owner => 'root',
  46. }).with_content(/APT::Update::Post-Invoke-Success \{"touch \/var\/lib\/apt\/periodic\/update-success-stamp 2>\/dev\/null \|\| true";\};/)
  47. end
  48. it { is_expected.to contain_exec('apt_update').with({
  49. :refreshonly => 'true',
  50. })}
  51. it { is_expected.not_to contain_apt__setting('conf-proxy') }
  52. end
  53. describe 'proxy=' do
  54. context 'host=localhost' do
  55. let(:params) { { :proxy => { 'host' => 'localhost'} } }
  56. it { is_expected.to contain_apt__setting('conf-proxy').with({
  57. :priority => '01',
  58. }).with_content(
  59. /Acquire::http::proxy "http:\/\/localhost:8080\/";/
  60. ).without_content(
  61. /Acquire::https::proxy/
  62. )}
  63. end
  64. context 'host=localhost and port=8180' do
  65. let(:params) { { :proxy => { 'host' => 'localhost', 'port' => 8180} } }
  66. it { is_expected.to contain_apt__setting('conf-proxy').with({
  67. :priority => '01',
  68. }).with_content(
  69. /Acquire::http::proxy "http:\/\/localhost:8180\/";/
  70. ).without_content(
  71. /Acquire::https::proxy/
  72. )}
  73. end
  74. context 'host=localhost and https=true' do
  75. let(:params) { { :proxy => { 'host' => 'localhost', 'https' => true} } }
  76. it { is_expected.to contain_apt__setting('conf-proxy').with({
  77. :priority => '01',
  78. }).with_content(
  79. /Acquire::http::proxy "http:\/\/localhost:8080\/";/
  80. ).with_content(
  81. /Acquire::https::proxy "https:\/\/localhost:8080\/";/
  82. )}
  83. end
  84. context 'ensure=absent' do
  85. let(:params) { { :proxy => { 'ensure' => 'absent'} } }
  86. it { is_expected.to contain_apt__setting('conf-proxy').with({
  87. :ensure => 'absent',
  88. :priority => '01',
  89. })}
  90. end
  91. end
  92. context 'lots of non-defaults' do
  93. let :params do
  94. {
  95. :update => { 'frequency' => 'always', 'timeout' => 1, 'tries' => 3 },
  96. :purge => { 'sources.list' => false, 'sources.list.d' => false,
  97. 'preferences' => false, 'preferences.d' => false, },
  98. }
  99. end
  100. it { is_expected.to contain_file('sources.list').with({
  101. :content => nil,
  102. })}
  103. it { is_expected.to contain_file('sources.list.d').with({
  104. :purge => false,
  105. :recurse => false,
  106. })}
  107. it { is_expected.to contain_file('preferences').with({
  108. :ensure => 'file',
  109. })}
  110. it { is_expected.to contain_file('preferences.d').with({
  111. :purge => false,
  112. :recurse => false,
  113. })}
  114. it { is_expected.to contain_exec('apt_update').with({
  115. :refreshonly => false,
  116. :timeout => 1,
  117. :tries => 3,
  118. })}
  119. end
  120. context 'with sources defined on valid osfamily' do
  121. let :facts do
  122. { :osfamily => 'Debian',
  123. :lsbdistcodename => 'precise',
  124. :lsbdistid => 'Debian',
  125. :puppetversion => Puppet.version,
  126. }
  127. end
  128. let(:params) { { :sources => {
  129. 'debian_unstable' => {
  130. 'location' => 'http://debian.mirror.iweb.ca/debian/',
  131. 'release' => 'unstable',
  132. 'repos' => 'main contrib non-free',
  133. 'key' => { 'id' => '150C8614919D8446E01E83AF9AA38DCD55BE302B', 'server' => 'subkeys.pgp.net' },
  134. 'pin' => '-10',
  135. 'include' => {'src' => true,},
  136. },
  137. 'puppetlabs' => {
  138. 'location' => 'http://apt.puppetlabs.com',
  139. 'repos' => 'main',
  140. 'key' => { 'id' => '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30', 'server' => 'pgp.mit.edu' },
  141. }
  142. } } }
  143. it {
  144. is_expected.to contain_apt__setting('list-debian_unstable').with({
  145. :ensure => 'present',
  146. })
  147. }
  148. it { is_expected.to contain_file('/etc/apt/sources.list.d/debian_unstable.list').with_content(/^deb http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }
  149. it { is_expected.to contain_file('/etc/apt/sources.list.d/debian_unstable.list').with_content(/^deb-src http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }
  150. it {
  151. is_expected.to contain_apt__setting('list-puppetlabs').with({
  152. :ensure => 'present',
  153. })
  154. }
  155. it { is_expected.to contain_file('/etc/apt/sources.list.d/puppetlabs.list').with_content(/^deb http:\/\/apt.puppetlabs.com precise main$/) }
  156. end
  157. context 'with keys defined on valid osfamily' do
  158. let :facts do
  159. { :osfamily => 'Debian',
  160. :lsbdistcodename => 'precise',
  161. :lsbdistid => 'Debian',
  162. :puppetversion => Puppet.version,
  163. }
  164. end
  165. let(:params) { { :keys => {
  166. '55BE302B' => {
  167. 'server' => 'subkeys.pgp.net',
  168. },
  169. '4BD6EC30' => {
  170. 'server' => 'pgp.mit.edu',
  171. }
  172. } } }
  173. it { is_expected.to contain_apt__key('55BE302B').with({
  174. :server => 'subkeys.pgp.net',
  175. })}
  176. it { is_expected.to contain_apt__key('4BD6EC30').with({
  177. :server => 'pgp.mit.edu',
  178. })}
  179. end
  180. context 'with ppas defined on valid osfamily' do
  181. let :facts do
  182. { :osfamily => 'Debian',
  183. :lsbdistcodename => 'precise',
  184. :lsbdistid => 'ubuntu',
  185. :lsbdistrelease => '12.04',
  186. :puppetversion => Puppet.version,
  187. }
  188. end
  189. let(:params) { { :ppas => {
  190. 'ppa:drizzle-developers/ppa' => {},
  191. 'ppa:nginx/stable' => {},
  192. } } }
  193. it { is_expected.to contain_apt__ppa('ppa:drizzle-developers/ppa')}
  194. it { is_expected.to contain_apt__ppa('ppa:nginx/stable')}
  195. end
  196. context 'with settings defined on valid osfamily' do
  197. let :facts do
  198. { :osfamily => 'Debian',
  199. :lsbdistcodename => 'precise',
  200. :lsbdistid => 'Debian',
  201. :puppetversion => Puppet.version,
  202. }
  203. end
  204. let(:params) { { :settings => {
  205. 'conf-banana' => { 'content' => 'banana' },
  206. 'pref-banana' => { 'content' => 'banana' },
  207. } } }
  208. it { is_expected.to contain_apt__setting('conf-banana')}
  209. it { is_expected.to contain_apt__setting('pref-banana')}
  210. end
  211. context 'with pins defined on valid osfamily' do
  212. let :facts do
  213. { :osfamily => 'Debian',
  214. :lsbdistcodename => 'precise',
  215. :lsbdistid => 'Debian',
  216. :puppetversion => Puppet.version,
  217. }
  218. end
  219. let(:params) { { :pins => {
  220. 'stable' => { 'priority' => 600, 'order' => 50 },
  221. 'testing' => { 'priority' => 700, 'order' => 100 },
  222. } } }
  223. it { is_expected.to contain_apt__pin('stable') }
  224. it { is_expected.to contain_apt__pin('testing') }
  225. end
  226. describe 'failing tests' do
  227. context "purge['sources.list']=>'banana'" do
  228. let(:params) { { :purge => { 'sources.list' => 'banana' }, } }
  229. it do
  230. expect {
  231. subject.call
  232. }.to raise_error(Puppet::Error)
  233. end
  234. end
  235. context "purge['sources.list.d']=>'banana'" do
  236. let(:params) { { :purge => { 'sources.list.d' => 'banana' }, } }
  237. it do
  238. expect {
  239. subject.call
  240. }.to raise_error(Puppet::Error)
  241. end
  242. end
  243. context "purge['preferences']=>'banana'" do
  244. let(:params) { { :purge => { 'preferences' => 'banana' }, } }
  245. it do
  246. expect {
  247. subject.call
  248. }.to raise_error(Puppet::Error)
  249. end
  250. end
  251. context "purge['preferences.d']=>'banana'" do
  252. let(:params) { { :purge => { 'preferences.d' => 'banana' }, } }
  253. it do
  254. expect {
  255. subject.call
  256. }.to raise_error(Puppet::Error)
  257. end
  258. end
  259. context 'with unsupported osfamily' do
  260. let :facts do
  261. { :osfamily => 'Darwin', :puppetversion => Puppet.version,}
  262. end
  263. it do
  264. expect {
  265. subject.call
  266. }.to raise_error(Puppet::Error, /This module only works on Debian or derivatives like Ubuntu/)
  267. end
  268. end
  269. end
  270. end