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