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