File: openstackconfig_spec.rb

package info (click to toggle)
puppet-module-openstacklib 25.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 968 kB
  • sloc: ruby: 4,500; python: 38; sh: 22; makefile: 10
file content (323 lines) | stat: -rw-r--r-- 8,621 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323

#
# Forked from https://github.com/puppetlabs/puppetlabs-inifile .
#

require 'spec_helper'
require 'puppet/util/openstackconfig'


describe Puppet::Util::OpenStackConfig do
  include PuppetlabsSpec::Files

  let(:subject) do
    Puppet::Util::OpenStackConfig.new("/my/config/path")
  end

  before :each do
    allow(Puppet::Util::OpenStackConfig).to receive(:readlines).and_return(sample_content)
  end

  context "when parsing a file" do
    let(:sample_content) {
      template = <<-EOS
# This is a comment
[section1]
; This is also a comment
foo=foovalue

bar = barvalue
baz =
[section2]

foo= foovalue2
baz=bazvalue
 ; commented = out setting
    #another comment
 ; yet another comment
 zot = multi word value
 xyzzy['thing1']['thing2']=xyzzyvalue
 l=git log

 [section3]
 multi_setting = value1
 multi_setting = value2
      EOS
      template.split("\n")
    }

    it "should parse the correct number of sections" do
      # there is always a "global" section, so our count should be 3.
      expect(subject.section_names.length).to eq(4)
    end

    it "should parse the correct section_names" do
      # there should always be a "global" section named "" at the beginning of the list
      expect(subject.section_names).to eq(["", "section1", "section2", "section3"])
    end

    it "should expose settings for sections" do
      expect(subject.get_settings("section1")).to eq({
        "bar" => "barvalue",
        "baz" => "",
        "foo" => "foovalue"
      })

      expect(subject.get_settings("section2")).to eq({
        "baz" => "bazvalue",
        "foo" => "foovalue2",
        "l" => "git log",
        "xyzzy['thing1']['thing2']" => "xyzzyvalue",
        "zot" => "multi word value"
      })

      expect(subject.get_settings("section3")).to eq({
        "multi_setting" => ["value1", "value2"]
      })
    end

  end

  context "when parsing a file whose first line is a section" do
    let(:sample_content) {
      template = <<-EOS
[section1]
; This is a comment
foo=foovalue
      EOS
      template.split("\n")
    }

    it "should parse the correct number of sections" do
      # there is always a "global" section, so our count should be 2.
      expect(subject.section_names.length).to eq(2)
    end

    it "should parse the correct section_names" do
      # there should always be a "global" section named "" at the beginning of the list
      expect(subject.section_names).to eq(["", "section1"])
    end

    it "should expose settings for sections" do
      expect(subject.get_value("section1", "foo")).to eq("foovalue")
    end

  end

  context "when parsing a file with a 'global' section" do
    let(:sample_content) {
      template = <<-EOS
foo = bar
[section1]
; This is a comment
foo=foovalue
      EOS
      template.split("\n")
    }

    it "should parse the correct number of sections" do
      # there is always a "global" section, so our count should be 2.
      expect(subject.section_names.length).to eq(2)
    end

    it "should parse the correct section_names" do
      # there should always be a "global" section named "" at the beginning of the list
      expect(subject.section_names).to eq(["", "section1"])
    end

    it "should expose settings for sections" do
      expect(subject.get_value("", "foo")).to eq("bar")
      expect(subject.get_value("section1", "foo")).to eq("foovalue")
    end
  end

  context "when updating a file with existing empty values" do
    let(:sample_content) {
      template = <<-EOS
[section1]
foo=
#bar=
#xyzzy['thing1']['thing2']='xyzzyvalue'
      EOS
      template.split("\n")
    }

    it "should properly update uncommented values" do
      expect(subject.get_value("section1", "far")).to eq(nil)
      subject.set_value("section1", "foo", "foovalue")
      expect(subject.get_value("section1", "foo")).to eq("foovalue")
    end

    it "should properly update commented values" do
      expect(subject.get_value("section1", "bar")).to eq(nil)
      subject.set_value("section1", "bar", "barvalue")
      expect(subject.get_value("section1", "bar")).to eq("barvalue")
      expect(subject.get_value("section1", "xyzzy['thing1']['thing2']")).to eq(nil)
      subject.set_value("section1", "xyzzy['thing1']['thing2']", "xyzzyvalue")
      expect(subject.get_value("section1", "xyzzy['thing1']['thing2']")).to eq("xyzzyvalue")
    end

    it "should properly add new empty values" do
      expect(subject.get_value("section1", "baz")).to eq(nil)
    end
  end

  context 'the file has quotation marks in its section names' do
    let(:sample_content) do
      template = <<-EOS
[branch "master"]
        remote = origin
        merge = refs/heads/master

[alias]
to-deploy = log --merges --grep='pull request' --format='%s (%cN)' origin/production..origin/master
[branch "production"]
        remote = origin
        merge = refs/heads/production
      EOS
      template.split("\n")
    end

    it 'should parse the sections' do
      expect(subject.section_names).to eq([
        '',
        'branch "master"',
        'alias',
        'branch "production"'
      ])
    end
  end

  context 'Samba INI file with dollars in section names' do
    let(:sample_content) do
      template = <<-EOS
      [global]
        workgroup = FELLOWSHIP
        ; ...
        idmap config * : backend = tdb

      [printers]
        comment = All Printers
        ; ...
        browseable = No

      [print$]
        comment = Printer Drivers
        path = /var/lib/samba/printers

      [Shares]
        path = /home/shares
        read only = No
        guest ok = Yes
      EOS
      template.split("\n")
    end

    it "should parse the correct section_names" do
      expect(subject.section_names).to eq([
        '',
        'global',
        'printers',
        'print$',
        'Shares'
      ])
    end
  end

  context 'section names with forward slashes in them' do
    let(:sample_content) do
      template = <<-EOS
[monitor:///var/log/*.log]
disabled = test_value
      EOS
      template.split("\n")
    end

    it "should parse the correct section_names" do
      expect(subject.section_names).to eq([
        '',
        'monitor:///var/log/*.log'
      ])
    end
  end

  context 'KDE Configuration with braces in setting names' do
    let(:sample_content) do
      template = <<-EOS
      [khotkeys]
_k_friendly_name=khotkeys
{5465e8c7-d608-4493-a48f-b99d99fdb508}=Print,none,PrintScreen
{d03619b6-9b3c-48cc-9d9c-a2aadb485550}=Search,none,Search
EOS
      template.split("\n")
    end

    it "should expose settings for sections" do
      expect(subject.get_value("khotkeys", "{5465e8c7-d608-4493-a48f-b99d99fdb508}")).to eq("Print,none,PrintScreen")
      expect(subject.get_value("khotkeys", "{d03619b6-9b3c-48cc-9d9c-a2aadb485550}")).to eq("Search,none,Search")
    end
  end

  context 'Configuration with colons in setting names' do
    let(:sample_content) do
      template = <<-EOS
      [Drive names]
A:=5.25" Floppy
B:=3.5" Floppy
C:=Winchester
EOS
      template.split("\n")
    end

    it "should expose settings for sections" do
      expect(subject.get_value("Drive names", "A:")).to eq('5.25" Floppy')
      expect(subject.get_value("Drive names", "B:")).to eq('3.5" Floppy')
      expect(subject.get_value("Drive names", "C:")).to eq('Winchester')
    end
  end

  context 'Configuration with spaces in setting names' do
    let(:sample_content) do
      template = <<-EOS
      [global]
        # log files split per-machine:
        log file = /var/log/samba/log.%m

        kerberos method = system keytab
        passdb backend = tdbsam
        security = ads
EOS
      template.split("\n")
    end

    it "should expose settings for sections" do
      expect(subject.get_value("global", "log file")).to eq('/var/log/samba/log.%m')
      expect(subject.get_value("global", "kerberos method")).to eq('system keytab')
      expect(subject.get_value("global", "passdb backend")).to eq('tdbsam')
      expect(subject.get_value("global", "security")).to eq('ads')
    end
  end


  context 'Multi settings' do
    let(:sample_content) do
      template = <<-EOS
      [test]
        # multi values
        test = value1
        test = value2
        test = value3
EOS
      template.split("\n")
    end

    it "should expose setting with array value" do
      expect(subject.get_value("test", "test")).to eq(['value1', 'value2', 'value3'])
    end

    it "should create setting with array value" do
      subject.set_value("test", "test2", ['valueA', 'valueB', 'valueC'])
      expect(subject.get_value("test", "test2")).to eq(['valueA', 'valueB', 'valueC'])
    end
  end
end