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