Sha256: d70eebefd22ed364578d4248d99204060b581b2a72971f1ac30ae86bcd1b18d2

Contents?: true

Size: 1.38 KB

Versions: 300

Compression:

Stored size: 1.38 KB

Contents

require 'spec_helper'

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

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

  context 'for an array' do
    it 'partitions by item' do
      manifest = "notify { String(partition(['', b, ab]) |$s| { $s.empty }): }"
      expect(compile_to_catalog(manifest)).to have_resource("Notify[[[''], ['b', 'ab']]]")
    end

    it 'partitions by index, item' do
      manifest = "notify { String(partition(['', b, ab]) |$i, $s| { $i == 2 or $s.empty }): }"
      expect(compile_to_catalog(manifest)).to have_resource("Notify[[['', 'ab'], ['b']]]")
    end
  end

  context 'for a hash' do
    it 'partitions by key-value pair' do
      manifest = "notify { String(partition(a => [1, 2], b => []) |$kv| { $kv[1].empty }): }"
      expect(compile_to_catalog(manifest)).to have_resource("Notify[[[['b', []]], [['a', [1, 2]]]]]")
    end

    it 'partitions by key, value' do
      manifest = "notify { String(partition(a => [1, 2], b => []) |$k, $v| { $v.empty }): }"
      expect(compile_to_catalog(manifest)).to have_resource("Notify[[[['b', []]], [['a', [1, 2]]]]]")
    end
  end

  context 'for a string' do
    it 'fails' do
      manifest = "notify { String(partition('something') |$s| { $s.empty }): }"
      expect { compile_to_catalog(manifest) }.to raise_error(Puppet::PreformattedError)
    end
  end
end

Version data entries

300 entries across 300 versions & 1 rubygems

Version Path
puppet-8.2.0 spec/unit/functions/partition_spec.rb
puppet-8.2.0-x86-mingw32 spec/unit/functions/partition_spec.rb
puppet-8.2.0-x64-mingw32 spec/unit/functions/partition_spec.rb
puppet-8.2.0-universal-darwin spec/unit/functions/partition_spec.rb
puppet-7.26.0 spec/unit/functions/partition_spec.rb
puppet-7.26.0-x86-mingw32 spec/unit/functions/partition_spec.rb
puppet-7.26.0-x64-mingw32 spec/unit/functions/partition_spec.rb
puppet-7.26.0-universal-darwin spec/unit/functions/partition_spec.rb
puppet-7.25.0 spec/unit/functions/partition_spec.rb
puppet-7.25.0-x86-mingw32 spec/unit/functions/partition_spec.rb
puppet-7.25.0-x64-mingw32 spec/unit/functions/partition_spec.rb
puppet-7.25.0-universal-darwin spec/unit/functions/partition_spec.rb
puppet-8.1.0 spec/unit/functions/partition_spec.rb
puppet-8.1.0-x86-mingw32 spec/unit/functions/partition_spec.rb
puppet-8.1.0-x64-mingw32 spec/unit/functions/partition_spec.rb
puppet-8.1.0-universal-darwin spec/unit/functions/partition_spec.rb
puppet-8.0.1 spec/unit/functions/partition_spec.rb
puppet-8.0.1-x86-mingw32 spec/unit/functions/partition_spec.rb
puppet-8.0.1-x64-mingw32 spec/unit/functions/partition_spec.rb
puppet-8.0.1-universal-darwin spec/unit/functions/partition_spec.rb