File: user_attr_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 (45 lines) | stat: -rw-r--r-- 1,457 bytes parent folder | download | duplicates (3)
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
require 'spec_helper'

require 'puppet/util/user_attr'

describe UserAttr do
  before do
    user_attr = ["foo::::type=role", "bar::::type=normal;profile=foobar"]
    allow(File).to receive(:readlines).and_return(user_attr)
  end

  describe "when getting attributes by name" do
    it "should return nil if there is no entry for that name" do
      expect(UserAttr.get_attributes_by_name('baz')).to eq(nil)
    end

    it "should return a hash if there is an entry in /etc/user_attr" do
      expect(UserAttr.get_attributes_by_name('foo').class).to eq(Hash)
    end

    it "should return a hash with the name value from /etc/user_attr" do
      expect(UserAttr.get_attributes_by_name('foo')[:name]).to eq('foo')
    end

    #this test is contrived
    #there are a bunch of possible parameters that could be in the hash
    #the role/normal is just a the convention of the file
    describe "when the name is a role" do
      it "should contain :type = role" do
        expect(UserAttr.get_attributes_by_name('foo')[:type]).to eq('role')
      end
    end

    describe "when the name is not a role" do
      it "should contain :type = normal" do
        expect(UserAttr.get_attributes_by_name('bar')[:type]).to eq('normal')
      end
    end

    describe "when the name has more attributes" do
      it "should contain all the attributes" do
        expect(UserAttr.get_attributes_by_name('bar')[:profile]).to eq('foobar')
      end
    end
  end
end