Merge pull request #670 from hunner/fix_specs
[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,
24         'include_src' => true,
25         'location'    => 'http://debian.mirror.iweb.ca/debian/',
26       }
27     end
28
29     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/)
30     }
31   end
32
33   context 'no defaults' do
34     let :facts do
35       {
36         :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
37         :lsbdistid       => 'Debian',
38         :lsbdistcodename => 'wheezy',
39         :osfamily        => 'Debian',
40         :puppetversion   => Puppet.version,
41       }
42     end
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         'required_packages' => 'vim',
51         'key'               => GPG_KEY_ID,
52         'key_server'        => 'pgp.mit.edu',
53         'key_content'       => 'GPG key content',
54         'key_source'        => 'http://apt.puppetlabs.com/pubkey.gpg',
55         'pin'               => '10',
56         'architecture'      => 'x86_64',
57         'trusted_source'    => true,
58       }
59     end
60
61     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/)
62     }
63
64     it { is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with({
65       'ensure'   => 'present',
66       'priority' => '10',
67       'origin'   => 'debian.mirror.iweb.ca',
68     })
69     }
70
71     it { is_expected.to contain_exec("Required packages: 'vim' for my_source").that_comes_before('Apt::Setting[list-my_source]').with({
72       'command'     => '/usr/bin/apt-get -y install vim',
73       'logoutput'   => 'on_failure',
74       'refreshonly' => true,
75       'tries'       => '3',
76       'try_sleep'   => '1',
77     })
78     }
79
80     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({
81       'ensure' => 'present',
82       'id'  => GPG_KEY_ID,
83       'key_server' => 'pgp.mit.edu',
84       'key_content' => 'GPG key content',
85       'key_source' => 'http://apt.puppetlabs.com/pubkey.gpg',
86     })
87     }
88   end
89
90   context 'trusted_source true' do
91     let :facts do
92       {
93         :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
94         :lsbdistid       => 'Debian',
95         :lsbdistcodename => 'wheezy',
96         :osfamily        => 'Debian',
97         :puppetversion   => Puppet.version,
98       }
99     end
100     let :params do
101       {
102         'include_src'    => false,
103         'location'       => 'http://debian.mirror.iweb.ca/debian/',
104         'trusted_source' => true,
105       }
106     end
107
108     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/) }
109   end
110
111   context 'architecture equals x86_64' do
112     let :facts do
113       {
114         :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
115         :lsbdistid       => 'Debian',
116         :lsbdistcodename => 'wheezy',
117         :osfamily        => 'Debian',
118         :puppetversion   => Puppet.version,
119       }
120     end
121     let :params do
122       {
123         'location'     => 'http://debian.mirror.iweb.ca/debian/',
124         'architecture' => 'x86_64',
125       }
126     end
127
128     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/)
129     }
130   end
131
132   context 'ensure => absent' do
133     let :facts do
134       {
135         :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
136         :lsbdistid       => 'Debian',
137         :lsbdistcodename => 'wheezy',
138         :osfamily        => 'Debian',
139         :puppetversion   => Puppet.version,
140       }
141     end
142     let :params do
143       {
144         'ensure' => 'absent',
145       }
146     end
147
148     it { is_expected.to contain_apt__setting('list-my_source').with({
149       'ensure' => 'absent'
150     })
151     }
152   end
153
154   describe 'validation' do
155     context 'no release' do
156       let :facts do
157         {
158           :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
159           :lsbdistid       => 'Debian',
160           :osfamily        => 'Debian',
161           :puppetversion   => Puppet.version,
162         }
163       end
164
165       it do
166         expect { subject.call }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/)
167       end
168     end
169   end
170 end