File: all_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 (97 lines) | stat: -rw-r--r-- 2,757 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
require 'puppet'
require 'spec_helper'
require 'puppet_spec/compiler'

require 'shared_behaviours/iterative_functions'

describe 'the all method' do
  include PuppetSpec::Compiler

  context "should be callable as" do
    it 'all on an array' do
      catalog = compile_to_catalog(<<-MANIFEST)
        $a = [1,2,3]
        $n = $a.all |$v| { $v > 0 }
        file { "$n": ensure => present }
      MANIFEST

      expect(catalog.resource(:file, "true")['ensure']).to eq('present')
    end

    it 'all on an array with index' do
      catalog = compile_to_catalog(<<-MANIFEST)
        $a = [0,2,4]
        $n = $a.all |$i, $v| { $v == $i * 2 }
        file { "$n": ensure => present }
      MANIFEST

      expect(catalog.resource(:file, "true")['ensure']).to eq('present')
    end

    it 'all on a hash selecting entries' do
      catalog = compile_to_catalog(<<-MANIFEST)
        $a = {0=>0,1=>2,2=>4}
        $n = $a.all |$e| { $e[1] == $e[0]*2 }
        file { "$n": ensure => present }
      MANIFEST

      expect(catalog.resource(:file, "true")['ensure']).to eq('present')
    end

    it 'all on a hash selecting key and value' do
      catalog = compile_to_catalog(<<-MANIFEST)
        $a = {0=>0,1=>2,2=>4}
        $n = $a.all |$k,$v| { $v == $k*2 }
        file { "$n": ensure => present }
      MANIFEST

      expect(catalog.resource(:file, "true")['ensure']).to eq('present')
    end
  end

  context "produces a boolean" do
    it 'true when boolean true is found' do
      catalog = compile_to_catalog(<<-MANIFEST)
        $a = [6,6,6]
        $n = $a.all |$v| { true }
        file { "$n": ensure => present }
      MANIFEST

      expect(catalog.resource(:file, "true")['ensure']).to eq('present')
    end

    it 'true when truthy is found' do
      catalog = compile_to_catalog(<<-MANIFEST)
        $a = [6,6,6]
        $n = $a.all |$v| { 42 }
        file { "$n": ensure => present }
      MANIFEST

      expect(catalog.resource(:file, "true")['ensure']).to eq('present')
    end

    it 'false when truthy is not found (all undef)' do
      catalog = compile_to_catalog(<<-MANIFEST)
        $a = [6,6,6]
        $n = $a.all |$v| { undef }
        file { "$n": ensure => present }
      MANIFEST

      expect(catalog.resource(:file, "false")['ensure']).to eq('present')
    end

    it 'false when truthy is not found (all false)' do
      catalog = compile_to_catalog(<<-MANIFEST)
        $a = [6,6,6]
        $n = $a.all |$v| { false }
        file { "$n": ensure => present }
      MANIFEST

      expect(catalog.resource(:file, "false")['ensure']).to eq('present')
    end

  end
  it_should_behave_like 'all iterative functions argument checks', 'any'
  it_should_behave_like 'all iterative functions hash handling', 'any'

end