1c7c18f4c2b6bdc1e1ee8faf858126212da903a1
[puppet-modules/puppetlabs-apt.git] / spec / classes / apt_spec.rb
1 require 'spec_helper'
2 describe 'apt', :type => :class do
3   let :default_params do
4     {
5       :disable_keys => false,
6       :always_apt_update => false
7     }
8   end
9
10   [{},
11    {
12       :disable_keys => true,
13       :always_apt_update => true,
14       :proxy_host => true,
15       :proxy_port => '3128'
16     }
17   ].each do |param_set|
18     describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
19       let :param_hash do
20         default_params.merge(param_set)
21       end
22
23       let :params do
24         param_set
25       end
26
27       let :refresh_only_apt_update do
28         if param_hash[:always_apt_update]
29           false
30         else
31           true
32         end
33       end
34
35       it { should include_class("apt::params") }
36
37       it { should contain_package("python-software-properties") }
38
39       it {
40         should contain_file("sources.list").with({
41           'path'    => "/etc/apt/sources.list",
42           'ensure'  => "present",
43           'owner'   => "root",
44           'group'   => "root",
45           'mode'    => 644
46         })
47       }
48
49       it {
50         should create_file("sources.list.d").with({
51           "path"    => "/etc/apt/sources.list.d",
52           "ensure"  => "directory",
53           "owner"   => "root",
54           "group"   => "root"
55         })
56       }
57
58       it {
59         should contain_exec("apt_update").with({
60           'command'     => "/usr/bin/apt-get update",
61           'subscribe'   => ["File[sources.list]", "File[sources.list.d]"],
62           'refreshonly' => refresh_only_apt_update
63         })
64       }
65
66       it {
67         if param_hash[:disable_keys]
68           should contain_exec("make-apt-insecure").with({
69             'command'   => '/bin/echo "APT::Get::AllowUnauthenticated 1;" >> /etc/apt/apt.conf.d/99unauth',
70             'creates'   => '/etc/apt/apt.conf.d/99unauth'
71           })
72         else
73           should_not contain_exec("make-apt-insecure").with({
74             'command'   => '/bin/echo "APT::Get::AllowUnauthenticated 1;" >> /etc/apt/apt.conf.d/99unauth',
75             'creates'   => '/etc/apt/apt.conf.d/99unauth'
76           })
77         end
78       }
79       describe 'when setting a proxy' do
80         it {
81           if param_hash[:proxy_host]
82             should contain_file('configure-apt-proxy').with(
83               'path'    => '/etc/apt/apt.conf.d/proxy',
84               'content' => "Acquire::http::Proxy \"http://#{param_hash[:proxy_host]}:#{param_hash[:proxy_port]}\";"
85             )
86           else
87             should_not contain_file('configure_apt_proxy')
88           end
89         }
90       end
91     end
92   end
93 end