pin_spec.rb 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. require 'spec_helper'
  2. describe 'apt::pin', :type => :define do
  3. let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
  4. let(:title) { 'my_pin' }
  5. context 'defaults' do
  6. it { is_expected.to contain_file("my_pin.pref").with_content(/Explanation: : my_pin\nPackage: \*\nPin: release a=my_pin\nPin-Priority: 0\n/)}
  7. it { is_expected.to contain_file("my_pin.pref").with({
  8. 'ensure' => 'present',
  9. 'path' => '/etc/apt/preferences.d/my_pin.pref',
  10. 'owner' => 'root',
  11. 'group' => 'root',
  12. 'mode' => '0644',
  13. })
  14. }
  15. end
  16. context 'set version' do
  17. let :params do
  18. {
  19. 'packages' => 'vim',
  20. 'version' => '1',
  21. }
  22. end
  23. it { is_expected.to contain_file("my_pin.pref").with_content(/Explanation: : my_pin\nPackage: vim\nPin: version 1\nPin-Priority: 0\n/)}
  24. it { is_expected.to contain_file("my_pin.pref").with({
  25. 'ensure' => 'present',
  26. 'path' => '/etc/apt/preferences.d/my_pin.pref',
  27. 'owner' => 'root',
  28. 'group' => 'root',
  29. 'mode' => '0644',
  30. })
  31. }
  32. end
  33. context 'set origin' do
  34. let :params do
  35. {
  36. 'packages' => 'vim',
  37. 'origin' => 'test',
  38. }
  39. end
  40. it { is_expected.to contain_file("my_pin.pref").with_content(/Explanation: : my_pin\nPackage: vim\nPin: origin test\nPin-Priority: 0\n/)}
  41. it { is_expected.to contain_file("my_pin.pref").with({
  42. 'ensure' => 'present',
  43. 'path' => '/etc/apt/preferences.d/my_pin.pref',
  44. 'owner' => 'root',
  45. 'group' => 'root',
  46. 'mode' => '0644',
  47. })
  48. }
  49. end
  50. context 'not defaults' do
  51. let :params do
  52. {
  53. 'explanation' => 'foo',
  54. 'order' => 99,
  55. 'release' => '1',
  56. 'codename' => 'bar',
  57. 'release_version' => '2',
  58. 'component' => 'baz',
  59. 'originator' => 'foobar',
  60. 'label' => 'foobaz',
  61. 'priority' => 10,
  62. }
  63. end
  64. it { is_expected.to contain_file("my_pin.pref").with_content(/Explanation: foo\nPackage: \*\nPin: release a=1, n=bar, v=2, c=baz, o=foobar, l=foobaz\nPin-Priority: 10\n/) }
  65. it { is_expected.to contain_file("my_pin.pref").with({
  66. 'ensure' => 'present',
  67. 'path' => '/etc/apt/preferences.d/99-my_pin.pref',
  68. 'owner' => 'root',
  69. 'group' => 'root',
  70. 'mode' => '0644',
  71. })
  72. }
  73. end
  74. context 'ensure absent' do
  75. let :params do
  76. {
  77. 'ensure' => 'absent'
  78. }
  79. end
  80. it { is_expected.to contain_file("my_pin.pref").with({
  81. 'ensure' => 'absent',
  82. })
  83. }
  84. end
  85. context 'bad characters' do
  86. let(:title) { 'such bad && wow!' }
  87. it { is_expected.to contain_file("such__bad____wow_.pref") }
  88. end
  89. describe 'validation' do
  90. context 'invalid order' do
  91. let :params do
  92. {
  93. 'order' => 'foo',
  94. }
  95. end
  96. it do
  97. expect {
  98. should compile
  99. }.to raise_error(Puppet::Error, /Only integers are allowed/)
  100. end
  101. end
  102. context 'packages == * and version' do
  103. let :params do
  104. {
  105. 'version' => '1',
  106. }
  107. end
  108. it do
  109. expect {
  110. should compile
  111. }.to raise_error(Puppet::Error, /parameter version cannot be used in general form/)
  112. end
  113. end
  114. context 'packages == * and release and origin' do
  115. let :params do
  116. {
  117. 'origin' => 'test',
  118. 'release' => 'foo',
  119. }
  120. end
  121. it do
  122. expect {
  123. should compile
  124. }.to raise_error(Puppet::Error, /parameters release and origin are mutually exclusive/)
  125. end
  126. end
  127. context 'specific form with release and origin' do
  128. let :params do
  129. {
  130. 'release' => 'foo',
  131. 'origin' => 'test',
  132. 'packages' => 'vim',
  133. }
  134. end
  135. it do
  136. expect {
  137. should compile
  138. }.to raise_error(Puppet::Error, /parameters release, origin, and version are mutually exclusive/)
  139. end
  140. end
  141. context 'specific form with version and origin' do
  142. let :params do
  143. {
  144. 'version' => '1',
  145. 'origin' => 'test',
  146. 'packages' => 'vim',
  147. }
  148. end
  149. it do
  150. expect {
  151. should compile
  152. }.to raise_error(Puppet::Error, /parameters release, origin, and version are mutually exclusive/)
  153. end
  154. end
  155. end
  156. end