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