(MAINT) pdk update
[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: '8',
19           full: '8.0',
20         },
21         distro: {
22           codename: 'jessie',
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/ jessie 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_unsigned true' do
75     let :params do
76       {
77         'include'        => { 'src' => false },
78         'location'       => 'http://debian.mirror.iweb.ca/debian/',
79         'allow_unsigned' => true,
80       }
81     end
82
83     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}) }
84   end
85
86   context 'with architecture equals x86_64' do
87     let :params do
88       {
89         'location'     => 'http://debian.mirror.iweb.ca/debian/',
90         'architecture' => 'x86_64',
91       }
92     end
93
94     it {
95       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})
96     }
97   end
98
99   context 'with ensure => absent' do
100     let :params do
101       {
102         'ensure' => 'absent',
103       }
104     end
105
106     it {
107       is_expected.to contain_apt__setting('list-my_source').with('ensure' => 'absent')
108     }
109   end
110
111   describe 'validation' do
112     context 'with no release' do
113       let :facts do
114         {
115           os: {
116             family: 'Debian',
117             name: 'Debian',
118             release: {
119               major: '8',
120               full: '8.0',
121             },
122             distro: {
123               id: 'Debian',
124             },
125           },
126         }
127       end
128
129       it do
130         is_expected.to raise_error(Puppet::Error, %r{os.distro.codename fact not available: release parameter required})
131       end
132     end
133   end
134 end