File: static_loader_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 (85 lines) | stat: -rw-r--r-- 2,118 bytes parent folder | download | duplicates (2)
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
require 'spec_helper'
require 'puppet/pops'
require 'puppet/loaders'

describe 'the static loader' do
  let(:loader) do
    loader = Puppet::Pops::Loader::StaticLoader.new()
    loader.runtime_3_init
    loader
  end

  it 'has no parent' do
    expect(loader.parent).to be(nil)
  end

  it 'identifies itself in string form' do
    expect(loader.to_s).to be_eql('(StaticLoader)')
  end

  it 'support the Loader API' do
    # it may produce things later, this is just to test that calls work as they should - now all lookups are nil.
    a_typed_name = typed_name(:function, 'foo')
    expect(loader[a_typed_name]).to be(nil)
    expect(loader.load_typed(a_typed_name)).to be(nil)
    expect(loader.find(a_typed_name)).to be(nil)
  end

  context 'provides access to resource types built into puppet' do
    %w{
      Component
      Exec
      File
      Filebucket
      Group
      Notify
      Package
      Resources
      Schedule
      Service
      Stage
      Tidy
      User
      Whit
    }.each do |name |
      it "such that #{name} is available" do
        expect(loader.load(:type, name.downcase)).to be_the_type(resource_type(name))
      end
    end
  end

  context 'provides access to app-management specific resource types built into puppet' do
    it "such that Node is available" do
      expect(loader.load(:type, 'node')).to be_the_type(resource_type('Node'))
    end
  end

  context 'without init_runtime3 initialization' do
    let(:loader) { Puppet::Pops::Loader::StaticLoader.new() }

    it 'does not provide access to resource types built into puppet' do
      expect(loader.load(:type, 'file')).to be_nil
    end
  end

  def typed_name(type, name)
    Puppet::Pops::Loader::TypedName.new(type, name)
  end

  def resource_type(name)
    Puppet::Pops::Types::TypeFactory.resource(name)
  end

  matcher :be_the_type do |type|
    calc = Puppet::Pops::Types::TypeCalculator.new

    match do |actual|
      calc.assignable?(actual, type) && calc.assignable?(type, actual)
    end

    failure_message do |actual|
      "expected #{type.to_s}, but was #{actual.to_s}"
    end
  end

end