]> review.fuel-infra Code Review - puppet-modules/puppetlabs-apt.git/blob - spec/classes/apt_spec.rb
Merge pull request #14 from haus/ticket/12094_add_spec_tests
[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         default_params.merge(param_set)
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 contain_file("sources.list").with({
39           'path'    => "/etc/apt/sources.list",
40           'ensure'  => "present",
41           'owner'   => "root",
42           'group'   => "root",
43           'mode'    => 644
44         })
45       }
46
47       it {
48         should create_file("sources.list.d").with({
49           "path"    => "/etc/apt/sources.list.d",
50           "ensure"  => "directory",
51           "owner"   => "root",
52           "group"   => "root"
53         })
54       }
55
56       it {
57         should contain_exec("apt_update").with({
58           'command'     => "/usr/bin/apt-get update",
59           'subscribe'   => ["File[sources.list]", "File[sources.list.d]"],
60           'refreshonly' => refresh_only_apt_update
61         })
62       }
63
64       it {
65         if param_hash[:disable_keys]
66           should contain_exec("make-apt-insecure").with({
67             'command'   => '/bin/echo "APT::Get::AllowUnauthenticated 1;" >> /etc/apt/apt.conf.d/99unauth',
68             'creates'   => '/etc/apt/apt.conf.d/99unauth'
69           })
70         else
71           should_not contain_exec("make-apt-insecure").with({
72             'command'   => '/bin/echo "APT::Get::AllowUnauthenticated 1;" >> /etc/apt/apt.conf.d/99unauth',
73             'creates'   => '/etc/apt/apt.conf.d/99unauth'
74           })
75         end
76       }
77     end
78   end
79 end