(maint) - add back gems removed by pdk update
[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   let :facts do
11     {
12       os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
13       lsbdistid: 'Debian',
14       lsbdistcodename: 'jessie',
15       osfamily: 'Debian',
16     }
17   end
18
19   context 'with mostly defaults' do
20     let :params do
21       {
22         'include' => { 'deb' => false, 'src' => true },
23         'location' => 'http://debian.mirror.iweb.ca/debian/',
24       }
25     end
26
27     it {
28       is_expected.to contain_apt__setting('list-my_source').with_content(%r{# my_source\ndeb-src http://debian.mirror.iweb.ca/debian/ jessie main\n})
29     }
30   end
31
32   context 'with no defaults' do
33     let :params do
34       {
35         'comment'        => 'foo',
36         'location'       => 'http://debian.mirror.iweb.ca/debian/',
37         'release'        => 'sid',
38         'repos'          => 'testing',
39         'include'        => { 'src' => false },
40         'key'            => GPG_KEY_ID,
41         'pin'            => '10',
42         'architecture'   => 'x86_64',
43         'allow_unsigned' => true,
44       }
45     end
46
47     it {
48       is_expected.to contain_apt__setting('list-my_source').with_content(%r{# foo\ndeb \[arch=x86_64 trusted=yes\] http://debian.mirror.iweb.ca/debian/ sid testing\n})
49                                                            .without_content(%r{deb-src})
50     }
51
52     it {
53       is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with('ensure' => 'present',
54                                                                                                           'priority' => '10',
55                                                                                                           'origin'   => 'debian.mirror.iweb.ca')
56     }
57
58     it {
59       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',
60                                                                                                                                                   'id' => GPG_KEY_ID)
61     }
62   end
63
64   context 'when allow_unsigned true' do
65     let :params do
66       {
67         'include'        => { 'src' => false },
68         'location'       => 'http://debian.mirror.iweb.ca/debian/',
69         'allow_unsigned' => true,
70       }
71     end
72
73     it { is_expected.to contain_apt__setting('list-my_source').with_content(%r{# my_source\ndeb \[trusted=yes\] http://debian.mirror.iweb.ca/debian/ jessie main\n}) }
74   end
75
76   context 'with architecture equals x86_64' do
77     let :params do
78       {
79         'location'     => 'http://debian.mirror.iweb.ca/debian/',
80         'architecture' => 'x86_64',
81       }
82     end
83
84     it {
85       is_expected.to contain_apt__setting('list-my_source').with_content(%r{# my_source\ndeb \[arch=x86_64\] http://debian.mirror.iweb.ca/debian/ jessie main\n})
86     }
87   end
88
89   context 'with ensure => absent' do
90     let :params do
91       {
92         'ensure' => 'absent',
93       }
94     end
95
96     it {
97       is_expected.to contain_apt__setting('list-my_source').with('ensure' => 'absent')
98     }
99   end
100
101   describe 'validation' do
102     context 'with no release' do
103       let :facts do
104         {
105           os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
106           osfamily: 'Debian',
107         }
108       end
109
110       it do
111         is_expected.to raise_error(Puppet::Error, %r{lsbdistcodename fact not available: release parameter required})
112       end
113     end
114   end
115 end