a858180455b74c0848fa59118b70cd0b63c0fe17
[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     }
15   ].each do |param_set|
16     describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
17       let :param_hash do
18         param_set == {} ? default_params : params
19       end
20
21       let :params do
22         param_set
23       end
24
25       let :refresh_only_apt_update do
26         if param_hash[:always_apt_update]
27           false
28         else
29           true
30         end
31       end
32
33       it { should include_class("apt::params") }
34
35       it { should contain_package("python-software-properties") }
36
37       it {
38         should create_file("sources.list")\
39           .with_path("/etc/apt/sources.list")\
40           .with_ensure("present")\
41           .with_owner("root")\
42           .with_group("root")\
43           .with_mode(644)
44       }
45
46       it {
47         should create_file("sources.list.d")\
48           .with_path("/etc/apt/sources.list.d")\
49           .with_ensure("directory")\
50           .with_owner("root")\
51           .with_group("root")
52       }
53
54       it {
55         should create_exec("apt_update")\
56           .with_command("/usr/bin/apt-get update")\
57           .with_subscribe(["File[sources.list]", "File[sources.list.d]"])\
58           .with_refreshonly(refresh_only_apt_update)
59       }
60
61       it {
62         if param_hash[:disable_keys]
63           should create_exec("make-apt-insecure")\
64             .with_command('/bin/echo "APT::Get::AllowUnauthenticated 1;" >> /etc/apt/apt.conf.d/99unauth')\
65             .with_creates('/etc/apt/apt.conf.d/99unauth')
66         else
67           should_not create_exec("make-apt-insecure")\
68             .with_command('/bin/echo "APT::Get::AllowUnauthenticated 1;" >> /etc/apt/apt.conf.d/99unauth')\
69             .with_creates('/etc/apt/apt.conf.d/99unauth')
70         end
71       }
72     end
73   end
74 end