summaryrefslogtreecommitdiff
path: root/spec/unit/parser/functions/realize_spec.rb
blob: 79e5eb155e9e29373ae248795f847867ecdd73c3 (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
require 'spec_helper'
require 'matchers/resource'
require 'puppet_spec/compiler'

describe "the realize function" do
  include Matchers::Resource
  include PuppetSpec::Compiler

  it "realizes a single, referenced resource" do
    catalog = compile_to_catalog(<<-EOM)
      @notify { testing: }
      realize(Notify[testing])
    EOM

    expect(catalog).to have_resource("Notify[testing]")
  end

  it "realizes multiple resources" do
    catalog = compile_to_catalog(<<-EOM)
      @notify { testing: }
      @notify { other: }
      realize(Notify[testing], Notify[other])
    EOM

    expect(catalog).to have_resource("Notify[testing]")
    expect(catalog).to have_resource("Notify[other]")
  end

  it "realizes resources provided in arrays" do
    catalog = compile_to_catalog(<<-EOM)
      @notify { testing: }
      @notify { other: }
      realize([Notify[testing], [Notify[other]]])
    EOM

    expect(catalog).to have_resource("Notify[testing]")
    expect(catalog).to have_resource("Notify[other]")
  end

  it "fails when the resource does not exist" do
    expect do
      compile_to_catalog(<<-EOM)
        realize(Notify[missing])
      EOM
    end.to raise_error(Puppet::Error, /Failed to realize/)
  end

  it "fails when no parameters given" do
    expect do
      compile_to_catalog(<<-EOM)
        realize()
      EOM
    end.to raise_error(Puppet::Error, /Wrong number of arguments/)
  end

  it "silently does nothing when an empty array of resources is given" do
    compile_to_catalog(<<-EOM)
      realize([])
    EOM
  end
end