source_compat_spec.rb 4.3 KB

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