puppet-debugger 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.gitignore +54 -0
  4. data/.gitlab-ci.yml +129 -0
  5. data/.rspec +3 -0
  6. data/CHANGELOG.md +61 -0
  7. data/Gemfile +18 -0
  8. data/Gemfile.lock +67 -0
  9. data/LICENSE.txt +20 -0
  10. data/README.md +276 -0
  11. data/Rakefile +32 -0
  12. data/bin/pdb +4 -0
  13. data/lib/awesome_print/ext/awesome_puppet.rb +40 -0
  14. data/lib/puppet-debugger/cli.rb +247 -0
  15. data/lib/puppet-debugger/code/code_file.rb +98 -0
  16. data/lib/puppet-debugger/code/code_range.rb +69 -0
  17. data/lib/puppet-debugger/code/loc.rb +80 -0
  18. data/lib/puppet-debugger/debugger_code.rb +318 -0
  19. data/lib/puppet-debugger/support/compiler.rb +20 -0
  20. data/lib/puppet-debugger/support/environment.rb +38 -0
  21. data/lib/puppet-debugger/support/errors.rb +75 -0
  22. data/lib/puppet-debugger/support/facts.rb +78 -0
  23. data/lib/puppet-debugger/support/functions.rb +72 -0
  24. data/lib/puppet-debugger/support/input_responders.rb +136 -0
  25. data/lib/puppet-debugger/support/node.rb +90 -0
  26. data/lib/puppet-debugger/support/play.rb +91 -0
  27. data/lib/puppet-debugger/support/scope.rb +42 -0
  28. data/lib/puppet-debugger/support.rb +176 -0
  29. data/lib/puppet-debugger.rb +55 -0
  30. data/lib/trollop.rb +861 -0
  31. data/lib/version.rb +3 -0
  32. data/puppet-debugger.gemspec +36 -0
  33. data/run_container_test.sh +12 -0
  34. data/spec/facts_spec.rb +86 -0
  35. data/spec/fixtures/environments/production/manifests/site.pp +1 -0
  36. data/spec/fixtures/invalid_node_obj.yaml +8 -0
  37. data/spec/fixtures/node_obj.yaml +298 -0
  38. data/spec/fixtures/sample_manifest.pp +2 -0
  39. data/spec/fixtures/sample_start_debugger.pp +13 -0
  40. data/spec/pdb_spec.rb +50 -0
  41. data/spec/puppet-debugger_spec.rb +492 -0
  42. data/spec/remote_node_spec.rb +170 -0
  43. data/spec/spec_helper.rb +57 -0
  44. data/spec/support_spec.rb +190 -0
  45. data/test_matrix.rb +42 -0
  46. metadata +148 -0
@@ -0,0 +1,492 @@
1
+ require 'spec_helper'
2
+ require 'stringio'
3
+ describe "PuppetDebugger" do
4
+
5
+ let(:resource) do
6
+ "service{'httpd': ensure => running}"
7
+ end
8
+
9
+ before(:each) do
10
+ debugger.handle_input('reset')
11
+ end
12
+
13
+ let(:output) do
14
+ StringIO.new('', 'w')
15
+ end
16
+
17
+ let(:debugger) do
18
+ PuppetDebugger::Cli.new({:out_buffer => output}.merge(options))
19
+ end
20
+
21
+ let(:options) do
22
+ {}
23
+ end
24
+
25
+ let(:input) do
26
+ "file{'/tmp/test2.txt': ensure => present, mode => '0755'}"
27
+ end
28
+
29
+ let(:resource_types) do
30
+ debugger.parser.evaluate_string(debugger.scope, input)
31
+ end
32
+
33
+ describe 'native classes' do
34
+ describe 'create' do
35
+ let(:input) do
36
+ 'class testfoo {}'
37
+ end
38
+ let(:debugger_output) do
39
+ "\n => Puppet::Type::Component {\n loglevel\e[0;37m => \e[0m\e[0;36mnotice\e[0m,\n name\e[0;37m => \e[0m\e[0;33m\"Testfoo\"\e[0m,\n title\e[0;37m => \e[0m\e[0;33m\"Class[Testfoo]\"\e[0m\n}\n"
40
+ end
41
+ it do
42
+ debugger.handle_input(input)
43
+ expect(output.string).to eq("\n")
44
+ expect(debugger.known_resource_types[:hostclasses]).to include('testfoo')
45
+ end
46
+ it do
47
+ debugger.handle_input(input)
48
+ debugger.handle_input("include testfoo")
49
+ expect(debugger.scope.compiler.catalog.classes).to include('testfoo')
50
+ end
51
+ it do
52
+ debugger.handle_input(input)
53
+ debugger.handle_input('include testfoo')
54
+ expect(debugger.scope.compiler.catalog.resources.map(&:name)).to include('Testfoo')
55
+ end
56
+ end
57
+ end
58
+
59
+ describe 'native definitions' do
60
+ describe 'create' do
61
+ let(:input) do
62
+ 'define testfoo {}'
63
+ end
64
+ let(:debugger_output) do
65
+ "\n => Puppet::Type::Component {\n loglevel\e[0;37m => \e[0m\e[0;36mnotice\e[0m,\n name\e[0;37m => \e[0m\e[0;33m\"some_name\"\e[0m,\n title\e[0;37m => \e[0m\e[0;33m\"Testfoo[some_name]\"\e[0m\n}\n"
66
+ end
67
+ it do
68
+ debugger.handle_input(input)
69
+ expect(debugger.scope.environment.known_resource_types.definitions.keys).to include('testfoo')
70
+ expect(output.string).to eq("\n")
71
+ end
72
+ it do
73
+ debugger.handle_input(input)
74
+ debugger.handle_input("testfoo{'some_name':}")
75
+ expect(debugger.scope.compiler.resources.collect(&:name)).to include('some_name')
76
+ expect(debugger.scope.compiler.resources.collect(&:type)).to include('Testfoo')
77
+ expect(output.string).to include("\n => Puppet::Type::Component")
78
+ end
79
+ end
80
+ end
81
+
82
+ describe 'native functions', :native_functions => true do
83
+ let(:func) do
84
+ <<-EOF
85
+ function debugger::bool2http($arg) {
86
+ case $arg {
87
+ false, undef, /(?i:false)/ : { 'Off' }
88
+ true, /(?i:true)/ : { 'On' }
89
+ default : { "$arg" }
90
+ }
91
+ }
92
+ EOF
93
+ end
94
+ before(:each) do
95
+ debugger.handle_input(func)
96
+ end
97
+ describe 'create' do
98
+ it 'shows function' do
99
+ expect(output.string).to eq("\n")
100
+ end
101
+ end
102
+ describe 'run' do
103
+ let(:input) do
104
+ <<-EOF
105
+ debugger::bool2http(false)
106
+ EOF
107
+ end
108
+ it do
109
+ debugger.handle_input(input)
110
+ expect(output.string).to include('Off')
111
+ end
112
+ end
113
+ end
114
+
115
+ describe 'types' do
116
+
117
+ describe 'string' do
118
+ let(:input) do
119
+ "String"
120
+ end
121
+ it 'shows type' do
122
+ debugger.handle_input(input)
123
+ expect(output.string).to eq("\n => String\n")
124
+ end
125
+ end
126
+ describe 'Array' do
127
+ let(:input) do
128
+ "type_of([1,2,3,4])"
129
+ end
130
+ it 'shows type' do
131
+ debugger.handle_input(input)
132
+ expect(output.string).to eq("\n => Tuple[Integer[1, 1], Integer[2, 2], Integer[3, 3], Integer[4, 4]]\n")
133
+ end
134
+ end
135
+
136
+ end
137
+
138
+ describe 'multiple lines of input' do
139
+ describe '3 lines' do
140
+ let(:input) do
141
+ "$var1 = 'test'\nfile{\"/tmp/${var1}.txt\": ensure => present, mode => '0755'}\nvars"
142
+ end
143
+ it do
144
+ debugger.play_back_string(input)
145
+ expect(output.string).to match(/server_facts/) if Puppet.version.to_f >= 4.1
146
+ expect(output.string).to match(/test/)
147
+ expect(output.string).to match(/Puppet::Type::File/)
148
+ end
149
+ end
150
+ describe '2 lines' do
151
+ let(:input) do
152
+ "$var1 = 'test'\n $var2 = 'test2'"
153
+ end
154
+ it do
155
+ debugger.play_back_string(input)
156
+ expect(output.string).to include("$var1 = 'test'")
157
+ expect(output.string).to include("\"test\"")
158
+ expect(output.string).to include("$var2 = 'test2'")
159
+ expect(output.string).to include("\"test2\"")
160
+ end
161
+ end
162
+ describe '1 lines' do
163
+ let(:input) do
164
+ "$var1 = 'test'"
165
+ end
166
+ it do
167
+ debugger.play_back_string(input)
168
+ expect(output.string).to include("$var1 = 'test'")
169
+ expect(output.string).to include("\"test\"")
170
+ end
171
+ end
172
+ end
173
+
174
+ describe 'returns a array of resource_types' do
175
+ it 'returns resource type' do
176
+ expect(resource_types.first.class.to_s).to eq('Puppet::Pops::Types::PResourceType')
177
+ end
178
+ end
179
+
180
+ describe 'help' do
181
+ let(:input) do
182
+ 'help'
183
+ end
184
+ it 'can show the help screen' do
185
+ expected_debugger_output = /Type \"exit\", \"functions\", \"vars\", \"krt\", \"whereami\", \"facts\", \"resources\", \"classes\",\n \"play\", \"classification\", \"reset\", or \"help\" for more information.\n\n/
186
+ debugger.handle_input(input)
187
+ expect(output.string).to match(/Ruby Version: #{RUBY_VERSION}\n/)
188
+ expect(output.string).to match(/Puppet Version: \d.\d.\d\n/)
189
+ expect(output.string).to match(/Puppet Debugger Version: \d.\d.\d\n/)
190
+ expect(output.string).to match(/Created by: NWOps <corey@nwops.io>\n/)
191
+ expect(output.string).to match(expected_debugger_output)
192
+ end
193
+ end
194
+
195
+ describe 'empty' do
196
+ let(:input) do
197
+ ""
198
+ end
199
+ it 'can run' do
200
+ debugger_output = "\n"
201
+ debugger.handle_input(input)
202
+ expect(output.string).to eq(debugger_output)
203
+ end
204
+ describe 'space' do
205
+ let(:input) do
206
+ " "
207
+ end
208
+ it 'can run' do
209
+ debugger_output = "\n"
210
+ debugger.handle_input(input)
211
+ expect(output.string).to eq(debugger_output)
212
+ end
213
+ end
214
+ end
215
+
216
+ describe 'krt' do
217
+ let(:input) do
218
+ "krt"
219
+ end
220
+ it 'can run' do
221
+ debugger_output = /hostclasses/
222
+ debugger.handle_input(input)
223
+ expect(output.string).to match(debugger_output)
224
+ end
225
+ end
226
+
227
+ describe 'play' do
228
+ let(:fixtures_file) do
229
+ File.join(fixtures_dir, 'sample_manifest.pp')
230
+ end
231
+
232
+ before(:each) do
233
+ allow(debugger).to receive(:fetch_url_data).with(file_url + '.txt').and_return(File.read(fixtures_file))
234
+ end
235
+
236
+ let(:file_url) do
237
+ 'https://gist.githubusercontent.com/logicminds/f9b1ac65a3a440d562b0'
238
+ end
239
+ it 'file' do
240
+ debugger.handle_input("play #{fixtures_file}")
241
+ expect(output.string).to match(/Puppet::Type::File/)
242
+ end
243
+ it 'url' do
244
+ debugger.handle_input("play #{file_url}")
245
+ expect(output.string).to match(/Puppet::Type::File/)
246
+ end
247
+ end
248
+
249
+ describe 'variables' do
250
+ let(:input) do
251
+ "$file_path = '/tmp/test2.txt'"
252
+ end
253
+ it 'can process a variable' do
254
+ debugger.handle_input(input)
255
+ expect(output.string).to match(/\/tmp\/test2.txt/)
256
+ end
257
+ end
258
+
259
+ describe 'resource' do
260
+ let(:input) do
261
+ "file{'/tmp/test2.txt': ensure => present, mode => '0755'}"
262
+ end
263
+ it 'can process a resource' do
264
+ debugger_output = /Puppet::Type::File/
265
+ debugger.handle_input(input)
266
+ expect(output.string).to match(debugger_output)
267
+ end
268
+ end
269
+
270
+ describe 'bad input' do
271
+ let(:input) do
272
+ "Service{"
273
+ end
274
+ it 'can process' do
275
+ debugger_output = "\n => \e[31mSyntax error at end of file\e[0m\n"
276
+ debugger.handle_input(input)
277
+ expect(output.string).to eq(debugger_output)
278
+ end
279
+ end
280
+
281
+ describe 'classification' do
282
+ let(:input) do
283
+ "classification"
284
+ end
285
+
286
+ it 'can process a file' do
287
+ debugger.handle_input(input)
288
+ expect(output.string).to eq("\n[]\n")
289
+ end
290
+ end
291
+
292
+ describe 'reset' do
293
+ let(:input) do
294
+ "file{'/tmp/reset': ensure => present}"
295
+ end
296
+
297
+ it 'can process a file' do
298
+ debugger_output = /Puppet::Type::File/
299
+ debugger.handle_input(input)
300
+ expect(output.string).to match(debugger_output)
301
+ debugger.handle_input('reset')
302
+ debugger.handle_input(input)
303
+ expect(output.string).to match(debugger_output)
304
+ end
305
+
306
+ describe 'loglevel' do
307
+ it 'has not changed' do
308
+ debugger.handle_input(":set loglevel debug")
309
+ expect(Puppet::Util::Log.level).to eq(:debug)
310
+ expect(Puppet::Util::Log.destinations[:buffer].name).to eq(:buffer)
311
+ debugger.handle_input('reset')
312
+ expect(Puppet::Util::Log.level).to eq(:debug)
313
+ expect(Puppet::Util::Log.destinations[:buffer].name).to eq(:buffer)
314
+ end
315
+ end
316
+ end
317
+
318
+ describe 'map block' do
319
+ let(:input) do
320
+ "['/tmp/test3', '/tmp/test4'].map |String $path| { file{$path: ensure => present} }"
321
+ end
322
+ it 'can process a each block' do
323
+ debugger_output = /Puppet::Type::File/
324
+ debugger.handle_input(input)
325
+ expect(output.string).to match(debugger_output)
326
+ end
327
+ end
328
+
329
+ describe 'each block' do
330
+ let(:input) do
331
+ "['/tmp/test3', '/tmp/test4'].each |String $path| { file{$path: ensure => present} }"
332
+ end
333
+ it 'can process a each block' do
334
+ debugger.handle_input(input)
335
+ expect(output.string).to match(/\/tmp\/test3/)
336
+ expect(output.string).to match(/\/tmp\/test4/)
337
+ end
338
+ end
339
+
340
+ describe 'facts' do
341
+ let(:input) do
342
+ "$::fqdn"
343
+ end
344
+ it 'should be able to resolve fqdn' do
345
+ debugger_output = /foo\.example\.com/
346
+ debugger.handle_input(input)
347
+ expect(output.string).to match(debugger_output)
348
+ end
349
+ end
350
+
351
+ describe 'print facts' do
352
+ let(:input) do
353
+ "facts"
354
+ end
355
+ it 'should be able to print facts' do
356
+ debugger_output = /kernel/
357
+ debugger.handle_input(input)
358
+ expect(output.string).to match(debugger_output)
359
+ end
360
+ end
361
+
362
+ describe 'print resources' do
363
+ let(:input) do
364
+ 'resources'
365
+ end
366
+ it 'should be able to print resources' do
367
+ debugger_output = /main/
368
+ debugger.handle_input(input)
369
+ expect(output.string).to match(debugger_output)
370
+ end
371
+ end
372
+
373
+ describe 'print class' do
374
+ let(:input) do
375
+ "Class['settings']"
376
+ end
377
+ it 'should be able to print classes' do
378
+ debugger_output = /Settings/
379
+ debugger.handle_input(input)
380
+ expect(output.string).to match(debugger_output)
381
+ end
382
+ end
383
+
384
+ describe 'print classes' do
385
+ let(:input) do
386
+ 'resources'
387
+ end
388
+ it 'should be able to print classes' do
389
+ debugger_output = /Settings/
390
+ debugger.handle_input(input)
391
+ expect(output.string).to match(debugger_output)
392
+ end
393
+ end
394
+
395
+ describe 'set' do
396
+ let(:input) do
397
+ ":set loglevel debug"
398
+ end
399
+ it 'should set the loglevel' do
400
+ debugger_output = /loglevel debug is set/
401
+ debugger.handle_input(input)
402
+ expect(output.string).to match(debugger_output)
403
+ expect(Puppet::Util::Log.level).to eq(:debug)
404
+ expect(Puppet::Util::Log.destinations[:buffer].name).to eq(:buffer)
405
+ end
406
+ end
407
+
408
+ describe 'vars' do
409
+ let(:input) do
410
+ "vars"
411
+ end
412
+ it 'display facts variable' do
413
+ debugger_output = /facts/
414
+ debugger.handle_input(input)
415
+ expect(output.string).to match(debugger_output)
416
+ end
417
+ it 'display server facts variable' do
418
+ debugger_output = /server_facts/
419
+ debugger.handle_input(input)
420
+ expect(output.string).to match(debugger_output) if Puppet.version.to_f >= 4.1
421
+ end
422
+ it 'display serverversion variable' do
423
+ debugger_output = /serverversion/
424
+ debugger.handle_input(input)
425
+ expect(output.string).to match(debugger_output) if Puppet.version.to_f >= 4.1
426
+ end
427
+ it 'display local variable' do
428
+ debugger.handle_input("$var1 = 'value1'")
429
+ expect(output.string).to match(/value1/)
430
+ debugger.handle_input("$var1")
431
+ expect(output.string).to match(/value1/)
432
+ end
433
+
434
+ end
435
+
436
+ describe 'execute functions' do
437
+ let(:input) do
438
+ "md5('hello')"
439
+ end
440
+ it 'execute md5' do
441
+ debugger_output = /5d41402abc4b2a76b9719d911017c592/
442
+ debugger.handle_input(input)
443
+ expect(output.string).to match(debugger_output)
444
+ end
445
+ it 'execute swapcase' do
446
+ debugger_output = /HELLO/
447
+ debugger.handle_input("swapcase('hello')")
448
+ expect(output.string).to match(debugger_output)
449
+ end
450
+ end
451
+
452
+ describe 'whereami' do
453
+ let(:input) do
454
+ File.expand_path File.join(fixtures_dir, 'sample_start_debugger.pp')
455
+ end
456
+ let(:options) do
457
+ {
458
+ source_file: input,
459
+ source_line: 10,
460
+ }
461
+ end
462
+
463
+ it 'runs' do
464
+ expect(debugger.whereami).to match(/\s+5/)
465
+ end
466
+ it 'contains marker' do
467
+ expect(debugger.whereami).to match(/\s+=>\s10/)
468
+ end
469
+
470
+ end
471
+
472
+ describe 'error message' do
473
+ let(:input) do
474
+ "file{'/tmp/test': ensure => present, contact => 'blah'}"
475
+ end
476
+ if Gem::Version.new(Puppet.version) >= Gem::Version.new('4.0')
477
+ it 'show error message' do
478
+ debugger_output = /no\ parameter\ named\ 'contact'/
479
+ debugger.handle_input(input)
480
+ expect(output.string).to match(debugger_output)
481
+ end
482
+ else
483
+ it 'show error message' do
484
+ debugger_output = /Invalid\ parameter\ contact/
485
+ debugger.handle_input(input)
486
+ expect(output.string).to match(debugger_output)
487
+ end
488
+ end
489
+
490
+ end
491
+
492
+ end
@@ -0,0 +1,170 @@
1
+ require 'spec_helper'
2
+ require 'stringio'
3
+ describe "PuppetDebugger" do
4
+
5
+ let(:resource) do
6
+ "service{'httpd': ensure => running}"
7
+ end
8
+
9
+ before(:each) do
10
+ debugger.handle_input('reset')
11
+ end
12
+
13
+ let(:output) do
14
+ StringIO.new('', 'w')
15
+ end
16
+
17
+ let(:debugger) do
18
+ PuppetDebugger::Cli.new(:out_buffer => output)
19
+ end
20
+
21
+ let(:input) do
22
+ "file{'/tmp/test2.txt': ensure => present, mode => '0755'}"
23
+ end
24
+
25
+ let(:resource_types) do
26
+ debugger.parser.evaluate_string(debugger.scope, input)
27
+ end
28
+
29
+ describe 'remote node' do
30
+ let(:node_obj) do
31
+ YAML.load_file(File.join(fixtures_dir, 'node_obj.yaml'))
32
+ end
33
+ let(:node_name) do
34
+ 'puppetdev.localdomain'
35
+ end
36
+ before :each do
37
+ allow(debugger).to receive(:get_remote_node).with(node_name).and_return(node_obj)
38
+ debugger.handle_input(":set node #{node_name}")
39
+ end
40
+
41
+ describe 'set' do
42
+ it 'sends message about resetting' do
43
+ expect(output.string).to eq("\n => Resetting to use node puppetdev.localdomain\n")
44
+ end
45
+
46
+ it "return node name" do
47
+ output.reopen # removes previous message
48
+ debugger.handle_input('$::hostname')
49
+ expect(output.string).to match(/puppetdev.localdomain/)
50
+ end
51
+
52
+ it "return classification" do
53
+ output.reopen # removes previous message
54
+ debugger.handle_input('classification')
55
+ expect(output.string).to match(/stdlib/)
56
+ end
57
+ end
58
+
59
+ describe 'facts' do
60
+ let(:input) do
61
+ "$::facts['os']['family'].downcase == 'debian'"
62
+ end
63
+ it 'fact evaulation should return false' do
64
+ debugger_output = /false/
65
+ debugger.handle_input(input)
66
+ expect(output.string).to match(debugger_output)
67
+ end
68
+
69
+ end
70
+ describe 'use defaults when invalid' do
71
+ let(:node_obj) do
72
+ YAML.load_file(File.join(fixtures_dir, 'invalid_node_obj.yaml'))
73
+ end
74
+ let(:node_name) do
75
+ 'invalid.localdomain'
76
+ end
77
+ it 'name' do
78
+ expect{debugger.node.name}.to raise_error(PuppetDebugger::Exception::UndefinedNode)
79
+ end
80
+ end
81
+
82
+ it 'set node name' do
83
+ expect(debugger.remote_node_name = 'puppetdev.localdomain').to eq("puppetdev.localdomain")
84
+ end
85
+
86
+ describe 'print classes' do
87
+ let(:input) do
88
+ 'resources'
89
+ end
90
+ it 'should be able to print classes' do
91
+ debugger_output = /Settings/
92
+ debugger.handle_input(input)
93
+ expect(output.string).to match(debugger_output)
94
+ end
95
+ end
96
+
97
+ describe 'vars' do
98
+ let(:input) do
99
+ "vars"
100
+ end
101
+ it 'display facts variable' do
102
+ debugger_output = /facts/
103
+ debugger.handle_input(input)
104
+ expect(output.string).to match(debugger_output)
105
+ end
106
+ it 'display server facts variable' do
107
+ debugger_output = /server_facts/
108
+ debugger.handle_input(input)
109
+ expect(output.string).to match(debugger_output) if Puppet.version.to_f >= 4.1
110
+ end
111
+ it 'display server facts variable' do
112
+ debugger_output = /server_facts/
113
+ debugger.handle_input(input)
114
+ expect(output.string).to match(debugger_output) if Puppet.version.to_f >= 4.1
115
+ end
116
+ it 'display local variable' do
117
+ debugger.handle_input("$var1 = 'value1'")
118
+ expect(output.string).to match(/value1/)
119
+ debugger.handle_input("$var1")
120
+ expect(output.string).to match(/value1/)
121
+ end
122
+ it 'display productname variable' do
123
+ debugger.handle_input("$productname")
124
+ expect(output.string).to match(/VMware Virtual Platform/)
125
+ end
126
+ end
127
+
128
+ describe 'execute functions' do
129
+ let(:input) do
130
+ "md5('hello')"
131
+ end
132
+ it 'execute md5' do
133
+ debugger_output = /5d41402abc4b2a76b9719d911017c592/
134
+ debugger.handle_input(input)
135
+ expect(output.string).to match(debugger_output)
136
+ end
137
+ it 'execute swapcase' do
138
+ debugger_output = /HELLO/
139
+ debugger.handle_input("swapcase('hello')")
140
+ expect(output.string).to match(debugger_output)
141
+ end
142
+ end
143
+
144
+ describe 'reset' do
145
+ let(:input) do
146
+ "file{'/tmp/reset': ensure => present}"
147
+ end
148
+
149
+ it 'can process a file' do
150
+ debugger_output = /Puppet::Type::File/
151
+ debugger.handle_input(input)
152
+ expect(output.string).to match(debugger_output)
153
+ debugger.handle_input('reset')
154
+ debugger.handle_input(input)
155
+ expect(output.string).to match(debugger_output)
156
+ end
157
+ end
158
+
159
+ describe 'classification' do
160
+ let(:input) do
161
+ "classification"
162
+ end
163
+
164
+ it 'shows certificate_authority_host' do
165
+ debugger.handle_input(input)
166
+ expect(output.string).to match(/stdlib/)
167
+ end
168
+ end
169
+ end
170
+ end
@@ -0,0 +1,57 @@
1
+ require 'simplecov'
2
+ require_relative '../lib/puppet-debugger'
3
+ require 'yaml'
4
+ ENV['COVERAGE'] = "true"
5
+
6
+ module SimpleCov::Configuration
7
+ def clean_filters
8
+ @filters = []
9
+ end
10
+ end
11
+
12
+ SimpleCov.configure do
13
+ clean_filters
14
+ load_profile 'test_frameworks'
15
+ end
16
+
17
+ SimpleCov.start do
18
+ add_filter "/.rvm/"
19
+ add_filter "vendor"
20
+ add_filter "bundler"
21
+ end
22
+
23
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
24
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
25
+
26
+ require 'rspec'
27
+ require 'puppet-debugger'
28
+ ENV['REPL_FACTERDB_FILTER'] = "operatingsystem=Fedora and operatingsystemrelease=23 and architecture=x86_64 and facterversion=/^2\\.4/"
29
+ # Requires supporting files with custom matchers and macros, etc,
30
+ # in ./support/ and its subdirectories.
31
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
32
+
33
+ def stdlib_path
34
+ File.join(Puppet[:basemodulepath].split(':').first, 'stdlib')
35
+ end
36
+
37
+ # def install_stdlib
38
+ # `bundle exec puppet module install puppetlabs/stdlib` unless File.exists?(stdlib_path)
39
+ # end
40
+ #
41
+ # install_stdlib
42
+
43
+ def fixtures_dir
44
+ File.join(File.dirname(__FILE__), 'fixtures')
45
+ end
46
+
47
+ def environments_dir
48
+ File.join(fixtures_dir, 'environments')
49
+ end
50
+
51
+ def supports_native_functions?
52
+ Gem::Version.new(Puppet.version) >= Gem::Version.new('4.3')
53
+ end
54
+
55
+ RSpec.configure do |config|
56
+ config.filter_run_excluding :native_functions => ! supports_native_functions?
57
+ end