source_spec.rb 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. require 'spec_helper'
  2. describe 'apt::source' do
  3. GPG_KEY_ID = '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30'
  4. let :pre_condition do
  5. 'class { "apt": }'
  6. end
  7. let :title do
  8. 'my_source'
  9. end
  10. context 'defaults' do
  11. context 'without location' do
  12. let :facts do
  13. {
  14. :lsbdistid => 'Debian',
  15. :lsbdistcodename => 'wheezy',
  16. :osfamily => 'Debian',
  17. :puppetversion => Puppet.version,
  18. }
  19. end
  20. it do
  21. expect {
  22. subject.call
  23. }.to raise_error(Puppet::Error, /source entry without specifying a location/)
  24. end
  25. end
  26. context 'with location' do
  27. let :facts do
  28. {
  29. :lsbdistid => 'Debian',
  30. :lsbdistcodename => 'wheezy',
  31. :osfamily => 'Debian',
  32. :puppetversion => Puppet.version,
  33. }
  34. end
  35. let(:params) { { :location => 'hello.there', } }
  36. it { is_expected.to contain_apt__setting('list-my_source').with({
  37. :ensure => 'present',
  38. }).without_content(/# my_source\ndeb-src hello.there wheezy main\n/)
  39. }
  40. end
  41. end
  42. describe 'no defaults' do
  43. let :facts do
  44. {
  45. :lsbdistid => 'Debian',
  46. :lsbdistcodename => 'wheezy',
  47. :osfamily => 'Debian',
  48. :puppetversion => Puppet.version,
  49. }
  50. end
  51. context 'with complex pin' do
  52. let :params do
  53. {
  54. :location => 'hello.there',
  55. :pin => { 'release' => 'wishwash',
  56. 'explanation' => 'wishwash',
  57. 'priority' => 1001, },
  58. }
  59. end
  60. it { is_expected.to contain_apt__setting('list-my_source').with({
  61. :ensure => 'present',
  62. }).with_content(/hello.there wheezy main\n/)
  63. }
  64. it { is_expected.to contain_file('/etc/apt/sources.list.d/my_source.list').that_notifies('Class[Apt::Update]')}
  65. it { is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with({
  66. :ensure => 'present',
  67. :priority => 1001,
  68. :explanation => 'wishwash',
  69. :release => 'wishwash',
  70. })
  71. }
  72. end
  73. context 'with simple key' do
  74. let :params do
  75. {
  76. :comment => 'foo',
  77. :location => 'http://debian.mirror.iweb.ca/debian/',
  78. :release => 'sid',
  79. :repos => 'testing',
  80. :key => GPG_KEY_ID,
  81. :pin => '10',
  82. :architecture => 'x86_64',
  83. :allow_unsigned => true,
  84. }
  85. end
  86. it { is_expected.to contain_apt__setting('list-my_source').with({
  87. :ensure => 'present',
  88. }).with_content(/# foo\ndeb \[arch=x86_64 trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(/deb-src/)
  89. }
  90. it { is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with({
  91. :ensure => 'present',
  92. :priority => '10',
  93. :origin => 'debian.mirror.iweb.ca',
  94. })
  95. }
  96. it { is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('Apt::Setting[list-my_source]').with({
  97. :ensure => 'present',
  98. :id => GPG_KEY_ID,
  99. })
  100. }
  101. end
  102. context 'with complex key' do
  103. let :params do
  104. {
  105. :comment => 'foo',
  106. :location => 'http://debian.mirror.iweb.ca/debian/',
  107. :release => 'sid',
  108. :repos => 'testing',
  109. :key => { 'id' => GPG_KEY_ID, 'server' => 'pgp.mit.edu',
  110. 'content' => 'GPG key content',
  111. 'source' => 'http://apt.puppetlabs.com/pubkey.gpg',},
  112. :pin => '10',
  113. :architecture => 'x86_64',
  114. :allow_unsigned => true,
  115. }
  116. end
  117. it { is_expected.to contain_apt__setting('list-my_source').with({
  118. :ensure => 'present',
  119. }).with_content(/# foo\ndeb \[arch=x86_64 trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(/deb-src/)
  120. }
  121. it { is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with({
  122. :ensure => 'present',
  123. :priority => '10',
  124. :origin => 'debian.mirror.iweb.ca',
  125. })
  126. }
  127. it { is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('Apt::Setting[list-my_source]').with({
  128. :ensure => 'present',
  129. :id => GPG_KEY_ID,
  130. :server => 'pgp.mit.edu',
  131. :content => 'GPG key content',
  132. :source => 'http://apt.puppetlabs.com/pubkey.gpg',
  133. })
  134. }
  135. end
  136. context 'with simple key' do
  137. let :params do
  138. {
  139. :comment => 'foo',
  140. :location => 'http://debian.mirror.iweb.ca/debian/',
  141. :release => 'sid',
  142. :repos => 'testing',
  143. :key => GPG_KEY_ID,
  144. :pin => '10',
  145. :architecture => 'x86_64',
  146. :allow_unsigned => true,
  147. }
  148. end
  149. it { is_expected.to contain_apt__setting('list-my_source').with({
  150. :ensure => 'present',
  151. }).with_content(/# foo\ndeb \[arch=x86_64 trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(/deb-src/)
  152. }
  153. it { is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with({
  154. :ensure => 'present',
  155. :priority => '10',
  156. :origin => 'debian.mirror.iweb.ca',
  157. })
  158. }
  159. it { is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('Apt::Setting[list-my_source]').with({
  160. :ensure => 'present',
  161. :id => GPG_KEY_ID,
  162. })
  163. }
  164. end
  165. end
  166. context 'allow_unsigned true' do
  167. let :facts do
  168. {
  169. :lsbdistid => 'Debian',
  170. :lsbdistcodename => 'wheezy',
  171. :osfamily => 'Debian',
  172. :puppetversion => Puppet.version,
  173. }
  174. end
  175. let :params do
  176. {
  177. :location => 'hello.there',
  178. :allow_unsigned => true,
  179. }
  180. end
  181. it { is_expected.to contain_apt__setting('list-my_source').with({
  182. :ensure => 'present',
  183. }).with_content(/# my_source\ndeb \[trusted=yes\] hello.there wheezy main\n/)
  184. }
  185. end
  186. context 'architecture equals x86_64' do
  187. let :facts do
  188. {
  189. :lsbdistid => 'Debian',
  190. :lsbdistcodename => 'wheezy',
  191. :osfamily => 'Debian',
  192. :puppetversion => Puppet.version,
  193. }
  194. end
  195. let :params do
  196. {
  197. :location => 'hello.there',
  198. :include => {'deb' => false, 'src' => true,},
  199. :architecture => 'x86_64',
  200. }
  201. end
  202. it { is_expected.to contain_apt__setting('list-my_source').with({
  203. :ensure => 'present',
  204. }).with_content(/# my_source\ndeb-src \[arch=x86_64\] hello.there wheezy main\n/)
  205. }
  206. end
  207. context 'include_src => true' do
  208. let :facts do
  209. {
  210. :lsbdistid => 'Debian',
  211. :lsbdistcodename => 'wheezy',
  212. :osfamily => 'Debian',
  213. :puppetversion => Puppet.version,
  214. }
  215. end
  216. let :params do
  217. {
  218. :location => 'hello.there',
  219. :include_src => true,
  220. }
  221. end
  222. it { is_expected.to contain_apt__setting('list-my_source').with({
  223. :ensure => 'present',
  224. }).with_content(/# my_source\ndeb hello.there wheezy main\ndeb-src hello.there wheezy main\n/)
  225. }
  226. end
  227. context 'include_deb => false' do
  228. let :facts do
  229. {
  230. :lsbdistid => 'debian',
  231. :lsbdistcodename => 'wheezy',
  232. :osfamily => 'debian',
  233. :puppetversion => Puppet.version,
  234. }
  235. end
  236. let :params do
  237. {
  238. :location => 'hello.there',
  239. :include_deb => false,
  240. }
  241. end
  242. it { is_expected.to contain_apt__setting('list-my_source').with({
  243. :ensure => 'present',
  244. }).without_content(/deb-src hello.there wheezy main\n/)
  245. }
  246. it { is_expected.to contain_apt__setting('list-my_source').without_content(/deb hello.there wheezy main\n/) }
  247. end
  248. context 'include_src => true and include_deb => false' do
  249. let :facts do
  250. {
  251. :lsbdistid => 'debian',
  252. :lsbdistcodename => 'wheezy',
  253. :osfamily => 'debian',
  254. :puppetversion => Puppet.version,
  255. }
  256. end
  257. let :params do
  258. {
  259. :location => 'hello.there',
  260. :include_deb => false,
  261. :include_src => true,
  262. }
  263. end
  264. it { is_expected.to contain_apt__setting('list-my_source').with({
  265. :ensure => 'present',
  266. }).with_content(/deb-src hello.there wheezy main\n/)
  267. }
  268. it { is_expected.to contain_apt__setting('list-my_source').without_content(/deb hello.there wheezy main\n/) }
  269. end
  270. context 'include precedence' do
  271. let :facts do
  272. {
  273. :lsbdistid => 'debian',
  274. :lsbdistcodename => 'wheezy',
  275. :osfamily => 'debian',
  276. :puppetversion => Puppet.version,
  277. }
  278. end
  279. let :params do
  280. {
  281. :location => 'hello.there',
  282. :include_deb => true,
  283. :include_src => false,
  284. :include => { 'deb' => false, 'src' => true },
  285. }
  286. end
  287. it { is_expected.to contain_apt__setting('list-my_source').with({
  288. :ensure => 'present',
  289. }).with_content(/deb-src hello.there wheezy main\n/)
  290. }
  291. it { is_expected.to contain_apt__setting('list-my_source').without_content(/deb hello.there wheezy main\n/) }
  292. end
  293. context 'ensure => absent' do
  294. let :facts do
  295. {
  296. :lsbdistid => 'Debian',
  297. :lsbdistcodename => 'wheezy',
  298. :osfamily => 'Debian',
  299. :puppetversion => Puppet.version,
  300. }
  301. end
  302. let :params do
  303. {
  304. :ensure => 'absent',
  305. }
  306. end
  307. it { is_expected.to contain_apt__setting('list-my_source').with({
  308. :ensure => 'absent'
  309. })
  310. }
  311. end
  312. describe 'validation' do
  313. context 'no release' do
  314. let :facts do
  315. {
  316. :lsbdistid => 'Debian',
  317. :osfamily => 'Debian',
  318. :puppetversion => Puppet.version,
  319. }
  320. end
  321. let(:params) { { :location => 'hello.there', } }
  322. it do
  323. expect {
  324. subject.call
  325. }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/)
  326. end
  327. end
  328. context 'invalid pin' do
  329. let :facts do
  330. {
  331. :lsbdistid => 'Debian',
  332. :lsbdistcodename => 'wheezy',
  333. :osfamily => 'Debian',
  334. :puppetversion => Puppet.version,
  335. }
  336. end
  337. let :params do
  338. {
  339. :location => 'hello.there',
  340. :pin => true,
  341. }
  342. end
  343. it do
  344. expect {
  345. subject.call
  346. }.to raise_error(Puppet::Error, /invalid value for pin/)
  347. end
  348. end
  349. end
  350. end