File: concat_merge_spec.rb

package info (click to toggle)
puppet-module-voxpupuli-elasticsearch 9.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,496 kB
  • sloc: ruby: 9,906; sh: 392; makefile: 4
file content (199 lines) | stat: -rw-r--r-- 8,293 bytes parent folder | download
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# frozen_string_literal: true

require 'spec_helper'
describe 'concat_merge' do
  describe 'exception handling' do
    it {
      expect(subject).to run.with_params.and_raise_error(
        Puppet::ParseError, %r{wrong number of arguments}i
      )
    }

    it {
      expect(subject).to run.with_params({}).and_raise_error(
        Puppet::ParseError, %r{wrong number of arguments}i
      )
    }

    it {
      expect(subject).to run.with_params('2', 2).and_raise_error(
        Puppet::ParseError, %r{unexpected argument type}
      )
    }

    it {
      expect(subject).to run.with_params(2, '2').and_raise_error(
        Puppet::ParseError, %r{unexpected argument type}
      )
    }
  end

  describe 'collisions' do
    context 'single keys' do
      it {
        expect(subject).to run.with_params({
                                             'key1' => 'value1'
                                           }, {
                                             'key1' => 'value2'
                                           }).and_return({
                                                           'key1' => 'value2'
                                                         })
      }

      it {
        expect(subject).to run.with_params({
                                             'key1' => 'value1'
                                           }, {
                                             'key1' => 'value2'
                                           }, {
                                             'key1' => 'value3'
                                           }).and_return({
                                                           'key1' => 'value3'
                                                         })
      }
    end

    context 'multiple keys' do
      it {
        expect(subject).to run.with_params({
                                             'key1' => 'value1',
                                             'key2' => 'value2'
                                           }, {
                                             'key1' => 'value2'
                                           }).and_return({
                                                           'key1' => 'value2',
                                                           'key2' => 'value2'
                                                         })
      }

      it {
        expect(subject).to run.with_params({
                                             'key1' => 'value1',
                                             'key2' => 'value1'
                                           }, {
                                             'key1' => 'value2'
                                           }, {
                                             'key1' => 'value3',
                                             'key2' => 'value2'
                                           }).and_return({
                                                           'key1' => 'value3',
                                                           'key2' => 'value2'
                                                         })
      }
    end
  end

  describe 'concat merging' do
    context 'single keys' do
      it {
        expect(subject).to run.with_params({
                                             'key1' => ['value1']
                                           }, {
                                             'key1' => ['value2']
                                           }).and_return({
                                                           'key1' => %w[value1 value2]
                                                         })
      }

      it {
        expect(subject).to run.with_params({
                                             'key1' => ['value1']
                                           }, {
                                             'key1' => ['value2']
                                           }, {
                                             'key1' => ['value3']
                                           }).and_return({
                                                           'key1' => %w[value1 value2 value3]
                                                         })
      }

      it {
        expect(subject).to run.with_params({
                                             'key1' => ['value1']
                                           }, {
                                             'key1' => 'value2'
                                           }).and_return({
                                                           'key1' => 'value2'
                                                         })
      }

      it {
        expect(subject).to run.with_params({
                                             'key1' => 'value1'
                                           }, {
                                             'key1' => ['value2']
                                           }).and_return({
                                                           'key1' => ['value2']
                                                         })
      }
    end

    context 'multiple keys' do
      it {
        expect(subject).to run.with_params({
                                             'key1' => ['value1'],
                                             'key2' => ['value3']
                                           }, {
                                             'key1' => ['value2'],
                                             'key2' => ['value4']
                                           }).and_return({
                                                           'key1' => %w[value1 value2],
                                                           'key2' => %w[value3 value4]
                                                         })
      }

      it {
        expect(subject).to run.with_params({
                                             'key1' => ['value1'],
                                             'key2' => ['value1.1']
                                           }, {
                                             'key1' => ['value2'],
                                             'key2' => ['value2.1']
                                           }, {
                                             'key1' => ['value3'],
                                             'key2' => ['value3.1']
                                           }).and_return({
                                                           'key1' => %w[value1 value2 value3],
                                                           'key2' => ['value1.1', 'value2.1', 'value3.1']
                                                         })
      }

      it {
        expect(subject).to run.with_params({
                                             'key1' => ['value1'],
                                             'key2' => 'value1'
                                           }, {
                                             'key1' => 'value2',
                                             'key2' => ['value2']
                                           }).and_return({
                                                           'key1' => 'value2',
                                                           'key2' => ['value2']
                                                         })
      }

      it {
        expect(subject).to run.with_params({
                                             'key1' => 'value1',
                                             'key2' => ['value1']
                                           }, {
                                             'key1' => ['value2'],
                                             'key2' => 'value2'
                                           }).and_return(
                                             'key1' => ['value2'],
                                             'key2' => 'value2'
                                           )
      }
    end
  end

  it 'does not change the original hashes' do
    argument1 = { 'key1' => 'value1' }
    original1 = argument1.dup
    argument2 = { 'key2' => 'value2' }
    original2 = argument2.dup

    subject.execute(argument1, argument2)
    expect(argument1).to eq(original1)
    expect(argument2).to eq(original2)
  end
end