(CONT-773) Rubocop Auto Fixes 1-5
[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'
7
8   let :title do
9     'my_source'
10   end
11
12   let :facts do
13     {
14       os: {
15         family: 'Debian',
16         name: 'Debian',
17         release: {
18           major: '9',
19           full: '9.0',
20         },
21         distro: {
22           codename: 'stretch',
23           id: 'Debian',
24         },
25       },
26     }
27   end
28
29   context 'with mostly defaults' do
30     let :params do
31       {
32         'include' => { 'deb' => false, 'src' => true },
33         'location' => 'http://debian.mirror.iweb.ca/debian/',
34       }
35     end
36
37     it {
38       is_expected.to contain_apt__setting('list-my_source').with_content(%r{# my_source\ndeb-src http://debian.mirror.iweb.ca/debian/ stretch main\n})
39     }
40   end
41
42   context 'with no defaults' do
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(%r{# foo\ndeb \[arch=x86_64 trusted=yes\] http://debian.mirror.iweb.ca/debian/ sid testing\n})
59                                                            .without_content(%r{deb-src})
60     }
61
62     it {
63       is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with('ensure' => 'present',
64                                                                                                           'priority' => '10',
65                                                                                                           'origin' => 'debian.mirror.iweb.ca')
66     }
67
68     it {
69       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',
70                                                                                                                                                   'id' => GPG_KEY_ID)
71     }
72   end
73
74   context 'when allow_insecure true' do
75     let :params do
76       {
77         'include' => { 'src' => false },
78         'location' => 'http://debian.mirror.iweb.ca/debian/',
79         'allow_insecure' => true,
80       }
81     end
82
83     it { is_expected.to contain_apt__setting('list-my_source').with_content(%r{# my_source\ndeb \[allow-insecure=yes\] http://debian.mirror.iweb.ca/debian/ stretch main\n}) }
84   end
85
86   context 'when allow_unsigned true' do
87     let :params do
88       {
89         'include' => { 'src' => false },
90         'location' => 'http://debian.mirror.iweb.ca/debian/',
91         'allow_unsigned' => true,
92       }
93     end
94
95     it { is_expected.to contain_apt__setting('list-my_source').with_content(%r{# my_source\ndeb \[trusted=yes\] http://debian.mirror.iweb.ca/debian/ stretch main\n}) }
96   end
97
98   context 'with architecture equals x86_64' do
99     let :params do
100       {
101         'location' => 'http://debian.mirror.iweb.ca/debian/',
102         'architecture' => 'x86_64',
103       }
104     end
105
106     it {
107       is_expected.to contain_apt__setting('list-my_source').with_content(%r{# my_source\ndeb \[arch=x86_64\] http://debian.mirror.iweb.ca/debian/ stretch main\n})
108     }
109   end
110
111   context 'with ensure => absent' do
112     let :params do
113       {
114         'ensure' => 'absent',
115       }
116     end
117
118     it {
119       is_expected.to contain_apt__setting('list-my_source').with('ensure' => 'absent')
120     }
121   end
122
123   describe 'validation' do
124     context 'with no release' do
125       let :facts do
126         {
127           os: {
128             family: 'Debian',
129             name: 'Debian',
130             release: {
131               major: '8',
132               full: '8.0',
133             },
134             distro: {
135               id: 'Debian',
136             },
137           },
138         }
139       end
140
141       it do
142         is_expected.to raise_error(Puppet::Error, %r{os.distro.codename fact not available: release parameter required})
143       end
144     end
145   end
146 end