Sha256: b8f5daa02737be833cb75bae415aa11cde2a2c1ec662a7d9818bd89f91d66830

Contents?: true

Size: 1.24 KB

Versions: 576

Compression:

Stored size: 1.24 KB

Contents

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

Version data entries

576 entries across 576 versions & 1 rubygems

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