File: with_spec.rb

package info (click to toggle)
puppet 5.5.22-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 21,316 kB
  • sloc: ruby: 254,925; sh: 1,608; xml: 219; makefile: 153; sql: 103
file content (31 lines) | stat: -rw-r--r-- 1,123 bytes parent folder | download | duplicates (6)
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
require 'spec_helper'

require 'puppet_spec/compiler'
require 'matchers/resource'

describe 'the with function' do
  include PuppetSpec::Compiler
  include Matchers::Resource

  it 'calls a lambda passing no arguments' do
    expect(compile_to_catalog("with() || { notify { testing: } }")).to have_resource('Notify[testing]')
  end

  it 'calls a lambda passing a single argument' do
    expect(compile_to_catalog('with(1) |$x| { notify { "testing$x": } }')).to have_resource('Notify[testing1]')
  end

  it 'calls a lambda passing more than one argument' do
    expect(compile_to_catalog('with(1, 2) |*$x| { notify { "testing${x[0]}, ${x[1]}": } }')).to have_resource('Notify[testing1, 2]')
  end

  it 'passes a type reference to a lambda' do
    expect(compile_to_catalog('notify { test: message => "data" } with(Notify[test]) |$x| { notify { "${x[message]}": } }')).to have_resource('Notify[data]')
  end

  it 'errors when not given enough arguments for the lambda' do
    expect do
      compile_to_catalog('with(1) |$x, $y| { }')
    end.to raise_error(/Parameter \$y is required but no value was given/m)
  end
end