puppet-debugger 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.gitlab-ci.yml +30 -13
  4. data/.rubocop.yml +3 -1
  5. data/.rubocop_todo.yml +11 -2
  6. data/.ruby-version +1 -1
  7. data/CHANGELOG.md +9 -0
  8. data/DEVELOPMENT.md +6 -1
  9. data/Gemfile +14 -12
  10. data/Plugin_development.md +304 -0
  11. data/README.md +4 -7
  12. data/Rakefile +6 -5
  13. data/bin/pdb +1 -0
  14. data/lib/awesome_print/ext/awesome_puppet.rb +1 -0
  15. data/lib/plugins/puppet-debugger/input_responders/benchmark.rb +40 -0
  16. data/lib/plugins/puppet-debugger/input_responders/classes.rb +15 -0
  17. data/lib/plugins/puppet-debugger/input_responders/classification.rb +14 -0
  18. data/lib/plugins/puppet-debugger/input_responders/commands.rb +95 -0
  19. data/lib/plugins/puppet-debugger/input_responders/datatypes.rb +17 -0
  20. data/lib/plugins/puppet-debugger/input_responders/environment.rb +14 -0
  21. data/lib/plugins/puppet-debugger/input_responders/exit.rb +14 -0
  22. data/lib/plugins/puppet-debugger/input_responders/facterdb_filter.rb +16 -0
  23. data/lib/plugins/puppet-debugger/input_responders/facts.rb +15 -0
  24. data/lib/plugins/puppet-debugger/input_responders/functions.rb +15 -0
  25. data/lib/plugins/puppet-debugger/input_responders/help.rb +14 -0
  26. data/lib/plugins/puppet-debugger/input_responders/krt.rb +14 -0
  27. data/lib/{puppet-debugger/support → plugins/puppet-debugger/input_responders}/play.rb +37 -26
  28. data/lib/plugins/puppet-debugger/input_responders/reset.rb +21 -0
  29. data/lib/plugins/puppet-debugger/input_responders/resources.rb +22 -0
  30. data/lib/plugins/puppet-debugger/input_responders/set.rb +55 -0
  31. data/lib/plugins/puppet-debugger/input_responders/types.rb +35 -0
  32. data/lib/plugins/puppet-debugger/input_responders/vars.rb +18 -0
  33. data/lib/plugins/puppet-debugger/input_responders/whereami.rb +29 -0
  34. data/lib/puppet-debugger.rb +12 -1
  35. data/lib/puppet-debugger/cli.rb +38 -22
  36. data/lib/puppet-debugger/code/code_file.rb +16 -15
  37. data/lib/puppet-debugger/code/code_range.rb +1 -0
  38. data/lib/puppet-debugger/code/loc.rb +1 -0
  39. data/lib/puppet-debugger/debugger_code.rb +1 -0
  40. data/lib/puppet-debugger/hooks.rb +174 -0
  41. data/lib/puppet-debugger/input_responder_plugin.rb +45 -0
  42. data/lib/puppet-debugger/plugin_test_helper.rb +44 -0
  43. data/lib/puppet-debugger/support.rb +13 -9
  44. data/lib/puppet-debugger/support/compiler.rb +1 -0
  45. data/lib/puppet-debugger/support/environment.rb +2 -0
  46. data/lib/puppet-debugger/support/errors.rb +9 -0
  47. data/lib/puppet-debugger/support/facts.rb +2 -1
  48. data/lib/puppet-debugger/support/functions.rb +3 -1
  49. data/lib/puppet-debugger/support/loader.rb +2 -0
  50. data/lib/puppet-debugger/support/node.rb +1 -0
  51. data/lib/puppet-debugger/support/scope.rb +1 -0
  52. data/lib/puppet/application/debugger.rb +1 -0
  53. data/lib/version.rb +2 -1
  54. data/puppet-debugger.gemspec +20 -15
  55. data/run_container_test.sh +1 -1
  56. data/spec/environment_spec.rb +2 -1
  57. data/spec/facts_spec.rb +1 -0
  58. data/spec/hooks_spec.rb +341 -0
  59. data/spec/input_responder_plugin_spec.rb +45 -0
  60. data/spec/input_responders/help_spec.rb +17 -0
  61. data/spec/input_responders/krt_spec.rb +12 -0
  62. data/spec/input_responders/play_spec.rb +160 -0
  63. data/spec/pdb_spec.rb +1 -0
  64. data/spec/puppet/application/debugger_spec.rb +1 -2
  65. data/spec/puppet_debugger_spec.rb +49 -88
  66. data/spec/remote_node_spec.rb +3 -2
  67. data/spec/spec_helper.rb +7 -0
  68. data/spec/support_spec.rb +5 -116
  69. data/test_matrix.rb +2 -0
  70. metadata +65 -12
  71. data/Gemfile.lock +0 -95
  72. data/lib/puppet-debugger/support/input_responders.rb +0 -191
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+ require 'puppet-debugger/input_responder_plugin'
3
+
4
+ describe :input_responder_plugin do
5
+ let(:output) do
6
+ StringIO.new
7
+ end
8
+
9
+ before(:each) do
10
+ allow(plugin).to receive(:run).and_return([])
11
+ end
12
+
13
+ let(:debugger) do
14
+ PuppetDebugger::Cli.new({ out_buffer: output }.merge(options))
15
+ end
16
+
17
+ let(:options) do
18
+ {}
19
+ end
20
+
21
+ let(:plugin) do
22
+ instance = PuppetDebugger::InputResponderPlugin.instance
23
+ instance.debugger = debugger
24
+ instance
25
+ end
26
+
27
+ it 'works' do
28
+ expect(plugin.run([])).to eq([])
29
+ end
30
+
31
+ {scope: Puppet::Parser::Scope, node: Puppet::Node, facts: Puppet::Node::Facts,
32
+ environment: Puppet::Node::Environment, function_map: Hash,
33
+ compiler: Puppet::Parser::Compiler, catalog: Puppet::Resource::Catalog}.each do |name, klass|
34
+ it "can access #{name}" do
35
+ expect(plugin.send(name).class).to be klass
36
+ end
37
+ end
38
+
39
+ [:add_hook, :handle_input, :delete_hook, :handle_input].each do |name|
40
+ it "responds to method #{name}" do
41
+ expect(plugin.respond_to?(name)).to eq(true)
42
+ end
43
+ end
44
+
45
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+ require 'puppet-debugger/plugin_test_helper'
3
+
4
+ describe :help do
5
+ include_examples "plugin_tests"
6
+ let(:args) { [] }
7
+
8
+ it 'can show the help screen' do
9
+ output = plugin.run(args)
10
+ expected_debugger_output = /Type \"commands\" for a list of debugger commands\nor \"help\" to show the help screen.\n\n/
11
+ expect(output).to match(/Ruby Version: #{RUBY_VERSION}\n/)
12
+ expect(output).to match(/Puppet Version: \d.\d\d?.\d\n/)
13
+ expect(output).to match(/Puppet Debugger Version: \d.\d.\d\n/)
14
+ expect(output).to match(/Created by: NWOps <corey@nwops.io>\n/)
15
+ expect(output).to match(expected_debugger_output)
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+ require 'puppet-debugger/plugin_test_helper'
3
+
4
+ describe :krt do
5
+ include_examples "plugin_tests"
6
+ let(:args) { [] }
7
+
8
+ it 'works' do
9
+ expect(plugin.run(args)).to match(/hostclasses/)
10
+ end
11
+
12
+ end
@@ -0,0 +1,160 @@
1
+ require 'spec_helper'
2
+ require 'puppet-debugger/plugin_test_helper'
3
+ describe :play do
4
+ include_examples "plugin_tests"
5
+
6
+ describe 'convert url' do
7
+ describe 'unsupported' do
8
+ let(:url) { 'https://bitbuck.com/master/lib/log_helper.rb' }
9
+ let(:converted) { 'https://bitbuck.com/master/lib/log_helper.rb' }
10
+ it do
11
+ expect(plugin.convert_to_text(url)).to eq(converted)
12
+ end
13
+ end
14
+ describe 'gitlab' do
15
+ describe 'blob' do
16
+ let(:url) { 'https://gitlab.com/nwops/pdebugger-web/blob/master/lib/log_helper.rb' }
17
+ let(:converted) { 'https://gitlab.com/nwops/pdebugger-web/raw/master/lib/log_helper.rb' }
18
+ it do
19
+ expect(plugin.convert_to_text(url)).to eq(converted)
20
+ end
21
+ end
22
+
23
+ describe 'raw' do
24
+ let(:url) { 'https://gitlab.com/nwops/pdebugger-web/raw/master/lib/log_helper.rb' }
25
+ let(:converted) { 'https://gitlab.com/nwops/pdebugger-web/raw/master/lib/log_helper.rb' }
26
+ it do
27
+ expect(plugin.convert_to_text(url)).to eq(converted)
28
+ end
29
+ end
30
+
31
+ describe 'snippet' do
32
+ describe 'not raw' do
33
+ let(:url) { 'https://gitlab.com/snippets/19471' }
34
+ let(:converted) { 'https://gitlab.com/snippets/19471/raw' }
35
+ it do
36
+ expect(plugin.convert_to_text(url)).to eq(converted)
37
+ end
38
+ end
39
+
40
+ describe 'raw' do
41
+ let(:url) { 'https://gitlab.com/snippets/19471/raw' }
42
+ let(:converted) { 'https://gitlab.com/snippets/19471/raw' }
43
+ it do
44
+ expect(plugin.convert_to_text(url)).to eq(converted)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ describe 'github' do
50
+ describe 'raw' do
51
+ let(:url) { 'https://gist.githubusercontent.com/logicminds/f9b1ac65a3a440d562b0/raw' }
52
+ let(:converted) { 'https://gist.githubusercontent.com/logicminds/f9b1ac65a3a440d562b0/raw' }
53
+ it do
54
+ expect(plugin.convert_to_text(url)).to eq(converted)
55
+ end
56
+ end
57
+ describe 'raw' do
58
+ let(:url) { 'https://gist.githubusercontent.com/logicminds/f9b1ac65a3a440d562b0' }
59
+ let(:converted) { 'https://gist.githubusercontent.com/logicminds/f9b1ac65a3a440d562b0.txt' }
60
+ it do
61
+ expect(plugin.convert_to_text(url)).to eq(converted)
62
+ end
63
+ end
64
+ describe 'raw gist' do
65
+ let(:url) { 'https://gist.githubusercontent.com/logicminds/f9b1ac65a3a440d562b0/raw/c8f6be52da5b2b0eeaabb9aa75832b75793d35d1/controls.pp' }
66
+ let(:converted) { 'https://gist.githubusercontent.com/logicminds/f9b1ac65a3a440d562b0/raw/c8f6be52da5b2b0eeaabb9aa75832b75793d35d1/controls.pp' }
67
+ it do
68
+ expect(plugin.convert_to_text(url)).to eq(converted)
69
+ end
70
+ end
71
+ describe 'raw non gist' do
72
+ let(:url) { 'https://raw.githubusercontent.com/nwops/puppet-debugger/master/lib/puppet-debugger.rb' }
73
+ let(:converted) { 'https://raw.githubusercontent.com/nwops/puppet-debugger/master/lib/puppet-debugger.rb' }
74
+ it do
75
+ expect(plugin.convert_to_text(url)).to eq(converted)
76
+ end
77
+ end
78
+
79
+ describe 'blob' do
80
+ let(:url) { 'https://github.com/nwops/puppet-debugger/blob/master/lib/puppet-debugger.rb' }
81
+ let(:converted) { 'https://github.com/nwops/puppet-debugger/raw/master/lib/puppet-debugger.rb' }
82
+ it do
83
+ expect(plugin.convert_to_text(url)).to eq(converted)
84
+ end
85
+ end
86
+
87
+ describe 'gist' do
88
+ let(:url) { 'https://gist.github.com/logicminds/f9b1ac65a3a440d562b0' }
89
+ let(:converted) { 'https://gist.github.com/logicminds/f9b1ac65a3a440d562b0.txt' }
90
+ it do
91
+ expect(plugin.convert_to_text(url)).to eq(converted)
92
+ end
93
+ end
94
+ end
95
+ end
96
+
97
+ describe 'multiple lines of input' do
98
+ before(:each) do
99
+
100
+ end
101
+ describe '3 lines' do
102
+ let(:input) do
103
+ "$var1 = 'test'\nfile{\"/tmp/${var1}.txt\": ensure => present, mode => '0755'}\nvars"
104
+ end
105
+ it do
106
+ plugin.play_back_string(input)
107
+ expect(output.string).to match(/server_facts/) if Gem::Version.new(Puppet.version) >= Gem::Version.new(4.1)
108
+ expect(output.string).to match(/test/)
109
+ expect(output.string).to match(/Puppet::Type::File/)
110
+ end
111
+ end
112
+ describe '2 lines' do
113
+ let(:input) do
114
+ "$var1 = 'test'\n $var2 = 'test2'"
115
+ end
116
+ it do
117
+ plugin.play_back_string(input)
118
+ expect(output.string).to include("$var1 = 'test'")
119
+ expect(output.string).to include('"test"')
120
+ expect(output.string).to include("$var2 = 'test2'")
121
+ expect(output.string).to include('"test2"')
122
+ end
123
+ end
124
+ describe '1 lines' do
125
+ let(:input) do
126
+ "$var1 = 'test'"
127
+ end
128
+ it do
129
+ plugin.play_back_string(input)
130
+ expect(output.string).to include("$var1 = 'test'")
131
+ expect(output.string).to include('"test"')
132
+ end
133
+ end
134
+ end
135
+
136
+ describe 'play' do
137
+ let(:fixtures_file) do
138
+ File.join(fixtures_dir, 'sample_manifest.pp')
139
+ end
140
+
141
+ let(:file_url) do
142
+ 'https://gist.github.com/logicminds/f9b1ac65a3a440d562b0'
143
+ end
144
+ let(:input) do
145
+ "play #{file_url}"
146
+ end
147
+ # requires internet and stops testing
148
+ xit 'url' do
149
+ allow(debugger).to receive(:fetch_url_data).with(file_url + '.txt').and_return(File.read(fixtures_file))
150
+ debugger.handle_input(input)
151
+ expect(output.string).to match(/test/)
152
+ expect(output.string).to match(/Puppet::Type::File/)
153
+ end
154
+
155
+ it 'file' do
156
+ debugger.handle_input("play #{fixtures_file}")
157
+ expect(output.string).to match(/Puppet::Type::File/)
158
+ end
159
+ end
160
+ end
data/spec/pdb_spec.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'spec_helper'
3
4
 
4
5
  describe 'pdb' do
@@ -1,7 +1,6 @@
1
- #! /usr/bin/env ruby
2
1
  # frozen_string_literal: true
3
- require 'spec_helper'
4
2
 
3
+ require 'spec_helper'
5
4
  require 'puppet/application/debugger'
6
5
 
7
6
  describe Puppet::Application::Debugger do
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'spec_helper'
3
4
  require 'stringio'
4
5
  describe 'PuppetDebugger' do
@@ -11,7 +12,7 @@ describe 'PuppetDebugger' do
11
12
  end
12
13
 
13
14
  let(:output) do
14
- StringIO.new('', 'w')
15
+ StringIO.new
15
16
  end
16
17
 
17
18
  let(:debugger) do
@@ -127,47 +128,15 @@ describe 'PuppetDebugger' do
127
128
  'type([1,2,3,4])'
128
129
  end
129
130
  it 'shows type' do
130
- debugger.handle_input(input)
131
- expect(output.string).to eq("\n => Tuple[Integer[1, 1], Integer[2, 2], Integer[3, 3], Integer[4, 4]]\n") if supports_type_function?
131
+ if Gem::Version.new(Puppet.version) > Gem::Version.new('4.4')
132
+ debugger.handle_input(input)
133
+ expect(output.string).to eq("\n => Tuple[Integer[1, 1], Integer[2, 2], Integer[3, 3], Integer[4, 4]]\n") if supports_type_function?
134
+ end
132
135
  end
133
136
  end
134
137
  end
135
138
 
136
- describe 'multiple lines of input' do
137
- describe '3 lines' do
138
- let(:input) do
139
- "$var1 = 'test'\nfile{\"/tmp/${var1}.txt\": ensure => present, mode => '0755'}\nvars"
140
- end
141
- it do
142
- debugger.play_back_string(input)
143
- expect(output.string).to match(/server_facts/) if Puppet.version.to_f >= 4.1
144
- expect(output.string).to match(/test/)
145
- expect(output.string).to match(/Puppet::Type::File/)
146
- end
147
- end
148
- describe '2 lines' do
149
- let(:input) do
150
- "$var1 = 'test'\n $var2 = 'test2'"
151
- end
152
- it do
153
- debugger.play_back_string(input)
154
- expect(output.string).to include("$var1 = 'test'")
155
- expect(output.string).to include('"test"')
156
- expect(output.string).to include("$var2 = 'test2'")
157
- expect(output.string).to include('"test2"')
158
- end
159
- end
160
- describe '1 lines' do
161
- let(:input) do
162
- "$var1 = 'test'"
163
- end
164
- it do
165
- debugger.play_back_string(input)
166
- expect(output.string).to include("$var1 = 'test'")
167
- expect(output.string).to include('"test"')
168
- end
169
- end
170
- end
139
+
171
140
 
172
141
  describe 'returns a array of resource_types' do
173
142
  it 'returns resource type' do
@@ -175,20 +144,40 @@ describe 'PuppetDebugger' do
175
144
  end
176
145
  end
177
146
 
178
- describe 'help' do
179
- let(:input) do
180
- 'help'
181
- end
182
- it 'can show the help screen' do
183
- expected_debugger_output = /Type \"exit\", \"functions\", \"vars\", \"krt\", \"whereami\", \"facts\", \"resources\", \"classes\",\n \"play\", \"classification\", \"types\", \"datatypes\", \"benchmark\",\n \"reset\", or \"help\" for more information.\n\n/
184
- debugger.handle_input(input)
185
- expect(output.string).to match(/Ruby Version: #{RUBY_VERSION}\n/)
186
- expect(output.string).to match(/Puppet Version: \d.\d.\d\n/)
187
- expect(output.string).to match(/Puppet Debugger Version: \d.\d.\d\n/)
188
- expect(output.string).to match(/Created by: NWOps <corey@nwops.io>\n/)
189
- expect(output.string).to match(expected_debugger_output)
190
- end
191
- end
147
+ # describe 'commands' do
148
+ # let(:input) do
149
+ # 'commands'
150
+ # end
151
+ #
152
+ # it 'shows a list of groups of available commands' do
153
+ # command_groups = {
154
+ # 'Important' => { 'help' => 'Get help.' },
155
+ #
156
+ # 'Misc' => {
157
+ # 'do_something' => 'Do something good.',
158
+ # 'do_something_else' => 'Do something really good.'
159
+ # }
160
+ # }
161
+ #
162
+ # stub_const('PuppetDebugger::Support::InputResponders::COMMAND_GROUPS', command_groups)
163
+ #
164
+ # debugger.handle_input(input)
165
+ #
166
+ # command_groups.each do |command_group|
167
+ # group_name = command_group[0]
168
+ # group_commands = command_group[1]
169
+ #
170
+ # expect(output.string).to match(group_name)
171
+ #
172
+ # group_commands.each do |command|
173
+ # command_name = command[0]
174
+ # command_description = command[1]
175
+ # expect(output.string).to match(command_name)
176
+ # expect(output.string).to match(command_description)
177
+ # end
178
+ # end
179
+ # end
180
+ # end
192
181
 
193
182
  describe 'empty' do
194
183
  let(:input) do
@@ -211,39 +200,6 @@ describe 'PuppetDebugger' do
211
200
  end
212
201
  end
213
202
 
214
- describe 'krt' do
215
- let(:input) do
216
- 'krt'
217
- end
218
- it 'can run' do
219
- debugger_output = /hostclasses/
220
- debugger.handle_input(input)
221
- expect(output.string).to match(debugger_output)
222
- end
223
- end
224
-
225
- describe 'play' do
226
- let(:fixtures_file) do
227
- File.join(fixtures_dir, 'sample_manifest.pp')
228
- end
229
-
230
- before(:each) do
231
- allow(debugger).to receive(:fetch_url_data).with(file_url + '.txt').and_return(File.read(fixtures_file))
232
- end
233
-
234
- let(:file_url) do
235
- 'https://gist.githubusercontent.com/logicminds/f9b1ac65a3a440d562b0'
236
- end
237
- it 'file' do
238
- debugger.handle_input("play #{fixtures_file}")
239
- expect(output.string).to match(/Puppet::Type::File/)
240
- end
241
- it 'url' do
242
- debugger.handle_input("play #{file_url}")
243
- expect(output.string).to match(/Puppet::Type::File/)
244
- end
245
- end
246
-
247
203
  describe 'variables' do
248
204
  let(:input) do
249
205
  "$file_path = '/tmp/test2.txt'"
@@ -452,7 +408,7 @@ describe 'PuppetDebugger' do
452
408
  end
453
409
  it 'handle datatypes' do
454
410
  debugger.handle_input(input)
455
- if Puppet.version < '4.3.0'
411
+ if Gem::Version.new(Puppet.version) < Gem::Version.new('4.5.0')
456
412
  expect(output.string).to eq("\n[]\n")
457
413
  else
458
414
  expect(output.string).to match(/.*Array.*/)
@@ -471,11 +427,16 @@ describe 'PuppetDebugger' do
471
427
  }
472
428
  end
473
429
 
430
+ before(:each) do
431
+ debugger.handle_input('whereami')
432
+ end
433
+
474
434
  it 'runs' do
475
- expect(debugger.whereami).to match(/\s+5/)
435
+ expect(output.string).to match(/\s+5/)
476
436
  end
437
+
477
438
  it 'contains marker' do
478
- expect(debugger.whereami).to match(/\s+=>\s10/)
439
+ expect(output.string).to match(/\s+=>\s10/)
479
440
  end
480
441
  end
481
442
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'spec_helper'
3
4
  require 'stringio'
4
5
  describe 'PuppetDebugger' do
@@ -11,7 +12,7 @@ describe 'PuppetDebugger' do
11
12
  end
12
13
 
13
14
  let(:output) do
14
- StringIO.new('', 'w')
15
+ StringIO.new
15
16
  end
16
17
 
17
18
  let(:debugger) do
@@ -40,7 +41,7 @@ describe 'PuppetDebugger' do
40
41
 
41
42
  describe 'set' do
42
43
  it 'sends message about resetting' do
43
- expect(output.string).to eq("\n => Resetting to use node puppetdev.localdomain\n")
44
+ expect(output.string).to eq("\nResetting to use node puppetdev.localdomain\n")
44
45
  end
45
46
 
46
47
  it 'return node name' do