source_compat_spec.rb 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. require 'spec_helper'
  2. describe 'apt::source', :type => :define do
  3. GPG_KEY_ID = '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30'
  4. let :title do
  5. 'my_source'
  6. end
  7. context 'mostly defaults' do
  8. let :facts do
  9. {
  10. :lsbdistid => 'Debian',
  11. :lsbdistcodename => 'wheezy',
  12. :osfamily => 'Debian',
  13. :puppetversion => Puppet.version,
  14. }
  15. end
  16. let :params do
  17. {
  18. 'include_deb' => false,
  19. 'include_src' => true,
  20. 'location' => 'http://debian.mirror.iweb.ca/debian/',
  21. }
  22. end
  23. it { is_expected.to contain_apt__setting('list-my_source').with_content(/# my_source\ndeb-src http:\/\/debian\.mirror\.iweb\.ca\/debian\/ wheezy main\n/)
  24. }
  25. end
  26. context 'no defaults' 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 do
  36. {
  37. 'comment' => 'foo',
  38. 'location' => 'http://debian.mirror.iweb.ca/debian/',
  39. 'release' => 'sid',
  40. 'repos' => 'testing',
  41. 'include_src' => false,
  42. 'required_packages' => 'vim',
  43. 'key' => GPG_KEY_ID,
  44. 'key_server' => 'pgp.mit.edu',
  45. 'key_content' => 'GPG key content',
  46. 'key_source' => 'http://apt.puppetlabs.com/pubkey.gpg',
  47. 'pin' => '10',
  48. 'architecture' => 'x86_64',
  49. 'trusted_source' => true,
  50. }
  51. end
  52. it { is_expected.to contain_apt__setting('list-my_source').with_content(/# foo\ndeb \[arch=x86_64 trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(/deb-src/)
  53. }
  54. it { is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with({
  55. 'ensure' => 'present',
  56. 'priority' => '10',
  57. 'origin' => 'debian.mirror.iweb.ca',
  58. })
  59. }
  60. it { is_expected.to contain_exec("Required packages: 'vim' for my_source").that_comes_before('Apt::Setting[list-my_source]').with({
  61. 'command' => '/usr/bin/apt-get -y install vim',
  62. 'logoutput' => 'on_failure',
  63. 'refreshonly' => true,
  64. 'tries' => '3',
  65. 'try_sleep' => '1',
  66. })
  67. }
  68. 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({
  69. 'ensure' => 'present',
  70. 'id' => GPG_KEY_ID,
  71. 'key_server' => 'pgp.mit.edu',
  72. 'key_content' => 'GPG key content',
  73. 'key_source' => 'http://apt.puppetlabs.com/pubkey.gpg',
  74. })
  75. }
  76. end
  77. context 'trusted_source true' do
  78. let :facts do
  79. {
  80. :lsbdistid => 'Debian',
  81. :lsbdistcodename => 'wheezy',
  82. :osfamily => 'Debian',
  83. :puppetversion => Puppet.version,
  84. }
  85. end
  86. let :params do
  87. {
  88. 'include_src' => false,
  89. 'location' => 'http://debian.mirror.iweb.ca/debian/',
  90. 'trusted_source' => true,
  91. }
  92. end
  93. it { is_expected.to contain_apt__setting('list-my_source').with_content(/# my_source\ndeb \[trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ wheezy main\n/) }
  94. end
  95. context 'architecture equals x86_64' do
  96. let :facts do
  97. {
  98. :lsbdistid => 'Debian',
  99. :lsbdistcodename => 'wheezy',
  100. :osfamily => 'Debian',
  101. :puppetversion => Puppet.version,
  102. }
  103. end
  104. let :params do
  105. {
  106. 'location' => 'http://debian.mirror.iweb.ca/debian/',
  107. 'architecture' => 'x86_64',
  108. }
  109. end
  110. it { is_expected.to contain_apt__setting('list-my_source').with_content(/# my_source\ndeb \[arch=x86_64\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ wheezy main\n/)
  111. }
  112. end
  113. context 'ensure => absent' do
  114. let :facts do
  115. {
  116. :lsbdistid => 'Debian',
  117. :lsbdistcodename => 'wheezy',
  118. :osfamily => 'Debian',
  119. :puppetversion => Puppet.version,
  120. }
  121. end
  122. let :params do
  123. {
  124. 'ensure' => 'absent',
  125. }
  126. end
  127. it { is_expected.to contain_apt__setting('list-my_source').with({
  128. 'ensure' => 'absent'
  129. })
  130. }
  131. end
  132. describe 'validation' do
  133. context 'no release' do
  134. let :facts do
  135. {
  136. :lsbdistid => 'Debian',
  137. :osfamily => 'Debian',
  138. :puppetversion => Puppet.version,
  139. }
  140. end
  141. it do
  142. expect { subject.call }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/)
  143. end
  144. end
  145. end
  146. end