File: values_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 (30 lines) | stat: -rw-r--r-- 941 bytes parent folder | download | duplicates (4)
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
require 'spec_helper'

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

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

  it 'returns the values in the hash in the order they appear in a hash iteration' do
    expect(compile_to_catalog(<<-'SRC'.unindent)).to have_resource('Notify[1 & 2]')
        $k = {'apples' => 1, 'oranges' => 2}.values
        notify { "${k[0]} & ${k[1]}": }
      SRC
  end

  it 'returns an empty array for an empty hash' do
    expect(compile_to_catalog(<<-'SRC'.unindent)).to have_resource('Notify[0]')
        $v = {}.values.reduce(0) |$m, $v| { $m+1 }
        notify { "${v}": }
      SRC
  end

  it 'includes an undef value if one is present in the hash' do
    expect(compile_to_catalog(<<-'SRC'.unindent)).to have_resource('Notify[Undef]')
        $types = {a => undef}.values.map |$v| { $v.type }
        notify { "${types[0]}": }
    SRC
  end
end