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