apt_backports_spec.rb 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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. :lsbdistrelease => '14.04',
  49. :puppetversion => Puppet.version,
  50. }
  51. end
  52. it { is_expected.to contain_apt__source('backports').with({
  53. :location => 'http://archive.ubuntu.com/ubuntu',
  54. :key => '630239CC130E1A7FD81A27B140976EAF437D05B5',
  55. :repos => 'main universe multiverse restricted',
  56. :release => 'trusty-backports',
  57. :pin => { 'priority' => 200, 'release' => 'trusty-backports' },
  58. })
  59. }
  60. end
  61. context 'set everything' do
  62. let(:facts) do
  63. {
  64. :lsbdistid => 'Ubuntu',
  65. :osfamily => 'Debian',
  66. :lsbdistcodename => 'trusty',
  67. :lsbdistrelease => '14.04',
  68. :puppetversion => Puppet.version,
  69. }
  70. end
  71. let(:params) do
  72. {
  73. :location => 'http://archive.ubuntu.com/ubuntu-test',
  74. :release => 'vivid',
  75. :repos => 'main',
  76. :key => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
  77. :pin => '90',
  78. }
  79. end
  80. it { is_expected.to contain_apt__source('backports').with({
  81. :location => 'http://archive.ubuntu.com/ubuntu-test',
  82. :key => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
  83. :repos => 'main',
  84. :release => 'vivid',
  85. :pin => { 'priority' => 90, 'release' => 'vivid' },
  86. })
  87. }
  88. end
  89. context 'set things with hashes' do
  90. let(:facts) do
  91. {
  92. :lsbdistid => 'Ubuntu',
  93. :osfamily => 'Debian',
  94. :lsbdistcodename => 'trusty',
  95. :lsbdistrelease => '14.04',
  96. :puppetversion => Puppet.version,
  97. }
  98. end
  99. let(:params) do
  100. {
  101. :key => {
  102. 'id' => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
  103. },
  104. :pin => {
  105. 'priority' => '90',
  106. },
  107. }
  108. end
  109. it { is_expected.to contain_apt__source('backports').with({
  110. :key => { 'id' => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553' },
  111. :pin => { 'priority' => '90' },
  112. })
  113. }
  114. end
  115. end
  116. describe 'mint tests' do
  117. let(:facts) do
  118. {
  119. :lsbdistid => 'linuxmint',
  120. :osfamily => 'Debian',
  121. :lsbdistcodename => 'qiana',
  122. :puppetversion => Puppet.version,
  123. }
  124. end
  125. context 'sets all the needed things' do
  126. let(:params) do
  127. {
  128. :location => 'http://archive.ubuntu.com/ubuntu',
  129. :release => 'trusty-backports',
  130. :repos => 'main universe multiverse restricted',
  131. :key => '630239CC130E1A7FD81A27B140976EAF437D05B5',
  132. }
  133. end
  134. it { is_expected.to contain_apt__source('backports').with({
  135. :location => 'http://archive.ubuntu.com/ubuntu',
  136. :key => '630239CC130E1A7FD81A27B140976EAF437D05B5',
  137. :repos => 'main universe multiverse restricted',
  138. :release => 'trusty-backports',
  139. :pin => { 'priority' => 200, 'release' => 'trusty-backports' },
  140. })
  141. }
  142. end
  143. context 'missing location' do
  144. let(:params) do
  145. {
  146. :release => 'trusty-backports',
  147. :repos => 'main universe multiverse restricted',
  148. :key => '630239CC130E1A7FD81A27B140976EAF437D05B5',
  149. }
  150. end
  151. it do
  152. expect {
  153. subject.call
  154. }.to raise_error(Puppet::Error, /If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key/)
  155. end
  156. end
  157. context 'missing release' do
  158. let(:params) do
  159. {
  160. :location => 'http://archive.ubuntu.com/ubuntu',
  161. :repos => 'main universe multiverse restricted',
  162. :key => '630239CC130E1A7FD81A27B140976EAF437D05B5',
  163. }
  164. end
  165. it do
  166. expect {
  167. subject.call
  168. }.to raise_error(Puppet::Error, /If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key/)
  169. end
  170. end
  171. context 'missing repos' do
  172. let(:params) do
  173. {
  174. :location => 'http://archive.ubuntu.com/ubuntu',
  175. :release => 'trusty-backports',
  176. :key => '630239CC130E1A7FD81A27B140976EAF437D05B5',
  177. }
  178. end
  179. it do
  180. expect {
  181. subject.call
  182. }.to raise_error(Puppet::Error, /If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key/)
  183. end
  184. end
  185. context 'missing key' do
  186. let(:params) do
  187. {
  188. :location => 'http://archive.ubuntu.com/ubuntu',
  189. :release => 'trusty-backports',
  190. :repos => 'main universe multiverse restricted',
  191. }
  192. end
  193. it do
  194. expect {
  195. subject.call
  196. }.to raise_error(Puppet::Error, /If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key/)
  197. end
  198. end
  199. end
  200. describe 'validation' do
  201. let(:facts) do
  202. {
  203. :lsbdistid => 'Ubuntu',
  204. :osfamily => 'Debian',
  205. :lsbdistcodename => 'trusty',
  206. :lsbdistrelease => '14.04',
  207. :puppetversion => Puppet.version,
  208. }
  209. end
  210. context 'invalid location' do
  211. let(:params) do
  212. {
  213. :location => true
  214. }
  215. end
  216. it do
  217. expect {
  218. subject.call
  219. }.to raise_error(Puppet::Error, /is not a string/)
  220. end
  221. end
  222. context 'invalid release' do
  223. let(:params) do
  224. {
  225. :release => true
  226. }
  227. end
  228. it do
  229. expect {
  230. subject.call
  231. }.to raise_error(Puppet::Error, /is not a string/)
  232. end
  233. end
  234. context 'invalid repos' do
  235. let(:params) do
  236. {
  237. :repos => true
  238. }
  239. end
  240. it do
  241. expect {
  242. subject.call
  243. }.to raise_error(Puppet::Error, /is not a string/)
  244. end
  245. end
  246. context 'invalid key' do
  247. let(:params) do
  248. {
  249. :key => true
  250. }
  251. end
  252. it do
  253. expect {
  254. subject.call
  255. }.to raise_error(Puppet::Error, /is not a string/)
  256. end
  257. end
  258. context 'invalid pin' do
  259. let(:params) do
  260. {
  261. :pin => true
  262. }
  263. end
  264. it do
  265. expect {
  266. subject.call
  267. }.to raise_error(Puppet::Error, /pin must be either a string, number or hash/)
  268. end
  269. end
  270. end
  271. end