File: then_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 (40 lines) | stat: -rw-r--r-- 1,271 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
32
33
34
35
36
37
38
39
40
require 'spec_helper'

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

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

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

  it 'produces what lambda returns if value is not undef' do
    expect(compile_to_catalog("notify{ then(1) |$x| { testing }: }")).to have_resource('Notify[testing]')
  end

  it 'does not call lambda if argument is undef' do
    expect(compile_to_catalog('then(undef) |$x| { notify { "failed": } }')).to_not have_resource('Notify[failed]')
  end

  it 'produces undef if given value is undef' do
    expect(compile_to_catalog(<<-SOURCE)).to have_resource('Notify[test-Undef-ing]')
    notify{ "test-${type(then(undef) |$x| { testing })}-ing": }
    SOURCE
  end

  it 'errors when lambda wants too many args' do
    expect do
      compile_to_catalog('then(1) |$x, $y| { }')
    end.to raise_error(/'then' block expects 1 argument, got 2/m)
  end

  it 'errors when lambda wants too few args' do
    expect do
      compile_to_catalog('then(1) || { }')
    end.to raise_error(/'then' block expects 1 argument, got none/m)
  end

end