Sha256: 81096472da2161c1ebb26546d20b69099d589d3dd11994e840246ed6b42d840e

Contents?: true

Size: 1.86 KB

Versions: 340

Compression:

Stored size: 1.86 KB

Contents

require 'spec_helper'
require 'puppet_spec/compiler'
require 'matchers/resource'
require 'puppet_spec/files'

describe 'the module_directory function' do
  include PuppetSpec::Compiler
  include Matchers::Resource
  include PuppetSpec::Files

  it 'returns first found module from one or more given names' do
    mod = double('module')
    allow(mod).to receive(:path).and_return('expected_path')
    Puppet[:code] = "notify { module_directory('one', 'two'):}"
    node = Puppet::Node.new('localhost')
    compiler = Puppet::Parser::Compiler.new(node)
    allow(compiler.environment).to receive(:module).with('one').and_return(nil)
    allow(compiler.environment).to receive(:module).with('two').and_return(mod)
    expect(compiler.compile()).to have_resource("Notify[expected_path]")
  end

  it 'returns first found module from one or more given names in an array' do
    mod = double('module')
    allow(mod).to receive(:path).and_return('expected_path')
    Puppet[:code] = "notify { module_directory(['one', 'two']):}"
    node = Puppet::Node.new('localhost')
    compiler = Puppet::Parser::Compiler.new(node)
    allow(compiler.environment).to receive(:module).with('one').and_return(nil)
    allow(compiler.environment).to receive(:module).with('two').and_return(mod)
    expect(compiler.compile()).to have_resource("Notify[expected_path]")
  end

  it 'returns undef when none of the modules were found' do
    mod = double('module')
    allow(mod).to receive(:path).and_return('expected_path')
    Puppet[:code] = "notify { String(type(module_directory('one', 'two'))):}"
    node = Puppet::Node.new('localhost')
    compiler = Puppet::Parser::Compiler.new(node)
    allow(compiler.environment).to receive(:module).with('one').and_return(nil)
    allow(compiler.environment).to receive(:module).with('two').and_return(nil)
    expect(compiler.compile()).to have_resource("Notify[Undef]")
  end
end

Version data entries

340 entries across 340 versions & 1 rubygems

Version Path
puppet-8.3.0 spec/unit/functions/module_directory_spec.rb
puppet-8.3.0-x86-mingw32 spec/unit/functions/module_directory_spec.rb
puppet-8.3.0-x64-mingw32 spec/unit/functions/module_directory_spec.rb
puppet-8.3.0-universal-darwin spec/unit/functions/module_directory_spec.rb
puppet-8.4.0 spec/unit/functions/module_directory_spec.rb
puppet-8.4.0-x86-mingw32 spec/unit/functions/module_directory_spec.rb
puppet-8.4.0-x64-mingw32 spec/unit/functions/module_directory_spec.rb
puppet-8.4.0-universal-darwin spec/unit/functions/module_directory_spec.rb
puppet-7.28.0 spec/unit/functions/module_directory_spec.rb
puppet-7.28.0-x86-mingw32 spec/unit/functions/module_directory_spec.rb
puppet-7.28.0-x64-mingw32 spec/unit/functions/module_directory_spec.rb
puppet-7.28.0-universal-darwin spec/unit/functions/module_directory_spec.rb
puppet-8.3.1 spec/unit/functions/module_directory_spec.rb
puppet-8.3.1-x86-mingw32 spec/unit/functions/module_directory_spec.rb
puppet-8.3.1-x64-mingw32 spec/unit/functions/module_directory_spec.rb
puppet-8.3.1-universal-darwin spec/unit/functions/module_directory_spec.rb
puppet-7.27.0 spec/unit/functions/module_directory_spec.rb
puppet-7.27.0-x86-mingw32 spec/unit/functions/module_directory_spec.rb
puppet-7.27.0-x64-mingw32 spec/unit/functions/module_directory_spec.rb
puppet-7.27.0-universal-darwin spec/unit/functions/module_directory_spec.rb