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