summaryrefslogtreecommitdiff
path: root/spec/unit/plugins/root_group_spec.rb
blob: f8492e69296db1e7992b2baf1e618bddd327dff0 (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#
# Author:: Joseph Anthony Pasquale Holsten (<joseph@josephholsten.com>)
# Copyright:: Copyright (c) 2013 Joseph Anthony Pasquale Holsten
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')

ORIGINAL_CONFIG_HOST_OS = ::RbConfig::CONFIG['host_os']

describe Ohai::System, 'root_group' do
  before(:each) do
    @ohai = Ohai::System.new
    @plugin = Ohai::DSL::Plugin.new(@ohai, "root_group", File.join(PLUGIN_PATH, "root_group.rb"))
    @plugin.stub(:require_plugin)
  end

  describe 'unix platform', :unix_only do
    before(:each) do
      # this is deeply intertwingled. unfortunately, the law of demeter
      # apparently didn't apply to this api. we're just trying to fake
      # Etc.getgrgid(Etc.getpwnam('root').gid).name
      @pwnam = Object.new
      @pwnam.stub(:gid).and_return(0)
      Etc.stub(:getpwnam).with('root').and_return(@pwnam)
      @grgid = Object.new
      Etc.stub(:getgrgid).and_return(@grgid)
    end

    describe 'with wheel group' do
      before(:each) do
        @grgid.stub(:name).and_return('wheel')
      end
      it 'should have a root_group of wheel' do
        @plugin.run
        @plugin[:root_group].should == 'wheel'
      end
    end

    describe 'with root group' do
      before(:each) do
        @grgid.stub(:name).and_return('root')
      end
      it 'should have a root_group of root' do
        @plugin.run
        @plugin[:root_group].should == 'root'
      end
    end

    describe 'platform hpux with sys group' do
      before(:each) do
        @pwnam.stub(:gid).and_return(3)
        @grgid.stub(:name).and_return('sys')
      end
      it 'should have a root_group of sys' do
        @plugin.run
        @plugin[:root_group].should == 'sys'
      end
    end
    describe 'platform aix with system group' do
      before(:each) do
        @grgid.stub(:name).and_return('system')
      end
      it 'should have a root_group of system' do
        @plugin.run
        @plugin[:root_group].should == 'system'
      end
    end
  end

  describe 'windows', :windows_only do

    # TODO: Not implemented on windows.
    # See also:
    #
    # http://tickets.opscode.com/browse/OHAI-490
    # http://tickets.opscode.com/browse/OHAI-491

  end
end