summaryrefslogtreecommitdiff
path: root/spec/defines/conf_spec.rb
blob: 167b249c7d69a6d7101af0cfd659b5ac8905a347 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
require 'spec_helper'
describe 'apt::apt_conf', :type => :define do
  let :pre_condition do
    'class { "apt": }'
  end
  let(:facts) { {
    :lsbdistid           => 'Debian',
    :osfamily            => 'Debian',
    :operatingsystem     => 'Debian',
    :debian_release      => 'jessie',
    :debian_codename     => 'jessie',
    :lsbdistcodename     => 'jessie',
    :debian_nextcodename => 'stretch',
    :virtual             => 'physical',
    :puppetversion       => Puppet.version, } }
  let :title do
    'norecommends'
  end

  describe "when creating an apt_conf snippet" do
    let :default_params do
      {
        :ensure  => 'present',
        :content  => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n"
      }
    end
    let :params do
      default_params
    end
    let :filename do
      "/etc/apt/apt.conf.d/norecommends"
    end

    it { is_expected.to contain_file(filename).with({
          'ensure'    => 'present',
          'content'   => /Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;/,
          'owner'     => 'root',
          # default to '0', not 'root'
          #'group'     => 'root',
          'mode'      => '0644',
        })
      }

  end

  describe "when creating a preference without content" do
    let :params do
      {
        :ensure   => 'absent',
      }
    end

    it 'fails' do
      expect { subject.call } .to raise_error(Puppet::Error, /One of \$source or \$content must be specified for apt_conf norecommends/)
    end
  end

  describe "when removing an apt preference" do
    let :params do
      {
        :ensure   => 'absent',
        :content  => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n",
      }
    end

    let :filename do
      "/etc/apt/apt.conf.d/norecommends"
    end

    it { is_expected.to contain_file(filename).with({
        'ensure'    => 'absent',
      })
    }
  end
end