File: module_directory_spec.rb

package info (click to toggle)
puppet 5.5.10-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 21,116 kB
  • sloc: ruby: 250,669; sh: 1,620; xml: 218; makefile: 151; sql: 103
file content (43 lines) | stat: -rw-r--r-- 1,763 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
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 = mock 'module'
    mod.stubs(:path).returns('expected_path')
    Puppet[:code] = "notify { module_directory('one', 'two'):}"
    node = Puppet::Node.new('localhost')
    compiler = Puppet::Parser::Compiler.new(node)
    compiler.environment.stubs(:module).with('one').returns(nil)
    compiler.environment.stubs(:module).with('two').returns(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 = mock 'module'
    mod.stubs(:path).returns('expected_path')
    Puppet[:code] = "notify { module_directory(['one', 'two']):}"
    node = Puppet::Node.new('localhost')
    compiler = Puppet::Parser::Compiler.new(node)
    compiler.environment.stubs(:module).with('one').returns(nil)
    compiler.environment.stubs(:module).with('two').returns(mod)
    expect(compiler.compile()).to have_resource("Notify[expected_path]")
  end

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