File: computer_spec.rb

package info (click to toggle)
puppet 5.5.22-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 21,316 kB
  • sloc: ruby: 254,925; sh: 1,608; xml: 219; makefile: 153; sql: 103
file content (77 lines) | stat: -rw-r--r-- 2,523 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
require 'spec_helper'

computer = Puppet::Type.type(:computer)

describe Puppet::Type.type(:computer), " when checking computer objects" do
  before do
    provider_class = Puppet::Type::Computer.provider(Puppet::Type::Computer.providers[0])
    expect(Puppet::Type::Computer).to receive(:defaultprovider).and_return(provider_class)

    @resource = Puppet::Type::Computer.new(
      :name => "puppetcomputertest",
      :en_address => "aa:bb:cc:dd:ee:ff",
      :ip_address => "1.2.3.4")
    @properties = {}
    @ensure = Puppet::Type::Computer.attrclass(:ensure).new(:resource => @resource)
  end

  it "should be able to create an instance" do
    provider_class = Puppet::Type::Computer.provider(Puppet::Type::Computer.providers[0])
    expect(Puppet::Type::Computer).to receive(:defaultprovider).and_return(provider_class)
    expect(computer.new(:name => "bar")).not_to be_nil
  end

  properties = [:en_address, :ip_address]
  params = [:name]

  properties.each do |property|
    it "should have a #{property} property" do
      expect(computer.attrclass(property).ancestors).to be_include(Puppet::Property)
    end

    it "should have documentation for its #{property} property" do
      expect(computer.attrclass(property).doc).to be_instance_of(String)
    end

    it "should accept :absent as a value" do
      prop = computer.attrclass(property).new(:resource => @resource)
      prop.should = :absent
      expect(prop.should).to eq(:absent)
    end
  end

  params.each do |param|
    it "should have a #{param} parameter" do
      expect(computer.attrclass(param).ancestors).to be_include(Puppet::Parameter)
    end

    it "should have documentation for its #{param} parameter" do
      expect(computer.attrclass(param).doc).to be_instance_of(String)
    end
  end

  describe "default values" do
    before do
      provider_class = computer.provider(computer.providers[0])
      expect(computer).to receive(:defaultprovider).and_return(provider_class)
    end

    it "should be nil for en_address" do
      expect(computer.new(:name => :en_address)[:en_address]).to eq(nil)
    end

    it "should be nil for ip_address" do
      expect(computer.new(:name => :ip_address)[:ip_address]).to eq(nil)
    end
  end

  describe "when managing the ensure property" do
    it "should support a :present value" do
      expect { @ensure.should = :present }.not_to raise_error
    end

    it "should support an :absent value" do
      expect { @ensure.should = :absent }.not_to raise_error
    end
  end
end