Sha256: e27ef931aabfcd40c0c0b9835b7f4f3c00088ae461c61d4acc0b6314759247c3

Contents?: true

Size: 1.78 KB

Versions: 4

Compression:

Stored size: 1.78 KB

Contents

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

  it 'is not available when --tasks is on' do
    Puppet[:tasks] = true
    expect do
      catalog = compile_to_catalog(<<-MANIFEST)
        realize([])
      MANIFEST
    end.to raise_error(Puppet::ParseError, /is only available when compiling a catalog/)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
puppet-5.4.0 spec/unit/parser/functions/realize_spec.rb
puppet-5.4.0-x86-mingw32 spec/unit/parser/functions/realize_spec.rb
puppet-5.4.0-x64-mingw32 spec/unit/parser/functions/realize_spec.rb
puppet-5.4.0-universal-darwin spec/unit/parser/functions/realize_spec.rb