source_spec.rb 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. require 'spec_helper'
  2. describe 'apt::source', :type => :define do
  3. GPG_KEY_ID = '4BD6EC30'
  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. }
  19. end
  20. it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({
  21. 'ensure' => 'present',
  22. 'path' => '/etc/apt/sources.list.d/my_source.list',
  23. 'owner' => 'root',
  24. 'group' => 'root',
  25. 'mode' => '0644',
  26. }).with_content(/#file generated by puppet\n# my_source\ndeb-src wheezy main\n/)
  27. }
  28. end
  29. context 'no defaults' do
  30. let :facts do
  31. {
  32. :lsbdistid => 'Debian',
  33. :lsbdistcodename => 'wheezy',
  34. :osfamily => 'Debian'
  35. }
  36. end
  37. let :params do
  38. {
  39. 'comment' => 'foo',
  40. 'location' => 'http://debian.mirror.iweb.ca/debian/',
  41. 'release' => 'sid',
  42. 'repos' => 'testing',
  43. 'include_src' => false,
  44. 'required_packages' => 'vim',
  45. 'key' => GPG_KEY_ID,
  46. 'key_server' => 'pgp.mit.edu',
  47. 'key_content' => 'GPG key content',
  48. 'key_source' => 'http://apt.puppetlabs.com/pubkey.gpg',
  49. 'pin' => '10',
  50. 'architecture' => 'x86_64',
  51. }
  52. end
  53. it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({
  54. 'ensure' => 'present',
  55. 'path' => '/etc/apt/sources.list.d/my_source.list',
  56. 'owner' => 'root',
  57. 'group' => 'root',
  58. 'mode' => '0644',
  59. }).with_content(/#file generated by puppet\n# foo\ndeb \[arch=x86_64\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(/deb-src/)
  60. }
  61. it { is_expected.to contain_apt__pin('my_source').that_comes_before('File[my_source.list]').with({
  62. 'ensure' => 'present',
  63. 'priority' => '10',
  64. 'origin' => 'debian.mirror.iweb.ca',
  65. })
  66. }
  67. it { is_expected.to contain_exec("Required packages: 'vim' for my_source").that_comes_before('Exec[apt_update]').that_subscribes_to('File[my_source.list]').with({
  68. 'command' => '/usr/bin/apt-get -y install vim',
  69. 'logoutput' => 'on_failure',
  70. 'refreshonly' => true,
  71. 'tries' => '3',
  72. 'try_sleep' => '1',
  73. })
  74. }
  75. it { is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('File[my_source.list]').with({
  76. 'ensure' => 'present',
  77. 'key' => GPG_KEY_ID,
  78. 'key_server' => 'pgp.mit.edu',
  79. 'key_content' => 'GPG key content',
  80. 'key_source' => 'http://apt.puppetlabs.com/pubkey.gpg',
  81. })
  82. }
  83. end
  84. context 'ensure => absent' do
  85. let :facts do
  86. {
  87. :lsbdistid => 'Debian',
  88. :lsbdistcodename => 'wheezy',
  89. :osfamily => 'Debian'
  90. }
  91. end
  92. let :params do
  93. {
  94. 'ensure' => 'absent',
  95. }
  96. end
  97. it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({
  98. 'ensure' => 'absent'
  99. })
  100. }
  101. end
  102. describe 'validation' do
  103. context 'no release' do
  104. let :facts do
  105. {
  106. :lsbdistid => 'Debian',
  107. :osfamily => 'Debian'
  108. }
  109. end
  110. it do
  111. expect {
  112. should compile
  113. }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/)
  114. end
  115. end
  116. end
  117. end