apt_backports_spec.rb 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. #!/usr/bin/env rspec
  2. require 'spec_helper'
  3. describe 'apt::backports', :type => :class do
  4. let (:pre_condition) { "class{ '::apt': }" }
  5. describe 'debian/ubuntu tests' do
  6. context 'defaults on deb' do
  7. let(:facts) do
  8. {
  9. :lsbdistid => 'Debian',
  10. :osfamily => 'Debian',
  11. :lsbdistcodename => 'wheezy',
  12. :puppetversion => Puppet.version,
  13. }
  14. end
  15. it { is_expected.to contain_apt__source('backports').with({
  16. :location => 'http://httpredir.debian.org/debian',
  17. :key => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
  18. :repos => 'main contrib non-free',
  19. :release => 'wheezy-backports',
  20. :pin => { 'priority' => 200, 'release' => 'wheezy-backports' },
  21. })
  22. }
  23. end
  24. context 'defaults on squeeze' do
  25. let(:facts) do
  26. {
  27. :lsbdistid => 'Debian',
  28. :osfamily => 'Debian',
  29. :lsbdistcodename => 'squeeze',
  30. :puppetversion => Puppet.version,
  31. }
  32. end
  33. it { is_expected.to contain_apt__source('backports').with({
  34. :location => 'http://httpredir.debian.org/debian-backports',
  35. :key => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
  36. :repos => 'main contrib non-free',
  37. :release => 'squeeze-backports',
  38. :pin => { 'priority' => 200, 'release' => 'squeeze-backports' },
  39. })
  40. }
  41. end
  42. context 'defaults on ubuntu' do
  43. let(:facts) do
  44. {
  45. :lsbdistid => 'Ubuntu',
  46. :osfamily => 'Debian',
  47. :lsbdistcodename => 'trusty',
  48. :puppetversion => Puppet.version,
  49. }
  50. end
  51. it { is_expected.to contain_apt__source('backports').with({
  52. :location => 'http://archive.ubuntu.com/ubuntu',
  53. :key => '630239CC130E1A7FD81A27B140976EAF437D05B5',
  54. :repos => 'main universe multiverse restricted',
  55. :release => 'trusty-backports',
  56. :pin => { 'priority' => 200, 'release' => 'trusty-backports' },
  57. })
  58. }
  59. end
  60. context 'set everything' do
  61. let(:facts) do
  62. {
  63. :lsbdistid => 'Ubuntu',
  64. :osfamily => 'Debian',
  65. :lsbdistcodename => 'trusty',
  66. :puppetversion => Puppet.version,
  67. }
  68. end
  69. let(:params) do
  70. {
  71. :location => 'http://archive.ubuntu.com/ubuntu-test',
  72. :release => 'vivid',
  73. :repos => 'main',
  74. :key => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
  75. :pin => '90',
  76. }
  77. end
  78. it { is_expected.to contain_apt__source('backports').with({
  79. :location => 'http://archive.ubuntu.com/ubuntu-test',
  80. :key => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
  81. :repos => 'main',
  82. :release => 'vivid',
  83. :pin => { 'priority' => 90, 'release' => 'vivid' },
  84. })
  85. }
  86. end
  87. context 'set things with hashes' do
  88. let(:facts) do
  89. {
  90. :lsbdistid => 'Ubuntu',
  91. :osfamily => 'Debian',
  92. :lsbdistcodename => 'trusty',
  93. :puppetversion => Puppet.version,
  94. }
  95. end
  96. let(:params) do
  97. {
  98. :key => {
  99. 'id' => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
  100. },
  101. :pin => {
  102. 'priority' => '90',
  103. },
  104. }
  105. end
  106. it { is_expected.to contain_apt__source('backports').with({
  107. :key => { 'id' => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553' },
  108. :pin => { 'priority' => '90' },
  109. })
  110. }
  111. end
  112. end
  113. describe 'mint tests' do
  114. let(:facts) do
  115. {
  116. :lsbdistid => 'linuxmint',
  117. :osfamily => 'Debian',
  118. :lsbdistcodename => 'qiana',
  119. :puppetversion => Puppet.version,
  120. }
  121. end
  122. context 'sets all the needed things' do
  123. let(:params) do
  124. {
  125. :location => 'http://archive.ubuntu.com/ubuntu',
  126. :release => 'trusty-backports',
  127. :repos => 'main universe multiverse restricted',
  128. :key => '630239CC130E1A7FD81A27B140976EAF437D05B5',
  129. }
  130. end
  131. it { is_expected.to contain_apt__source('backports').with({
  132. :location => 'http://archive.ubuntu.com/ubuntu',
  133. :key => '630239CC130E1A7FD81A27B140976EAF437D05B5',
  134. :repos => 'main universe multiverse restricted',
  135. :release => 'trusty-backports',
  136. :pin => { 'priority' => 200, 'release' => 'trusty-backports' },
  137. })
  138. }
  139. end
  140. context 'missing location' do
  141. let(:params) do
  142. {
  143. :release => 'trusty-backports',
  144. :repos => 'main universe multiverse restricted',
  145. :key => '630239CC130E1A7FD81A27B140976EAF437D05B5',
  146. }
  147. end
  148. it do
  149. expect {
  150. subject.call
  151. }.to raise_error(Puppet::Error, /If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key/)
  152. end
  153. end
  154. context 'missing release' do
  155. let(:params) do
  156. {
  157. :location => 'http://archive.ubuntu.com/ubuntu',
  158. :repos => 'main universe multiverse restricted',
  159. :key => '630239CC130E1A7FD81A27B140976EAF437D05B5',
  160. }
  161. end
  162. it do
  163. expect {
  164. subject.call
  165. }.to raise_error(Puppet::Error, /If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key/)
  166. end
  167. end
  168. context 'missing repos' do
  169. let(:params) do
  170. {
  171. :location => 'http://archive.ubuntu.com/ubuntu',
  172. :release => 'trusty-backports',
  173. :key => '630239CC130E1A7FD81A27B140976EAF437D05B5',
  174. }
  175. end
  176. it do
  177. expect {
  178. subject.call
  179. }.to raise_error(Puppet::Error, /If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key/)
  180. end
  181. end
  182. context 'missing key' do
  183. let(:params) do
  184. {
  185. :location => 'http://archive.ubuntu.com/ubuntu',
  186. :release => 'trusty-backports',
  187. :repos => 'main universe multiverse restricted',
  188. }
  189. end
  190. it do
  191. expect {
  192. subject.call
  193. }.to raise_error(Puppet::Error, /If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key/)
  194. end
  195. end
  196. end
  197. describe 'validation' do
  198. let(:facts) do
  199. {
  200. :lsbdistid => 'Ubuntu',
  201. :osfamily => 'Debian',
  202. :lsbdistcodename => 'trusty',
  203. :puppetversion => Puppet.version,
  204. }
  205. end
  206. context 'invalid location' do
  207. let(:params) do
  208. {
  209. :location => true
  210. }
  211. end
  212. it do
  213. expect {
  214. subject.call
  215. }.to raise_error(Puppet::Error, /is not a string/)
  216. end
  217. end
  218. context 'invalid release' do
  219. let(:params) do
  220. {
  221. :release => true
  222. }
  223. end
  224. it do
  225. expect {
  226. subject.call
  227. }.to raise_error(Puppet::Error, /is not a string/)
  228. end
  229. end
  230. context 'invalid repos' do
  231. let(:params) do
  232. {
  233. :repos => true
  234. }
  235. end
  236. it do
  237. expect {
  238. subject.call
  239. }.to raise_error(Puppet::Error, /is not a string/)
  240. end
  241. end
  242. context 'invalid key' do
  243. let(:params) do
  244. {
  245. :key => true
  246. }
  247. end
  248. it do
  249. expect {
  250. subject.call
  251. }.to raise_error(Puppet::Error, /is not a string/)
  252. end
  253. end
  254. context 'invalid pin' do
  255. let(:params) do
  256. {
  257. :pin => true
  258. }
  259. end
  260. it do
  261. expect {
  262. subject.call
  263. }.to raise_error(Puppet::Error, /pin must be either a string, number or hash/)
  264. end
  265. end
  266. end
  267. end