puppet-debugger 0.4.1 → 0.4.2

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.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'puppet-debugger/cli'
2
3
  require_relative 'version'
3
4
  require 'awesome_print'
@@ -9,13 +10,33 @@ require_relative 'puppet-debugger/debugger_code'
9
10
  require_relative 'puppet-debugger/support/errors'
10
11
  # monkey patch in some color effects string methods
11
12
  class String
12
- def red; "\033[31m#{self}\033[0m" end
13
- def green; "\033[32m#{self}\033[0m" end
14
- def cyan; "\033[36m#{self}\033[0m" end
15
- def yellow; "\033[33m#{self}\033[0m" end
16
- def warning; yellow end
17
- def fatal; red end
18
- def info; green end
13
+ def red
14
+ "\033[31m#{self}\033[0m"
15
+ end
16
+
17
+ def green
18
+ "\033[32m#{self}\033[0m"
19
+ end
20
+
21
+ def cyan
22
+ "\033[36m#{self}\033[0m"
23
+ end
24
+
25
+ def yellow
26
+ "\033[33m#{self}\033[0m"
27
+ end
28
+
29
+ def warning
30
+ yellow
31
+ end
32
+
33
+ def fatal
34
+ red
35
+ end
36
+
37
+ def info
38
+ green
39
+ end
19
40
 
20
41
  def camel_case
21
42
  return self if self !~ /_/ && self =~ /[A-Z]+.*/
@@ -29,25 +50,25 @@ Puppet::Util::Log.newdesttype :buffer do
29
50
 
30
51
  attr_accessor :err_buffer, :out_buffer
31
52
 
32
- def initialize(err=$stderr, out=$stdout)
53
+ def initialize(err = $stderr, out = $stdout)
33
54
  @err_buffer = err
34
55
  @out_buffer = out
35
56
  end
36
57
 
37
58
  def handle(msg)
38
59
  levels = {
39
- :emerg => { :name => 'Emergency', :color => :hred, :stream => err_buffer },
40
- :alert => { :name => 'Alert', :color => :hred, :stream => err_buffer },
41
- :crit => { :name => 'Critical', :color => :hred, :stream => err_buffer },
42
- :err => { :name => 'Error', :color => :hred, :stream => err_buffer },
43
- :warning => { :name => 'Warning', :color => :hred, :stream => err_buffer },
44
- :notice => { :name => 'Notice', :color => :reset, :stream => out_buffer },
45
- :info => { :name => 'Info', :color => :green, :stream => out_buffer },
46
- :debug => { :name => 'Debug', :color => :cyan, :stream => out_buffer },
60
+ emerg: { name: 'Emergency', color: :hred, stream: err_buffer },
61
+ alert: { name: 'Alert', color: :hred, stream: err_buffer },
62
+ crit: { name: 'Critical', color: :hred, stream: err_buffer },
63
+ err: { name: 'Error', color: :hred, stream: err_buffer },
64
+ warning: { name: 'Warning', color: :hred, stream: err_buffer },
65
+ notice: { name: 'Notice', color: :reset, stream: out_buffer },
66
+ info: { name: 'Info', color: :green, stream: out_buffer },
67
+ debug: { name: 'Debug', color: :cyan, stream: out_buffer }
47
68
  }
48
69
 
49
70
  str = msg.respond_to?(:multiline) ? msg.multiline : msg.to_s
50
- str = msg.source == "Puppet" ? str : "#{msg.source}: #{str}"
71
+ str = msg.source == 'Puppet' ? str : "#{msg.source}: #{str}"
51
72
 
52
73
  level = levels[msg.level]
53
74
  level[:stream].puts colorize(level[:color], "#{level[:name]}: #{str}")
data/lib/version.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module PuppetDebugger
2
- VERSION = '0.4.1'
3
+ VERSION = '0.4.2'
3
4
  end
data/spec/facts_spec.rb CHANGED
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
4
  describe 'facts' do
4
5
  let(:debugger) do
5
- PuppetDebugger::Cli.new(:out_buffer => output)
6
+ PuppetDebugger::Cli.new(out_buffer: output)
6
7
  end
7
8
 
8
9
  let(:puppet_version) do
@@ -28,7 +29,7 @@ describe 'facts' do
28
29
  expect(facter_version).to eq('/^2\.4/')
29
30
  end
30
31
  it 'return default filter' do
31
- expect(debugger.dynamic_facterdb_filter).to eq("operatingsystem=Fedora and operatingsystemrelease=23 and architecture=x86_64 and facterversion=/^2\\.4/")
32
+ expect(debugger.dynamic_facterdb_filter).to eq('operatingsystem=Fedora and operatingsystemrelease=23 and architecture=x86_64 and facterversion=/^2\\.4/')
32
33
  end
33
34
  it 'get node_facts' do
34
35
  expect(debugger.node_facts).to be_instance_of(Hash)
@@ -58,7 +59,7 @@ describe 'facts' do
58
59
  expect(facter_version).to eq('/^3\.1/')
59
60
  end
60
61
  it 'return default filter' do
61
- expect(debugger.dynamic_facterdb_filter).to eq("operatingsystem=Fedora and operatingsystemrelease=23 and architecture=x86_64 and facterversion=/^3\\.1/")
62
+ expect(debugger.dynamic_facterdb_filter).to eq('operatingsystem=Fedora and operatingsystemrelease=23 and architecture=x86_64 and facterversion=/^3\\.1/')
62
63
  end
63
64
  end
64
65
 
@@ -68,10 +69,10 @@ describe 'facts' do
68
69
  ENV['DEBUGGER_FACTERDB_FILTER'] = 'facterversion=/^6\.5/'
69
70
  end
70
71
  it 'return filter' do
71
- expect(debugger.dynamic_facterdb_filter).to eq("facterversion=/^6\\.5/")
72
+ expect(debugger.dynamic_facterdb_filter).to eq('facterversion=/^6\\.5/')
72
73
  end
73
74
  it 'throws error' do
74
- expect{debugger.default_facts}.to raise_error(PuppetDebugger::Exception::BadFilter)
75
+ expect { debugger.default_facts }.to raise_error(PuppetDebugger::Exception::BadFilter)
75
76
  end
76
77
  end
77
78
  describe 'good filter' do
@@ -79,7 +80,7 @@ describe 'facts' do
79
80
  ENV['DEBUGGER_FACTERDB_FILTER'] = 'facterversion=/^3\.1/'
80
81
  end
81
82
  it 'return filter' do
82
- expect(debugger.dynamic_facterdb_filter).to eq("facterversion=/^3\\.1/")
83
+ expect(debugger.dynamic_facterdb_filter).to eq('facterversion=/^3\\.1/')
83
84
  end
84
85
  end
85
86
  end
data/spec/pdb_spec.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
4
  describe 'pdb' do
@@ -1,4 +1,5 @@
1
1
  #! /usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
  require 'spec_helper'
3
4
 
4
5
  require 'puppet/application/debugger'
@@ -24,7 +25,7 @@ describe Puppet::Application::Debugger do
24
25
  debugger.initialize_app_defaults
25
26
  end
26
27
 
27
- it "declare a main command" do
28
+ it 'declare a main command' do
28
29
  expect(debugger).to respond_to(:main)
29
30
  end
30
31
 
@@ -54,7 +55,6 @@ describe Puppet::Application::Debugger do
54
55
  # runonce
55
56
  # test
56
57
 
57
-
58
58
  # it 'create a node' do
59
59
  # require 'pry'; binding.pry
60
60
  # expect(node).to be_a(Puppet::Node::Environment)
@@ -63,5 +63,4 @@ describe Puppet::Application::Debugger do
63
63
  # it 'create a scope' do
64
64
  # expect(scope).to be_a(Puppet::Node::Environment)
65
65
  # end
66
-
67
66
  end
@@ -1,7 +1,7 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
  require 'stringio'
3
- describe "PuppetDebugger" do
4
-
4
+ describe 'PuppetDebugger' do
5
5
  let(:resource) do
6
6
  "service{'httpd': ensure => running}"
7
7
  end
@@ -15,7 +15,7 @@ describe "PuppetDebugger" do
15
15
  end
16
16
 
17
17
  let(:debugger) do
18
- PuppetDebugger::Cli.new({:out_buffer => output}.merge(options))
18
+ PuppetDebugger::Cli.new({ out_buffer: output }.merge(options))
19
19
  end
20
20
 
21
21
  let(:options) do
@@ -45,7 +45,7 @@ describe "PuppetDebugger" do
45
45
  end
46
46
  it do
47
47
  debugger.handle_input(input)
48
- debugger.handle_input("include testfoo")
48
+ debugger.handle_input('include testfoo')
49
49
  expect(debugger.scope.compiler.catalog.classes).to include('testfoo')
50
50
  end
51
51
  it do
@@ -79,7 +79,7 @@ describe "PuppetDebugger" do
79
79
  end
80
80
  end
81
81
 
82
- describe 'native functions', :native_functions => true do
82
+ describe 'native functions', native_functions: true do
83
83
  let(:func) do
84
84
  <<-EOF
85
85
  function debugger::bool2http($arg) {
@@ -113,10 +113,9 @@ describe "PuppetDebugger" do
113
113
  end
114
114
 
115
115
  describe 'types' do
116
-
117
116
  describe 'string' do
118
117
  let(:input) do
119
- "String"
118
+ 'String'
120
119
  end
121
120
  it 'shows type' do
122
121
  debugger.handle_input(input)
@@ -125,14 +124,13 @@ describe "PuppetDebugger" do
125
124
  end
126
125
  describe 'Array' do
127
126
  let(:input) do
128
- "type_of([1,2,3,4])"
127
+ 'type_of([1,2,3,4])'
129
128
  end
130
129
  it 'shows type' do
131
130
  debugger.handle_input(input)
132
131
  expect(output.string).to eq("\n => Tuple[Integer[1, 1], Integer[2, 2], Integer[3, 3], Integer[4, 4]]\n")
133
132
  end
134
133
  end
135
-
136
134
  end
137
135
 
138
136
  describe 'multiple lines of input' do
@@ -154,9 +152,9 @@ describe "PuppetDebugger" do
154
152
  it do
155
153
  debugger.play_back_string(input)
156
154
  expect(output.string).to include("$var1 = 'test'")
157
- expect(output.string).to include("\"test\"")
155
+ expect(output.string).to include('"test"')
158
156
  expect(output.string).to include("$var2 = 'test2'")
159
- expect(output.string).to include("\"test2\"")
157
+ expect(output.string).to include('"test2"')
160
158
  end
161
159
  end
162
160
  describe '1 lines' do
@@ -166,7 +164,7 @@ describe "PuppetDebugger" do
166
164
  it do
167
165
  debugger.play_back_string(input)
168
166
  expect(output.string).to include("$var1 = 'test'")
169
- expect(output.string).to include("\"test\"")
167
+ expect(output.string).to include('"test"')
170
168
  end
171
169
  end
172
170
  end
@@ -194,7 +192,7 @@ describe "PuppetDebugger" do
194
192
 
195
193
  describe 'empty' do
196
194
  let(:input) do
197
- ""
195
+ ''
198
196
  end
199
197
  it 'can run' do
200
198
  debugger_output = "\n"
@@ -203,7 +201,7 @@ describe "PuppetDebugger" do
203
201
  end
204
202
  describe 'space' do
205
203
  let(:input) do
206
- " "
204
+ ' '
207
205
  end
208
206
  it 'can run' do
209
207
  debugger_output = "\n"
@@ -215,7 +213,7 @@ describe "PuppetDebugger" do
215
213
 
216
214
  describe 'krt' do
217
215
  let(:input) do
218
- "krt"
216
+ 'krt'
219
217
  end
220
218
  it 'can run' do
221
219
  debugger_output = /hostclasses/
@@ -269,7 +267,7 @@ describe "PuppetDebugger" do
269
267
 
270
268
  describe 'bad input' do
271
269
  let(:input) do
272
- "Service{"
270
+ 'Service{'
273
271
  end
274
272
  it 'can process' do
275
273
  debugger_output = "\n => \e[31mSyntax error at end of file\e[0m\n"
@@ -280,7 +278,7 @@ describe "PuppetDebugger" do
280
278
 
281
279
  describe 'classification' do
282
280
  let(:input) do
283
- "classification"
281
+ 'classification'
284
282
  end
285
283
 
286
284
  it 'can process a file' do
@@ -305,7 +303,7 @@ describe "PuppetDebugger" do
305
303
 
306
304
  describe 'loglevel' do
307
305
  it 'has not changed' do
308
- debugger.handle_input(":set loglevel debug")
306
+ debugger.handle_input(':set loglevel debug')
309
307
  expect(Puppet::Util::Log.level).to eq(:debug)
310
308
  expect(Puppet::Util::Log.destinations[:buffer].name).to eq(:buffer)
311
309
  debugger.handle_input('reset')
@@ -339,7 +337,7 @@ describe "PuppetDebugger" do
339
337
 
340
338
  describe 'facts' do
341
339
  let(:input) do
342
- "$::fqdn"
340
+ '$::fqdn'
343
341
  end
344
342
  it 'should be able to resolve fqdn' do
345
343
  debugger_output = /foo\.example\.com/
@@ -350,7 +348,7 @@ describe "PuppetDebugger" do
350
348
 
351
349
  describe 'print facts' do
352
350
  let(:input) do
353
- "facts"
351
+ 'facts'
354
352
  end
355
353
  it 'should be able to print facts' do
356
354
  debugger_output = /kernel/
@@ -394,7 +392,7 @@ describe "PuppetDebugger" do
394
392
 
395
393
  describe 'set' do
396
394
  let(:input) do
397
- ":set loglevel debug"
395
+ ':set loglevel debug'
398
396
  end
399
397
  it 'should set the loglevel' do
400
398
  debugger_output = /loglevel debug is set/
@@ -407,7 +405,7 @@ describe "PuppetDebugger" do
407
405
 
408
406
  describe 'vars' do
409
407
  let(:input) do
410
- "vars"
408
+ 'vars'
411
409
  end
412
410
  it 'display facts variable' do
413
411
  debugger_output = /facts/
@@ -427,10 +425,9 @@ describe "PuppetDebugger" do
427
425
  it 'display local variable' do
428
426
  debugger.handle_input("$var1 = 'value1'")
429
427
  expect(output.string).to match(/value1/)
430
- debugger.handle_input("$var1")
428
+ debugger.handle_input('$var1')
431
429
  expect(output.string).to match(/value1/)
432
430
  end
433
-
434
431
  end
435
432
 
436
433
  describe 'execute functions' do
@@ -438,12 +435,12 @@ describe "PuppetDebugger" do
438
435
  "md5('hello')"
439
436
  end
440
437
  it 'execute md5' do
441
- debugger_output = /5d41402abc4b2a76b9719d911017c592/
438
+ debugger_output = /5d41402abc4b2a76b9719d911017c592/
442
439
  debugger.handle_input(input)
443
440
  expect(output.string).to match(debugger_output)
444
441
  end
445
442
  it 'execute swapcase' do
446
- debugger_output = /HELLO/
443
+ debugger_output = /HELLO/
447
444
  debugger.handle_input("swapcase('hello')")
448
445
  expect(output.string).to match(debugger_output)
449
446
  end
@@ -455,8 +452,8 @@ describe "PuppetDebugger" do
455
452
  end
456
453
  let(:options) do
457
454
  {
458
- source_file: input,
459
- source_line: 10,
455
+ source_file: input,
456
+ source_line: 10
460
457
  }
461
458
  end
462
459
 
@@ -466,7 +463,6 @@ describe "PuppetDebugger" do
466
463
  it 'contains marker' do
467
464
  expect(debugger.whereami).to match(/\s+=>\s10/)
468
465
  end
469
-
470
466
  end
471
467
 
472
468
  describe 'error message' do
@@ -475,18 +471,16 @@ describe "PuppetDebugger" do
475
471
  end
476
472
  if Gem::Version.new(Puppet.version) >= Gem::Version.new('4.0')
477
473
  it 'show error message' do
478
- debugger_output = /no\ parameter\ named\ 'contact'/
474
+ debugger_output = /no\ parameter\ named\ 'contact'/
479
475
  debugger.handle_input(input)
480
476
  expect(output.string).to match(debugger_output)
481
477
  end
482
478
  else
483
479
  it 'show error message' do
484
- debugger_output = /Invalid\ parameter\ contact/
480
+ debugger_output = /Invalid\ parameter\ contact/
485
481
  debugger.handle_input(input)
486
482
  expect(output.string).to match(debugger_output)
487
483
  end
488
484
  end
489
-
490
485
  end
491
-
492
486
  end
@@ -1,7 +1,7 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
  require 'stringio'
3
- describe "PuppetDebugger" do
4
-
4
+ describe 'PuppetDebugger' do
5
5
  let(:resource) do
6
6
  "service{'httpd': ensure => running}"
7
7
  end
@@ -15,7 +15,7 @@ describe "PuppetDebugger" do
15
15
  end
16
16
 
17
17
  let(:debugger) do
18
- PuppetDebugger::Cli.new(:out_buffer => output)
18
+ PuppetDebugger::Cli.new(out_buffer: output)
19
19
  end
20
20
 
21
21
  let(:input) do
@@ -43,13 +43,13 @@ describe "PuppetDebugger" do
43
43
  expect(output.string).to eq("\n => Resetting to use node puppetdev.localdomain\n")
44
44
  end
45
45
 
46
- it "return node name" do
46
+ it 'return node name' do
47
47
  output.reopen # removes previous message
48
48
  debugger.handle_input('$::hostname')
49
49
  expect(output.string).to match(/puppetdev.localdomain/)
50
50
  end
51
51
 
52
- it "return classification" do
52
+ it 'return classification' do
53
53
  output.reopen # removes previous message
54
54
  debugger.handle_input('classification')
55
55
  expect(output.string).to match(/stdlib/)
@@ -65,7 +65,6 @@ describe "PuppetDebugger" do
65
65
  debugger.handle_input(input)
66
66
  expect(output.string).to match(debugger_output)
67
67
  end
68
-
69
68
  end
70
69
  describe 'use defaults when invalid' do
71
70
  let(:node_obj) do
@@ -75,12 +74,12 @@ describe "PuppetDebugger" do
75
74
  'invalid.localdomain'
76
75
  end
77
76
  it 'name' do
78
- expect{debugger.node.name}.to raise_error(PuppetDebugger::Exception::UndefinedNode)
77
+ expect { debugger.node.name }.to raise_error(PuppetDebugger::Exception::UndefinedNode)
79
78
  end
80
79
  end
81
80
 
82
81
  it 'set node name' do
83
- expect(debugger.remote_node_name = 'puppetdev.localdomain').to eq("puppetdev.localdomain")
82
+ expect(debugger.remote_node_name = 'puppetdev.localdomain').to eq('puppetdev.localdomain')
84
83
  end
85
84
 
86
85
  describe 'print classes' do
@@ -96,7 +95,7 @@ describe "PuppetDebugger" do
96
95
 
97
96
  describe 'vars' do
98
97
  let(:input) do
99
- "vars"
98
+ 'vars'
100
99
  end
101
100
  it 'display facts variable' do
102
101
  debugger_output = /facts/
@@ -116,11 +115,11 @@ describe "PuppetDebugger" do
116
115
  it 'display local variable' do
117
116
  debugger.handle_input("$var1 = 'value1'")
118
117
  expect(output.string).to match(/value1/)
119
- debugger.handle_input("$var1")
118
+ debugger.handle_input('$var1')
120
119
  expect(output.string).to match(/value1/)
121
120
  end
122
121
  it 'display productname variable' do
123
- debugger.handle_input("$productname")
122
+ debugger.handle_input('$productname')
124
123
  expect(output.string).to match(/VMware Virtual Platform/)
125
124
  end
126
125
  end
@@ -130,12 +129,12 @@ describe "PuppetDebugger" do
130
129
  "md5('hello')"
131
130
  end
132
131
  it 'execute md5' do
133
- debugger_output = /5d41402abc4b2a76b9719d911017c592/
132
+ debugger_output = /5d41402abc4b2a76b9719d911017c592/
134
133
  debugger.handle_input(input)
135
134
  expect(output.string).to match(debugger_output)
136
135
  end
137
136
  it 'execute swapcase' do
138
- debugger_output = /HELLO/
137
+ debugger_output = /HELLO/
139
138
  debugger.handle_input("swapcase('hello')")
140
139
  expect(output.string).to match(debugger_output)
141
140
  end
@@ -158,7 +157,7 @@ describe "PuppetDebugger" do
158
157
 
159
158
  describe 'classification' do
160
159
  let(:input) do
161
- "classification"
160
+ 'classification'
162
161
  end
163
162
 
164
163
  it 'shows certificate_authority_host' do