apt(::key|_key) Remove the `key.*_` prefixes.
[puppet-modules/puppetlabs-apt.git] / spec / defines / source_spec.rb
1 require 'spec_helper'
2
3 describe 'apt::source' do
4   GPG_KEY_ID = '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30'
5
6   let :pre_condition do
7     'class { "apt": }'
8   end
9
10   let :title do
11     'my_source'
12   end
13
14   context 'mostly defaults' do
15     let :facts do
16       {
17         :lsbdistid       => 'Debian',
18         :lsbdistcodename => 'wheezy',
19         :osfamily        => 'Debian'
20       }
21     end
22
23     let :params do
24       {
25         'include_deb' => false,
26         'include_src' => true,
27       }
28     end
29
30     it { is_expected.to contain_apt__setting('list-my_source').with({
31       'ensure' => 'present',
32     }).with_content(/# my_source\ndeb-src  wheezy main\n/)
33     }
34   end
35
36   context 'no defaults' do
37     let :facts do
38       {
39         :lsbdistid       => 'Debian',
40         :lsbdistcodename => 'wheezy',
41         :osfamily        => 'Debian'
42       }
43     end
44     let :params do
45       {
46         'comment'           => 'foo',
47         'location'          => 'http://debian.mirror.iweb.ca/debian/',
48         'release'           => 'sid',
49         'repos'             => 'testing',
50         'include_src'       => false,
51         'key'               => GPG_KEY_ID,
52         'key_server'        => 'pgp.mit.edu',
53         'key_content'       => 'GPG key content',
54         'key_source'        => 'http://apt.puppetlabs.com/pubkey.gpg',
55         'pin'               => '10',
56         'architecture'      => 'x86_64',
57         'trusted_source'    => true,
58       }
59     end
60
61     it { is_expected.to contain_apt__setting('list-my_source').with({
62       'ensure' => 'present',
63     }).with_content(/# foo\ndeb \[arch=x86_64 trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(/deb-src/)
64     }
65
66     it { is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with({
67       'ensure'   => 'present',
68       'priority' => '10',
69       'origin'   => 'debian.mirror.iweb.ca',
70     })
71     }
72
73     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({
74       'ensure'  => 'present',
75       'key'     => GPG_KEY_ID,
76       'server'  => 'pgp.mit.edu',
77       'content' => 'GPG key content',
78       'source'  => 'http://apt.puppetlabs.com/pubkey.gpg',
79     })
80     }
81   end
82
83   context 'trusted_source true' do
84     let :facts do
85       {
86         :lsbdistid       => 'Debian',
87         :lsbdistcodename => 'wheezy',
88         :osfamily        => 'Debian'
89       }
90     end
91     let :params do
92       {
93         'include_src'    => false,
94         'trusted_source' => true,
95       }
96     end
97
98     it { is_expected.to contain_apt__setting('list-my_source').with({
99       'ensure' => 'present',
100     }).with_content(/# my_source\ndeb \[trusted=yes\]  wheezy main\n/)
101     }
102   end
103
104   context 'architecture equals x86_64' do
105     let :facts do
106       {
107         :lsbdistid       => 'Debian',
108         :lsbdistcodename => 'wheezy',
109         :osfamily        => 'Debian'
110       }
111     end
112     let :params do
113       {
114         'include_deb'  => false,
115         'include_src'  => true,
116         'architecture' => 'x86_64',
117       }
118     end
119
120     it { is_expected.to contain_apt__setting('list-my_source').with({
121       'ensure' => 'present',
122     }).with_content(/# my_source\ndeb-src \[arch=x86_64 \]  wheezy main\n/)
123     }
124   end
125
126   context 'ensure => absent' do
127     let :facts do
128       {
129         :lsbdistid       => 'Debian',
130         :lsbdistcodename => 'wheezy',
131         :osfamily        => 'Debian'
132       }
133     end
134     let :params do
135       {
136         'ensure' => 'absent',
137       }
138     end
139
140     it { is_expected.to contain_apt__setting('list-my_source').with({
141       'ensure' => 'absent'
142     })
143     }
144   end
145
146   describe 'validation' do
147     context 'no release' do
148       let :facts do
149         {
150           :lsbdistid       => 'Debian',
151           :osfamily        => 'Debian'
152         }
153       end
154
155       it do
156         expect {
157           is_expected.to compile
158         }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/)
159       end
160     end
161   end
162 end