File: freebsd_spec.rb

package info (click to toggle)
puppet-agent 7.23.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 19,092 kB
  • sloc: ruby: 245,074; sh: 456; makefile: 38; xml: 33
file content (92 lines) | stat: -rw-r--r-- 3,137 bytes parent folder | download
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
require 'spec_helper'

describe 'Puppet::Type::Service::Provider::Freebsd',
         unless: Puppet::Util::Platform.windows? || Puppet::Util::Platform.jruby? do
  let(:provider_class) { Puppet::Type.type(:service).provider(:freebsd) }

  before :each do
    @provider = provider_class.new
    allow(@provider).to receive(:initscript)
    allow(Facter).to receive(:value).with(:osfamily).and_return('FreeBSD')
  end

  it "should correctly parse rcvar for FreeBSD < 7" do
    allow(@provider).to receive(:execute).and_return(<<OUTPUT)
# ntpd
$ntpd_enable=YES
OUTPUT
    expect(@provider.rcvar).to eq(['# ntpd', 'ntpd_enable=YES'])
  end

  it "should correctly parse rcvar for FreeBSD 7 to 8" do
    allow(@provider).to receive(:execute).and_return(<<OUTPUT)
# ntpd
ntpd_enable=YES
OUTPUT
    expect(@provider.rcvar).to eq(['# ntpd', 'ntpd_enable=YES'])
  end

  it "should correctly parse rcvar for FreeBSD >= 8.1" do
    allow(@provider).to receive(:execute).and_return(<<OUTPUT)
# ntpd
#
ntpd_enable="YES"
#   (default: "")
OUTPUT
    expect(@provider.rcvar).to eq(['# ntpd', 'ntpd_enable="YES"', '#   (default: "")'])
  end

  it "should correctly parse rcvar for DragonFly BSD" do
    allow(@provider).to receive(:execute).and_return(<<OUTPUT)
# ntpd
$ntpd=YES
OUTPUT
    expect(@provider.rcvar).to eq(['# ntpd', 'ntpd=YES'])
  end

  it 'should parse service names with a description' do
    allow(@provider).to receive(:execute).and_return(<<OUTPUT)
# local_unbound : local caching forwarding resolver
local_unbound_enable="YES"
OUTPUT
    expect(@provider.service_name).to eq('local_unbound')
  end

  it 'should parse service names without a description' do
    allow(@provider).to receive(:execute).and_return(<<OUTPUT)
# local_unbound
local_unbound="YES"
OUTPUT
    expect(@provider.service_name).to eq('local_unbound')
  end

  it "should find the right rcvar_value for FreeBSD < 7" do
    allow(@provider).to receive(:rcvar).and_return(['# ntpd', 'ntpd_enable=YES'])

    expect(@provider.rcvar_value).to eq("YES")
  end

  it "should find the right rcvar_value for FreeBSD >= 7" do
    allow(@provider).to receive(:rcvar).and_return(['# ntpd', 'ntpd_enable="YES"', '#   (default: "")'])

    expect(@provider.rcvar_value).to eq("YES")
  end

  it "should find the right rcvar_name" do
    allow(@provider).to receive(:rcvar).and_return(['# ntpd', 'ntpd_enable="YES"'])

    expect(@provider.rcvar_name).to eq("ntpd")
  end

  it "should enable only the selected service" do
    allow(Puppet::FileSystem).to receive(:exist?).with('/etc/rc.conf').and_return(true)
    allow(File).to receive(:read).with('/etc/rc.conf').and_return("openntpd_enable=\"NO\"\nntpd_enable=\"NO\"\n")
    fh = double('fh')
    allow(Puppet::FileSystem).to receive(:replace_file).with('/etc/rc.conf').and_yield(fh)
    expect(fh).to receive(:<<).with("openntpd_enable=\"NO\"\nntpd_enable=\"YES\"\n")
    allow(Puppet::FileSystem).to receive(:exist?).with('/etc/rc.conf.local').and_return(false)
    allow(Puppet::FileSystem).to receive(:exist?).with('/etc/rc.conf.d/ntpd').and_return(false)

    @provider.rc_replace('ntpd', 'ntpd', 'YES')
  end
end