puppet-debugger 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/.gitlab-ci.yml +6 -0
  4. data/CHANGELOG.md +7 -0
  5. data/Gemfile +2 -1
  6. data/Plugin_development.md +43 -1
  7. data/README.md +13 -1
  8. data/Rakefile +24 -0
  9. data/lib/plugins/puppet-debugger/input_responders/commands.rb +2 -20
  10. data/lib/plugins/puppet-debugger/input_responders/play.rb +1 -1
  11. data/lib/plugins/puppet-debugger/input_responders/set.rb +20 -0
  12. data/lib/puppet-debugger/cli.rb +19 -4
  13. data/lib/puppet-debugger/input_responder_plugin.rb +12 -0
  14. data/lib/version.rb +1 -1
  15. data/puppet-debugger.gemspec +1 -1
  16. data/spec/input_responders/benchmark_spec.rb +32 -0
  17. data/spec/input_responders/classes_spec.rb +22 -0
  18. data/spec/input_responders/classification_spec.rb +17 -0
  19. data/spec/input_responders/commands_spec.rb +22 -0
  20. data/spec/input_responders/datatypes_spec.rb +17 -0
  21. data/spec/input_responders/environment_spec.rb +13 -0
  22. data/spec/input_responders/exit_spec.rb +51 -0
  23. data/spec/input_responders/facterdb_filter_spec.rb +12 -0
  24. data/spec/input_responders/facts_spec.rb +20 -0
  25. data/spec/input_responders/functions_spec.rb +20 -0
  26. data/spec/input_responders/krt_spec.rb +1 -2
  27. data/spec/input_responders/play_spec.rb +14 -0
  28. data/spec/input_responders/reset_spec.rb +27 -0
  29. data/spec/input_responders/resources_spec.rb +13 -0
  30. data/spec/input_responders/set_spec.rb +18 -0
  31. data/spec/input_responders/types_spec.rb +22 -0
  32. data/spec/input_responders/vars_spec.rb +27 -0
  33. data/spec/input_responders/whereami_spec.rb +28 -0
  34. data/spec/puppet_debugger_spec.rb +12 -270
  35. metadata +20 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6e41642281d06f230cba649f0ad0cca8845fc713
4
- data.tar.gz: 5f51ef9afa5c431937be5fa750978b3bedcf1b70
3
+ metadata.gz: 06bfeaee11d72cc1f5e2a68a325bf5c892df207a
4
+ data.tar.gz: 3ddd0743cc4daa1079174a4477c4863a373c326b
5
5
  SHA512:
6
- metadata.gz: 991540c9bb5dbd2e8995695818f0c05ce139c2832cfccd793ad01b3c062d242fd70026b4d4b2d19773b0268d0bc6d8d6709241dbe8bf030dd0663215ec43f1bf
7
- data.tar.gz: bd44969d0b5b2c934de7f4705ed6fa9828363d9c5e8a4a8bbcd672da351885552ab3e54d2b8197a26b56d6729fab21a97aa7eb536f4c6da0e07c73e1959ee6d5
6
+ metadata.gz: 07523f3f0f261e283c35c2d74f4feceba1f0d8a5b5416aa6b5f1206870fc28948fa231758ce41988c02788fc94ea7c5d11fcc17c2d922ef811e733c4a1959a20
7
+ data.tar.gz: accdd33ea736b3948e5191f27384135aada416962e740eaecde54a4147ed2bc4e0276c620272a725c5b5c6fca6f21df0e71a9111c73f2662e8bd5a26a268b93b
data/.gitignore CHANGED
@@ -10,6 +10,7 @@ bundler
10
10
  vendor
11
11
  coverage
12
12
  coverage.data
13
+ .DS*
13
14
 
14
15
  # rdoc generated
15
16
  rdoc
@@ -24,7 +25,7 @@ doc
24
25
  # jeweler generated
25
26
  pkg
26
27
 
27
- # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
28
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
28
29
  #
29
30
  # * Create a file at ~/.gitignore
30
31
  # * Include files you want ignored
data/.gitlab-ci.yml CHANGED
@@ -171,3 +171,9 @@ puppet_410_ruby24:
171
171
  PUPPET_GEM_VERSION: "~> 4.10.0"
172
172
  <<: *puppet_job_def
173
173
  <<: *ruby24
174
+
175
+ puppet_5_ruby24:
176
+ variables:
177
+ PUPPET_GEM_VERSION: "~> 5.0"
178
+ <<: *puppet_job_def
179
+ <<: *ruby24
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  ## Unreleased
2
2
 
3
+ ## 0.8.0
4
+ * Fixes bug with playback of multiline input
5
+ * Updates pluginator Gem to 1.5.0
6
+ * Adds ability to provide command completion for plugins
7
+ * Fixes error with commands plugin where id didn't detect bad names
8
+ * Fixes #3 - Move old input responder test code to individual plugin tests
9
+ * Adds puppet 5 to testing matrix
3
10
  ## 0.7.0
4
11
  * Adds new commands command
5
12
  * Adds new help command
data/Gemfile CHANGED
@@ -3,7 +3,8 @@ source 'http://rubygems.org'
3
3
  gem 'awesome_print', '~> 1.7'
4
4
  gem 'facterdb', '~> 0.3.8'
5
5
  gem 'puppet', ENV['PUPPET_GEM_VERSION'] || '~> 4.10.1'
6
- gem 'pluginator', '~> 1.4.1'
6
+ gem 'pluginator', '~> 1.5.0'
7
+
7
8
  group :test, :development do
8
9
  # ruby versions prior to 2.0 cannot install json_pure 2.0.2+
9
10
  gem 'bundler'
@@ -20,6 +20,7 @@
20
20
  - [Calling other plugins](#calling-other-plugins)
21
21
  - [Indirectly](#indirectly)
22
22
  - [Directly](#directly)
23
+ - [Command Completion](#command-completion)
23
24
  - [Testing your plugin code](#testing-your-plugin-code)
24
25
  - [Examples](#examples)
25
26
 
@@ -199,6 +200,8 @@ Objects exposed that you might want access to:
199
200
  * compiler (The puppet compiler object)
200
201
  * catalog (The puppet catalog)
201
202
  * function_map (Current map of functions)
203
+ * add_hook, delete_hook
204
+ * handle_input (use instead of debugger.handle_input)
202
205
 
203
206
  While you do have access to the `debugger` object itself and everything inside this object. I would recommend not using the debugger
204
207
  object directly since the debugger code base is changing rapidly. Usage can result in a broken plugin. If you are using
@@ -267,12 +270,51 @@ play_plugin = PuppetDebugger::InputResponders::Commands.plugin_from_command('pla
267
270
  # execute the plugin
268
271
  args = ['https://gists.github.com/sdalfsdfadsfds.txt']
269
272
  # pass an instance of the debugger (always do this)
270
- output = plugin.execute(args, debugger)
273
+ output = play_plugin.execute(args, debugger)
271
274
 
272
275
  ```
273
276
 
274
277
  If the command used to find the plugin is incorrect a `PuppetDebugger::Exception::InvalidCommand` error will be raised.
275
278
 
279
+ ## Command Completion
280
+ If your plugin takes extra arguments you may want to incorporate command completion to help the user. This can be done
281
+ by overriding the `self.command_completion` function in your plugin. The return value of this method must return an
282
+ array of possible words.
283
+
284
+ ```ruby
285
+ # @param buffer_words [Array[String]] a array of words the user has typed in
286
+ # @return Array[String] - an array of words that will help the user with word completion
287
+ # By default this returns an empty array, your plugin can chose to override this method in order to
288
+ # provide the user with a list of key words based on the user's input
289
+ def self.command_completion(buffer_words)
290
+ ['one', 'two', 'three']
291
+ end
292
+ ```
293
+
294
+ A real example of this can be found in the set plugin
295
+
296
+ ```ruby
297
+ KEYWORDS = %w(node loglevel)
298
+ LOGLEVELS = %w(debug info)
299
+
300
+ def self.command_completion(buffer_words)
301
+ next_word = buffer_words.shift
302
+ case next_word
303
+ when 'loglevel'
304
+ if buffer_words.count > 0
305
+ LOGLEVELS.grep(/^#{Regexp.escape(buffer_words.first)}/)
306
+ else
307
+ LOGLEVELS
308
+ end
309
+ when 'debug', 'info','node'
310
+ []
311
+ when nil
312
+ %w(node loglevel)
313
+ else
314
+ KEYWORDS.grep(/^#{Regexp.escape(next_word)}/)
315
+ end
316
+ end
317
+ ```
276
318
  ## Testing your plugin code
277
319
  1. Create a new rspec test file as `spec/input_responders/plugin_name_spec.rb`
278
320
 
data/README.md CHANGED
@@ -42,7 +42,7 @@ to install on your production puppet master. Please do not install because of th
42
42
  `gem install puppet-debugger`
43
43
 
44
44
  ## Load path
45
- puppet-debugger will load all functions from your basemodulepath and environmentpath.
45
+ puppet-debugger will load all puppet functions from your basemodulepath and environmentpath.
46
46
 
47
47
  This means if you run `puppet module install puppetlabs-stdlib` and they will be available
48
48
  in the debugger.
@@ -267,6 +267,18 @@ https://www.puppet-debugger.com/play?content=vars
267
267
  Please note the web based debugger only contains a minimal amount of puppet modules. So its likely
268
268
  that your code may not work if using third party modules. This may change in the future though.
269
269
 
270
+ ## Plugins
271
+ The puppet debugger has a plugin system that allows anyone to create new functionality
272
+ for the puppet debugger. By default the puppet debugger ships with serveral core
273
+ plugins that provide basic usage. Any non core plugin can be installed as a separate
274
+ gem. The following is a list of plugins we wrote or know about.
275
+
276
+
277
+ | Name | Project Url | Type | Description |
278
+ | ------------- |:-------------:| -----:| -------------:|
279
+ | playbooks | [playbooks](https://gitlab.com/puppet-debugger/puppet-debugger-playbooks) | editing | Allows group playback of scripted puppet commands |
280
+
281
+
270
282
  ## Development
271
283
  * [Plugin Development Guide](Plugin_development.md)
272
284
 
data/Rakefile CHANGED
@@ -31,3 +31,27 @@ Rake::RDocTask.new do |rdoc|
31
31
  rdoc.rdoc_files.include('README*')
32
32
  rdoc.rdoc_files.include('lib/**/*.rb')
33
33
  end
34
+
35
+ desc 'Creates generic input_responder spec files'
36
+ task :make_input_responder_tests do
37
+ files = Dir.glob("lib/plugins/**/*.rb")
38
+ new_files = files.collect do |pathname|
39
+ orig_file = File.basename(pathname, ".*")
40
+ test_file = File.join('spec', 'input_responders', "#{orig_file}_spec.rb")
41
+ unless File.exist?(test_file)
42
+ new_file = File.new(test_file, "w")
43
+ contents = <<-EOS
44
+ require 'spec_helper'
45
+ require 'puppet-debugger'
46
+ require 'puppet-debugger/plugin_test_helper'
47
+
48
+ describe :#{orig_file} do
49
+ include_examples 'plugin_tests'
50
+ let(:args) { [] }
51
+
52
+ end
53
+ EOS
54
+ File.write(test_file, contents)
55
+ end
56
+ end
57
+ end
@@ -68,28 +68,10 @@ module PuppetDebugger
68
68
  # @return [PuppetDebugger::InputResponders::InputResponderPlugin]
69
69
  def self.plugin_from_command(name)
70
70
  p = plugins.find {|p| p::COMMAND_WORDS.include?(name)}
71
- raise PuppetDebugger::Exception::InvalidCommand.new(message: "invalid command #{command}") unless p
71
+ raise PuppetDebugger::Exception::InvalidCommand.new(message: "invalid command #{name}") unless p
72
72
  p
73
73
  end
74
74
 
75
75
  end
76
76
  end
77
- end
78
-
79
- module Pluginator
80
- # a helper for handling name / file / class conversions
81
- module NameConverter
82
- private
83
- # full_name => class
84
- def name2class(name)
85
- klass = Kernel
86
- name.to_s.split(%r{/}).each do |part|
87
- klass = klass.const_get(
88
- part.capitalize.gsub(/[_-](.)/) { |match| match[1].upcase }
89
- )
90
- end
91
- klass
92
- end
93
-
94
- end
95
- end
77
+ end
@@ -79,7 +79,7 @@ module PuppetDebugger
79
79
  debugger.out_buffer.write('>> ')
80
80
  end
81
81
  rescue Puppet::ParseErrorWithIssue => e
82
- if multiline_input?(e)
82
+ if debugger.multiline_input?(e)
83
83
  full_buffer += "\n"
84
84
  next
85
85
  end
@@ -5,6 +5,26 @@ module PuppetDebugger
5
5
  COMMAND_WORDS = %w(set :set)
6
6
  SUMMARY = 'Set the a puppet debugger config'
7
7
  COMMAND_GROUP = :scope
8
+ KEYWORDS = %w(node loglevel)
9
+ LOGLEVELS = %w(debug info)
10
+
11
+ def self.command_completion(buffer_words)
12
+ next_word = buffer_words.shift
13
+ case next_word
14
+ when 'loglevel'
15
+ if buffer_words.count > 0
16
+ LOGLEVELS.grep(/^#{Regexp.escape(buffer_words.first)}/)
17
+ else
18
+ LOGLEVELS
19
+ end
20
+ when 'debug', 'info','node'
21
+ []
22
+ when nil
23
+ %w(node loglevel)
24
+ else
25
+ KEYWORDS.grep(/^#{Regexp.escape(next_word)}/)
26
+ end
27
+ end
8
28
 
9
29
  def run(args = [])
10
30
  handle_set(args)
@@ -29,12 +29,9 @@ module PuppetDebugger
29
29
  @source_file = options[:source_file] || nil
30
30
  @source_line_num = options[:source_line] || nil
31
31
  @in_buffer = options[:in_buffer] || $stdin
32
- comp = proc do |s|
33
- key_words.grep(/^#{Regexp.escape(s)}/)
34
- end
35
32
  Readline.completion_append_character = ''
36
33
  Readline.basic_word_break_characters = ' '
37
- Readline.completion_proc = comp
34
+ Readline.completion_proc = command_completion
38
35
  AwesomePrint.defaults = {
39
36
  html: @html_mode,
40
37
  sort_keys: true,
@@ -42,6 +39,24 @@ module PuppetDebugger
42
39
  }
43
40
  end
44
41
 
42
+ # @return [Proc] the proc used in the command completion for readline
43
+ # if a plugin keyword is found lets return keywords using the plugin's command completion
44
+ # otherwise return the default set of keywords and filter out based on input
45
+ def command_completion
46
+ proc do |input|
47
+ words = Readline.line_buffer.split(Readline.basic_word_break_characters)
48
+ first_word = words.shift
49
+ plugins = PuppetDebugger::InputResponders::Commands.plugins.find_all do |p|
50
+ p::COMMAND_WORDS.find { |word| word.start_with?(first_word)}
51
+ end
52
+ if plugins.count == 1 and /\A#{first_word}\s/.match(Readline.line_buffer)
53
+ plugins.first.command_completion(words)
54
+ else
55
+ key_words.grep(/^#{Regexp.escape(input)}/)
56
+ end
57
+ end
58
+ end
59
+
45
60
  def hooks
46
61
  @hooks ||= PuppetDebugger::Hooks.new
47
62
  end
@@ -12,22 +12,34 @@ module PuppetDebugger
12
12
  def_delegators :scope, :compiler, :catalog
13
13
  def_delegators :node, :facts
14
14
 
15
+ # @return [Array[String]] an array of words the user can call the command with
15
16
  def self.command_words
16
17
  self::COMMAND_WORDS
17
18
  end
18
19
 
20
+ # @return [String] a summary of the plugin
19
21
  def self.summary
20
22
  self::SUMMARY
21
23
  end
22
24
 
25
+ # @return [String] the name of the command group the plugin is in
23
26
  def self.command_group
24
27
  self::COMMAND_GROUP
25
28
  end
26
29
 
30
+ # @return [Hash] a has of all the details of the plugin
27
31
  def self.details
28
32
  { words: command_words, summary: summary, group: command_group }
29
33
  end
30
34
 
35
+ # @param buffer_words [Array[String]] a array of words the user has typed in
36
+ # @return Array[String] - an array of words that will help the user with word completion
37
+ # By default this returns an empty array, your plugin can chose to override this method in order to
38
+ # provide the user with a list of key words based on the user's input
39
+ def self.command_completion(buffer_words)
40
+ []
41
+ end
42
+
31
43
  # @param args [Array[String]] - an array of arguments to pass to the plugin command
32
44
  # @param debugger PuppetDebugger::Cli - an instance of the PuppetDebugger::Cli object
33
45
  # @return the output of the plugin command
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PuppetDebugger
4
- VERSION = '0.7.0'
4
+ VERSION = '0.8.0'
5
5
  end
@@ -32,7 +32,7 @@ Gem::Specification.new do |s|
32
32
  s.licenses = ["MIT"]
33
33
  s.rubygems_version = "2.4.5.1"
34
34
  s.summary = "A repl based debugger for the puppet language"
35
- s.add_runtime_dependency(%q<pluginator>, ["~> 1.4.1"])
35
+ s.add_runtime_dependency(%q<pluginator>, ["~> 1.5.0"])
36
36
  s.add_runtime_dependency(%q<puppet>, [">= 3.8"])
37
37
  s.add_runtime_dependency(%q<facterdb>, ["~> 0.3.1"])
38
38
  s.add_runtime_dependency(%q<awesome_print>, ["~> 1.7"])
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+ require 'puppet-debugger'
3
+ require 'puppet-debugger/plugin_test_helper'
4
+
5
+ describe :benchmark do
6
+ include_examples 'plugin_tests'
7
+ let(:args) { ["benchmark", "md5('12345')" ] }
8
+
9
+ describe 'mode' do
10
+ before(:each) do
11
+ debugger.handle_input('benchmark') # enable
12
+ end
13
+ it 'enable' do
14
+ debugger.handle_input("md5('12345')")
15
+ expect(output.string).to match(/Benchmark\ Mode\ On/)
16
+ expect(output.string).to match(/Time\ elapsed/)
17
+ end
18
+ it 'disable' do
19
+ debugger.handle_input('benchmark') # disable
20
+ expect(output.string).to match(/Benchmark\ Mode\ Off/)
21
+ end
22
+ end
23
+
24
+ describe 'onetime' do
25
+ it 'run' do
26
+ debugger.handle_input("benchmark md5('12345')")
27
+ expect(output.string).to_not match(/Benchmark\ Mode\ On/)
28
+ expect(output.string).to_not match(/Benchmark\ Mode\ Off/)
29
+ expect(output.string).to match(/Time\ elapsed/)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+ require 'puppet-debugger'
3
+ require 'puppet-debugger/plugin_test_helper'
4
+
5
+ describe :classes do
6
+ include_examples 'plugin_tests'
7
+ let(:args) { [] }
8
+
9
+ let(:input) do
10
+ 'classes'
11
+ end
12
+
13
+ it 'should be able to print classes' do
14
+ expect(plugin.run(args)).to match(/settings/)
15
+ end
16
+
17
+ it 'should be able to print classes with handle input' do
18
+ debugger_output = /settings/
19
+ debugger.handle_input(input)
20
+ expect(output.string).to match(debugger_output)
21
+ end
22
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+ require 'puppet-debugger'
3
+ require 'puppet-debugger/plugin_test_helper'
4
+
5
+ describe :classification do
6
+ include_examples 'plugin_tests'
7
+ let(:args) { [] }
8
+
9
+ it 'can process a file' do
10
+ expect(plugin.run(args)).to eq("[]")
11
+ end
12
+
13
+ it 'can process a file from handle input' do
14
+ debugger.handle_input('classification')
15
+ expect(output.string).to eq("[]\n")
16
+ end
17
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+ require 'puppet-debugger'
3
+ require 'puppet-debugger/plugin_test_helper'
4
+
5
+ describe :commands do
6
+ include_examples 'plugin_tests'
7
+ let(:args) { [] }
8
+
9
+ it do
10
+ expect(plugin.run(args)).to match(/environment/)
11
+ end
12
+
13
+ it 'run a plugin command' do
14
+ debugger.handle_input('help')
15
+ expect(output.string).to match(/Type "commands" for a list of debugger commands/)
16
+ end
17
+
18
+ it 'show error when command does not exist' do
19
+ debugger.handle_input('helpp')
20
+ expect(output.string).to match(/invalid command helpp/)
21
+ end
22
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+ require 'puppet-debugger'
3
+ require 'puppet-debugger/plugin_test_helper'
4
+
5
+ describe :datatypes do
6
+ include_examples 'plugin_tests'
7
+ let(:args) { [] }
8
+
9
+ it 'handle datatypes' do
10
+ output = plugin.run(args)
11
+ if Gem::Version.new(Puppet.version) < Gem::Version.new('4.5.0')
12
+ expect(output).to eq("[]")
13
+ else
14
+ expect(output).to match(/.*Array.*/)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+ require 'puppet-debugger'
3
+ require 'puppet-debugger/plugin_test_helper'
4
+
5
+ describe :environment do
6
+ include_examples 'plugin_tests'
7
+ let(:args) { [''] }
8
+
9
+ it 'can display itself' do
10
+ output = plugin.run(args)
11
+ expect(output).to eq("Puppet Environment: #{debugger.puppet_env_name}")
12
+ end
13
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+ require 'puppet-debugger'
3
+
4
+ describe :exit do
5
+ let(:args) { [] }
6
+
7
+ xit 'exits' do
8
+ expect{plugin.run(args)}.to eq('')
9
+ end
10
+
11
+ let(:plugin) do
12
+ instance = PuppetDebugger::InputResponders::Commands.plugin_from_command(subject.to_s).instance
13
+ instance.debugger = debugger
14
+ instance
15
+ end
16
+
17
+ let(:output) do
18
+ StringIO.new
19
+ end
20
+
21
+ let(:debugger) do
22
+ PuppetDebugger::Cli.new({ out_buffer: output }.merge(options))
23
+ end
24
+
25
+ let(:options) do
26
+ {}
27
+ end
28
+
29
+ it "commands contant is an array" do
30
+ expect(plugin.class::COMMAND_WORDS).to be_a(Array)
31
+ end
32
+
33
+ it "commands must contain at least one word" do
34
+ expect(plugin.class::COMMAND_WORDS.count).to be > 0
35
+ end
36
+
37
+ it "summary must be a string" do
38
+ expect(plugin.class::SUMMARY).to be_a(String)
39
+ end
40
+
41
+ it 'implements run' do
42
+ expect{plugin.run([])}.not_to raise_error(NotImplementedError)
43
+ end
44
+
45
+ it 'be looked up via any command words' do
46
+ plugin.class::COMMAND_WORDS.each do |word|
47
+ actual = PuppetDebugger::InputResponders::Commands.plugin_from_command(word.to_s).instance.class
48
+ expect(actual).to eq(plugin.class)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+ require 'puppet-debugger'
3
+ require 'puppet-debugger/plugin_test_helper'
4
+
5
+ describe :facterdb_filter do
6
+ include_examples 'plugin_tests'
7
+ let(:args) { [] }
8
+
9
+ it 'outputs filter' do
10
+ expect(plugin.run(args)).to match(/facterversion/)
11
+ end
12
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+ require 'puppet-debugger'
3
+ require 'puppet-debugger/plugin_test_helper'
4
+
5
+ describe :facts do
6
+ include_examples 'plugin_tests'
7
+ let(:args) { ['$::fqdn', 'facts'] }
8
+
9
+ it 'should be able to resolve fqdn' do
10
+ debugger_output = /foo\.example\.com/
11
+ output = plugin.run(args[0])
12
+ expect(output).to match(debugger_output)
13
+ end
14
+
15
+ it 'should be able to print facts' do
16
+ debugger_output = /kernel/
17
+ plugin.run(args[1])
18
+ expect(plugin.run(args[1])).to match(debugger_output)
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+ require 'puppet-debugger'
3
+ require 'puppet-debugger/plugin_test_helper'
4
+
5
+ describe :functions do
6
+ include_examples 'plugin_tests'
7
+ let(:input) do
8
+ "md5('hello')"
9
+ end
10
+ it 'execute md5' do
11
+ debugger_output = /5d41402abc4b2a76b9719d911017c592/
12
+ debugger.handle_input(input)
13
+ expect(output.string).to match(debugger_output)
14
+ end
15
+ it 'execute swapcase' do
16
+ debugger_output = /HELLO/
17
+ debugger.handle_input("swapcase('hello')")
18
+ expect(output.string).to match(debugger_output)
19
+ end
20
+ end
@@ -8,5 +8,4 @@ describe :krt do
8
8
  it 'works' do
9
9
  expect(plugin.run(args)).to match(/hostclasses/)
10
10
  end
11
-
12
- end
11
+ end
@@ -131,6 +131,20 @@ describe :play do
131
131
  expect(output.string).to include('"test"')
132
132
  end
133
133
  end
134
+ describe 'multiple lines puppet code' do
135
+ let(:input) do
136
+ <<-EOF
137
+ if $osfamily {
138
+ $var = '3'
139
+ }
140
+ $var
141
+ EOF
142
+ end
143
+ xit do
144
+ plugin.play_back_string(input)
145
+ expect(output.string).to include('"3"')
146
+ end
147
+ end
134
148
  end
135
149
 
136
150
  describe 'play' do
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+ require 'puppet-debugger'
3
+ require 'puppet-debugger/plugin_test_helper'
4
+
5
+ describe :reset do
6
+ include_examples 'plugin_tests'
7
+ let(:args) { [] }
8
+
9
+ it 'can process a file' do
10
+ debugger_output = /Puppet::Type::File/
11
+ debugger.handle_input("file{'/tmp/reset': ensure => present}")
12
+ expect(output.string).to match(debugger_output)
13
+ debugger.handle_input('reset')
14
+ expect(output.string).to match(debugger_output)
15
+ end
16
+
17
+ describe 'loglevel' do
18
+ it 'has not changed' do
19
+ debugger.handle_input(':set loglevel debug')
20
+ expect(Puppet::Util::Log.level).to eq(:debug)
21
+ expect(Puppet::Util::Log.destinations[:buffer].name).to eq(:buffer)
22
+ plugin.run('reset')
23
+ expect(Puppet::Util::Log.level).to eq(:debug)
24
+ expect(Puppet::Util::Log.destinations[:buffer].name).to eq(:buffer)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+ require 'puppet-debugger'
3
+ require 'puppet-debugger/plugin_test_helper'
4
+
5
+ describe :resources do
6
+ include_examples 'plugin_tests'
7
+ let(:args) { ["resources"] }
8
+
9
+ it 'should be able to print resources' do
10
+ debugger_output = /main/
11
+ expect(plugin.run(args)).to match(debugger_output)
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+ require 'puppet-debugger'
3
+ require 'puppet-debugger/plugin_test_helper'
4
+
5
+ describe 'set' do
6
+ include_examples 'plugin_tests'
7
+ let(:input) do
8
+ ':set loglevel debug'
9
+ end
10
+
11
+ it 'should set the loglevel' do
12
+ debugger_output = /loglevel debug is set/
13
+ debugger.handle_input(input)
14
+ expect(output.string).to match(debugger_output)
15
+ expect(Puppet::Util::Log.level).to eq(:debug)
16
+ expect(Puppet::Util::Log.destinations[:buffer].name).to eq(:buffer)
17
+ end
18
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+ require 'puppet-debugger'
3
+ require 'puppet-debugger/plugin_test_helper'
4
+
5
+ describe :types do
6
+ include_examples 'plugin_tests'
7
+ let(:args) { [] }
8
+
9
+ it 'runs' do
10
+ expect(plugin.run(args)).to match(/service/)
11
+ end
12
+
13
+ describe 'types' do
14
+ let(:input) do
15
+ 'types'
16
+ end
17
+ it 'runs' do
18
+ debugger.handle_input(input)
19
+ expect(output.string).to match(/service/)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+ require 'puppet-debugger'
3
+ require 'puppet-debugger/plugin_test_helper'
4
+ require 'pluginator'
5
+
6
+ describe :vars do
7
+ include_examples 'plugin_tests'
8
+ let(:args) { [] }
9
+
10
+ it 'display facts variable' do
11
+ debugger_output = /facts/
12
+ output = plugin.run(args)
13
+ expect(output).to match(debugger_output)
14
+ end
15
+ it 'display server facts variable' do
16
+ debugger_output = /server_facts/
17
+ expect(plugin.run(args)).to match(debugger_output) if Puppet.version.to_f >= 4.1
18
+ end
19
+ it 'display serverversion variable' do
20
+ debugger_output = /serverversion/
21
+ expect(plugin.run(args)).to match(debugger_output) if Puppet.version.to_f >= 4.1
22
+ end
23
+ it 'display local variable' do
24
+ debugger.handle_input("$var1 = 'value1'")
25
+ expect(plugin.run(args)).to match(/value1/)
26
+ end
27
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+ require 'puppet-debugger'
3
+ require 'puppet-debugger/plugin_test_helper'
4
+
5
+ describe :whereami do
6
+ include_examples 'plugin_tests'
7
+ let(:input) do
8
+ File.expand_path File.join(fixtures_dir, 'sample_start_debugger.pp')
9
+ end
10
+ let(:options) do
11
+ {
12
+ source_file: input,
13
+ source_line: 10
14
+ }
15
+ end
16
+
17
+ before(:each) do
18
+ debugger.handle_input('whereami')
19
+ end
20
+
21
+ it 'runs' do
22
+ expect(output.string).to match(/\s+5/)
23
+ end
24
+
25
+ it 'contains marker' do
26
+ expect(output.string).to match(/\s+=>\s10/)
27
+ end
28
+ end
@@ -113,28 +113,7 @@ describe 'PuppetDebugger' do
113
113
  end
114
114
  end
115
115
 
116
- describe 'types' do
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', type_function: true do
127
- let(:input) do
128
- 'type([1,2,3,4])'
129
- end
130
- it 'shows type' do
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
135
- end
136
- end
137
- end
116
+
138
117
 
139
118
 
140
119
 
@@ -144,40 +123,7 @@ describe 'PuppetDebugger' do
144
123
  end
145
124
  end
146
125
 
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
126
+
181
127
 
182
128
  describe 'empty' do
183
129
  let(:input) do
@@ -232,43 +178,6 @@ describe 'PuppetDebugger' do
232
178
  end
233
179
  end
234
180
 
235
- describe 'classification' do
236
- let(:input) do
237
- 'classification'
238
- end
239
-
240
- it 'can process a file' do
241
- debugger.handle_input(input)
242
- expect(output.string).to eq("\n[]\n")
243
- end
244
- end
245
-
246
- describe 'reset' do
247
- let(:input) do
248
- "file{'/tmp/reset': ensure => present}"
249
- end
250
-
251
- it 'can process a file' do
252
- debugger_output = /Puppet::Type::File/
253
- debugger.handle_input(input)
254
- expect(output.string).to match(debugger_output)
255
- debugger.handle_input('reset')
256
- debugger.handle_input(input)
257
- expect(output.string).to match(debugger_output)
258
- end
259
-
260
- describe 'loglevel' do
261
- it 'has not changed' do
262
- debugger.handle_input(':set loglevel debug')
263
- expect(Puppet::Util::Log.level).to eq(:debug)
264
- expect(Puppet::Util::Log.destinations[:buffer].name).to eq(:buffer)
265
- debugger.handle_input('reset')
266
- expect(Puppet::Util::Log.level).to eq(:debug)
267
- expect(Puppet::Util::Log.destinations[:buffer].name).to eq(:buffer)
268
- end
269
- end
270
- end
271
-
272
181
  describe 'map block' do
273
182
  let(:input) do
274
183
  "['/tmp/test3', '/tmp/test4'].map |String $path| { file{$path: ensure => present} }"
@@ -291,165 +200,27 @@ describe 'PuppetDebugger' do
291
200
  end
292
201
  end
293
202
 
294
- describe 'facts' do
295
- let(:input) do
296
- '$::fqdn'
297
- end
298
- it 'should be able to resolve fqdn' do
299
- debugger_output = /foo\.example\.com/
300
- debugger.handle_input(input)
301
- expect(output.string).to match(debugger_output)
302
- end
303
- end
304
-
305
- describe 'print facts' do
203
+ describe 'string' do
306
204
  let(:input) do
307
- 'facts'
205
+ 'String'
308
206
  end
309
- it 'should be able to print facts' do
310
- debugger_output = /kernel/
207
+ it 'shows type' do
311
208
  debugger.handle_input(input)
312
- expect(output.string).to match(debugger_output)
209
+ expect(output.string).to eq("\n => String\n")
313
210
  end
314
211
  end
315
-
316
- describe 'print resources' do
212
+ describe 'Array', type_function: true do
317
213
  let(:input) do
318
- 'resources'
319
- end
320
- it 'should be able to print resources' do
321
- debugger_output = /main/
322
- debugger.handle_input(input)
323
- expect(output.string).to match(debugger_output)
214
+ 'type([1,2,3,4])'
324
215
  end
325
- end
326
-
327
- describe 'print class' do
328
- let(:input) do
329
- "Class['settings']"
330
- end
331
- it 'should be able to print classes' do
332
- debugger_output = /Settings/
333
- debugger.handle_input(input)
334
- expect(output.string).to match(debugger_output)
335
- end
336
- end
337
-
338
- describe 'print classes' do
339
- let(:input) do
340
- 'resources'
341
- end
342
- it 'should be able to print classes' do
343
- debugger_output = /Settings/
344
- debugger.handle_input(input)
345
- expect(output.string).to match(debugger_output)
346
- end
347
- end
348
-
349
- describe 'set' do
350
- let(:input) do
351
- ':set loglevel debug'
352
- end
353
- it 'should set the loglevel' do
354
- debugger_output = /loglevel debug is set/
355
- debugger.handle_input(input)
356
- expect(output.string).to match(debugger_output)
357
- expect(Puppet::Util::Log.level).to eq(:debug)
358
- expect(Puppet::Util::Log.destinations[:buffer].name).to eq(:buffer)
359
- end
360
- end
361
-
362
- describe 'vars' do
363
- let(:input) do
364
- 'vars'
365
- end
366
- it 'display facts variable' do
367
- debugger_output = /facts/
368
- debugger.handle_input(input)
369
- expect(output.string).to match(debugger_output)
370
- end
371
- it 'display server facts variable' do
372
- debugger_output = /server_facts/
373
- debugger.handle_input(input)
374
- expect(output.string).to match(debugger_output) if Puppet.version.to_f >= 4.1
375
- end
376
- it 'display serverversion variable' do
377
- debugger_output = /serverversion/
378
- debugger.handle_input(input)
379
- expect(output.string).to match(debugger_output) if Puppet.version.to_f >= 4.1
380
- end
381
- it 'display local variable' do
382
- debugger.handle_input("$var1 = 'value1'")
383
- expect(output.string).to match(/value1/)
384
- debugger.handle_input('$var1')
385
- expect(output.string).to match(/value1/)
386
- end
387
- end
388
-
389
- describe 'execute functions' do
390
- let(:input) do
391
- "md5('hello')"
392
- end
393
- it 'execute md5' do
394
- debugger_output = /5d41402abc4b2a76b9719d911017c592/
395
- debugger.handle_input(input)
396
- expect(output.string).to match(debugger_output)
397
- end
398
- it 'execute swapcase' do
399
- debugger_output = /HELLO/
400
- debugger.handle_input("swapcase('hello')")
401
- expect(output.string).to match(debugger_output)
402
- end
403
- end
404
-
405
- describe 'datatypes' do
406
- let(:input) do
407
- 'datatypes'
408
- end
409
- it 'handle datatypes' do
410
- debugger.handle_input(input)
411
- if Gem::Version.new(Puppet.version) < Gem::Version.new('4.5.0')
412
- expect(output.string).to eq("\n[]\n")
413
- else
414
- expect(output.string).to match(/.*Array.*/)
216
+ it 'shows type' do
217
+ if Gem::Version.new(Puppet.version) > Gem::Version.new('4.4')
218
+ debugger.handle_input(input)
219
+ expect(output.string).to eq("\n => Tuple[Integer[1, 1], Integer[2, 2], Integer[3, 3], Integer[4, 4]]\n") if supports_type_function?
415
220
  end
416
221
  end
417
222
  end
418
223
 
419
- describe 'whereami' do
420
- let(:input) do
421
- File.expand_path File.join(fixtures_dir, 'sample_start_debugger.pp')
422
- end
423
- let(:options) do
424
- {
425
- source_file: input,
426
- source_line: 10
427
- }
428
- end
429
-
430
- before(:each) do
431
- debugger.handle_input('whereami')
432
- end
433
-
434
- it 'runs' do
435
- expect(output.string).to match(/\s+5/)
436
- end
437
-
438
- it 'contains marker' do
439
- expect(output.string).to match(/\s+=>\s10/)
440
- end
441
- end
442
-
443
- describe 'types' do
444
- let(:input) do
445
- 'types'
446
- end
447
- it 'runs' do
448
- debugger.handle_input(input)
449
- expect(output.string).to match(/service/)
450
- end
451
- end
452
-
453
224
  describe 'error message' do
454
225
  let(:input) do
455
226
  "file{'/tmp/test': ensure => present, contact => 'blah'}"
@@ -468,33 +239,4 @@ describe 'PuppetDebugger' do
468
239
  end
469
240
  end
470
241
  end
471
-
472
- describe 'benchmark' do
473
- let(:input) do
474
- "benchmark md5('12345')"
475
- end
476
- describe 'mode' do
477
- before(:each) do
478
- debugger.handle_input('benchmark') # enable
479
- end
480
- it 'enable' do
481
- debugger.handle_input("md5('12345')")
482
- expect(output.string).to match(/Benchmark\ Mode\ On/)
483
- expect(output.string).to match(/Time\ elapsed/)
484
- end
485
- it 'disable' do
486
- debugger.handle_input('benchmark') # disable
487
- expect(output.string).to match(/Benchmark\ Mode\ Off/)
488
- end
489
- end
490
-
491
- describe 'onetime' do
492
- it 'run' do
493
- debugger.handle_input("benchmark md5('12345')")
494
- expect(output.string).to_not match(/Benchmark\ Mode\ On/)
495
- expect(output.string).to_not match(/Benchmark\ Mode\ Off/)
496
- expect(output.string).to match(/Time\ elapsed/)
497
- end
498
- end
499
- end
500
242
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-debugger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Corey Osman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-11 00:00:00.000000000 Z
11
+ date: 2017-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pluginator
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.4.1
19
+ version: 1.5.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.4.1
26
+ version: 1.5.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: puppet
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -174,9 +174,25 @@ files:
174
174
  - spec/fixtures/sample_start_debugger.pp
175
175
  - spec/hooks_spec.rb
176
176
  - spec/input_responder_plugin_spec.rb
177
+ - spec/input_responders/benchmark_spec.rb
178
+ - spec/input_responders/classes_spec.rb
179
+ - spec/input_responders/classification_spec.rb
180
+ - spec/input_responders/commands_spec.rb
181
+ - spec/input_responders/datatypes_spec.rb
182
+ - spec/input_responders/environment_spec.rb
183
+ - spec/input_responders/exit_spec.rb
184
+ - spec/input_responders/facterdb_filter_spec.rb
185
+ - spec/input_responders/facts_spec.rb
186
+ - spec/input_responders/functions_spec.rb
177
187
  - spec/input_responders/help_spec.rb
178
188
  - spec/input_responders/krt_spec.rb
179
189
  - spec/input_responders/play_spec.rb
190
+ - spec/input_responders/reset_spec.rb
191
+ - spec/input_responders/resources_spec.rb
192
+ - spec/input_responders/set_spec.rb
193
+ - spec/input_responders/types_spec.rb
194
+ - spec/input_responders/vars_spec.rb
195
+ - spec/input_responders/whereami_spec.rb
180
196
  - spec/pdb_spec.rb
181
197
  - spec/puppet/application/debugger_spec.rb
182
198
  - spec/puppet_debugger_spec.rb