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