Update CODEOWNERS
[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   let(:id) { '6F6B15509CF8E59E6E469F327F438280EF8D349F' }
7   let(:title) { 'my_source' }
8   let :facts do
9     {
10       os: {
11         family: 'Debian',
12         name: 'Debian',
13         release: {
14           major: '9',
15           full: '9.0'
16         },
17         distro: {
18           codename: 'stretch',
19           id: 'Debian'
20         }
21       }
22     }
23   end
24
25   context 'with mostly defaults' do
26     let :params do
27       {
28         'include' => { 'deb' => false, 'src' => true },
29         'location' => 'http://debian.mirror.iweb.ca/debian/'
30       }
31     end
32
33     it {
34       expect(subject).to contain_apt__setting('list-my_source').with_content(%r{# my_source\ndeb-src http://debian.mirror.iweb.ca/debian/ stretch main\n})
35     }
36   end
37
38   context 'with no defaults' do
39     let :params do
40       {
41         'comment' => 'foo',
42         'location' => 'http://debian.mirror.iweb.ca/debian/',
43         'release' => 'sid',
44         'repos' => 'testing',
45         'include' => { 'src' => false },
46         'key' => id,
47         'pin' => '10',
48         'architecture' => 'x86_64',
49         'allow_unsigned' => true
50       }
51     end
52
53     it {
54       expect(subject).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})
55                                                                .without_content(%r{deb-src})
56     }
57
58     it {
59       expect(subject).to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with('ensure' => 'present',
60                                                                                                               'priority' => '10',
61                                                                                                               'origin' => 'debian.mirror.iweb.ca')
62     }
63
64     it {
65       expect(subject).to contain_apt__key("Add key: #{id} from Apt::Source my_source").that_comes_before('Apt::Setting[list-my_source]').with('ensure' => 'present',
66                                                                                                                                               'id' => id)
67     }
68   end
69
70   context 'when allow_insecure true' do
71     let :params do
72       {
73         'include' => { 'src' => false },
74         'location' => 'http://debian.mirror.iweb.ca/debian/',
75         'allow_insecure' => true
76       }
77     end
78
79     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}) }
80   end
81
82   context 'when allow_unsigned true' do
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(%r{# my_source\ndeb \[trusted=yes\] http://debian.mirror.iweb.ca/debian/ stretch main\n}) }
92   end
93
94   context 'with architecture equals x86_64' do
95     let :params do
96       {
97         'location' => 'http://debian.mirror.iweb.ca/debian/',
98         'architecture' => 'x86_64'
99       }
100     end
101
102     it {
103       expect(subject).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})
104     }
105   end
106
107   context 'with ensure => absent' do
108     let :params do
109       {
110         'ensure' => 'absent'
111       }
112     end
113
114     it {
115       expect(subject).to contain_apt__setting('list-my_source').with('ensure' => 'absent')
116     }
117   end
118
119   describe 'validation' do
120     context 'with no release' do
121       let :facts do
122         {
123           os: {
124             family: 'Debian',
125             name: 'Debian',
126             release: {
127               major: '8',
128               full: '8.0'
129             },
130             distro: {
131               id: 'Debian'
132             }
133           }
134         }
135       end
136
137       it do
138         expect(subject).to raise_error(Puppet::Error, %r{os.distro.codename fact not available: release parameter required})
139       end
140     end
141   end
142 end