summaryrefslogtreecommitdiffstats
path: root/spec/unit/util/run_mode_spec.rb
blob: 5d9a3d058222ff76f0e1597bae1f0d1773eabc8b (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
#!/usr/bin/env rspec
require 'spec_helper'

describe Puppet::Util::RunMode do
  before do
    @run_mode = Puppet::Util::RunMode.new('fake')
  end

  it "should have confdir /etc/puppet when run as root" do
    Puppet.features.stubs(:root?).returns(true)
    etcdir = Puppet.features.microsoft_windows? ? File.join(Dir::WINDOWS, "puppet", "etc") : '/etc/puppet'
    # REMIND: issue with windows backslashes
    @run_mode.conf_dir.should == File.expand_path(etcdir)
  end

  it "should have confdir ~/.puppet when run as non-root" do
    Puppet.features.stubs(:root?).returns(false)
    @run_mode.expects(:expand_path).with("~/.puppet").returns("~/.puppet")
    @run_mode.conf_dir.should == "~/.puppet"
  end

  it "should have vardir /var/lib/puppet when run as root" do
    Puppet.features.stubs(:root?).returns(true)
    vardir = Puppet.features.microsoft_windows? ? File.join(Dir::WINDOWS, "puppet", "var") : '/var/lib/puppet'
    # REMIND: issue with windows backslashes
    @run_mode.var_dir.should == File.expand_path(vardir)
  end

  it "should have vardir ~/.puppet/var when run as non-root" do
    Puppet.features.stubs(:root?).returns(false)
    @run_mode.expects(:expand_path).with("~/.puppet/var").returns("~/.puppet/var")
    @run_mode.var_dir.should == "~/.puppet/var"
  end

  it "should have rundir depend on vardir" do
    @run_mode.run_dir.should == '$vardir/run'
  end

  it "should have logopts return an array with $vardir/log if runmode is not master" do
    @run_mode.expects(:master?).returns false
    @run_mode.logopts.should == ["$vardir/log", "The Puppet log directory."]
  end

  it "should have logopts return a hash with $vardir/log and other metadata if runmode is master" do
    @run_mode.expects(:master?).returns true
    @run_mode.logopts.should == {
      :default => "$vardir/log",
      :mode    => 0750,
      :owner   => "service",
      :group   => "service",
      :desc    => "The Puppet log directory.",
    }
  end
end