puppet-debugger 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
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,190 @@
1
+ require 'spec_helper'
2
+ require 'tempfile'
3
+
4
+ describe 'support' do
5
+
6
+ let(:output) do
7
+ StringIO.new('', 'w')
8
+ end
9
+
10
+ let(:debugger) do
11
+ PuppetDebugger::Cli.new(:out_buffer => output)
12
+ end
13
+
14
+ let(:scope) do
15
+ debugger.scope
16
+ end
17
+
18
+ describe 'play' do
19
+ before(:each) do
20
+ allow(debugger).to receive(:fetch_url_data).with(file_url + ".txt").and_return(File.read(fixtures_file))
21
+ end
22
+
23
+ let(:fixtures_file) do
24
+ File.join(fixtures_dir, 'sample_manifest.pp')
25
+ end
26
+
27
+ let(:file_url) do
28
+ 'https://gist.github.com/logicminds/f9b1ac65a3a440d562b0'
29
+ end
30
+ let(:input) do
31
+ "play #{file_url}"
32
+ end
33
+
34
+ it do
35
+ debugger.handle_input(input)
36
+ expect(output.string).to match(/test/)
37
+ expect(output.string).to match(/Puppet::Type::File/)
38
+ end
39
+ end
40
+
41
+ let(:puppet_version) do
42
+ debugger.mod_finder.match(debugger.puppet_lib_dir)[1]
43
+ end
44
+
45
+ let(:manifest_file) do
46
+ file = File.open('/tmp/debugger_puppet_manifest.pp', 'w') do |f|
47
+ f.write(manifest_code)
48
+ end
49
+ '/tmp/debugger_puppet_manifest.pp'
50
+ end
51
+
52
+ let(:manifest_code) do
53
+ <<-EOF
54
+ file{'/tmp/test.txt': ensure => absent } \n
55
+ notify{'hello_there':} \n
56
+ service{'httpd': ensure => running}\n
57
+
58
+ EOF
59
+ end
60
+
61
+ after(:each) do
62
+ #manifest_file.close
63
+ end
64
+
65
+ context '#function_map' do
66
+
67
+ it 'should list functions' do
68
+ func = debugger.function_map["#{puppet_version}::hiera"]
69
+ expect(debugger.function_map).to be_instance_of(Hash)
70
+ expect(func).to eq({:name => 'hiera', :parent => puppet_version})
71
+ end
72
+
73
+ end
74
+
75
+ it 'should return a puppet version' do
76
+ expect(puppet_version).to match(/puppet-\d\.\d.\d/)
77
+ end
78
+
79
+ it 'should return lib dirs' do
80
+ expect(debugger.lib_dirs.count).to be >= 1
81
+ end
82
+
83
+ it 'should return module dirs' do
84
+ expect(debugger.modules_paths.count).to be >= 1
85
+ end
86
+
87
+ it 'should return a list of default facts' do
88
+ expect(debugger.default_facts.values).to be_instance_of(Hash)
89
+ expect(debugger.default_facts.values['fqdn']).to eq('foo.example.com')
90
+ end
91
+
92
+ it 'should return a list of facts' do
93
+ expect(debugger.node.facts.values).to be_instance_of(Hash)
94
+ expect(debugger.node.facts.values['fqdn']).to eq('foo.example.com')
95
+ end
96
+
97
+ describe 'convert url' do
98
+
99
+ describe 'unsupported' do
100
+ let(:url) { 'https://bitbuck.com/master/lib/log_helper.rb'}
101
+ let(:converted) { 'https://bitbuck.com/master/lib/log_helper.rb' }
102
+ it do
103
+ expect(debugger.convert_to_text(url)).to eq(converted)
104
+ end
105
+ end
106
+ describe 'gitlab' do
107
+ describe 'blob' do
108
+ let(:url) { 'https://gitlab.com/nwops/pdebugger-web/blob/master/lib/log_helper.rb'}
109
+ let(:converted) { 'https://gitlab.com/nwops/pdebugger-web/raw/master/lib/log_helper.rb' }
110
+ it do
111
+ expect(debugger.convert_to_text(url)).to eq(converted)
112
+ end
113
+ end
114
+
115
+ describe 'raw' do
116
+ let(:url) { 'https://gitlab.com/nwops/pdebugger-web/raw/master/lib/log_helper.rb'}
117
+ let(:converted) { 'https://gitlab.com/nwops/pdebugger-web/raw/master/lib/log_helper.rb' }
118
+ it do
119
+ expect(debugger.convert_to_text(url)).to eq(converted)
120
+ end
121
+ end
122
+
123
+ describe 'snippet' do
124
+
125
+ describe 'not raw' do
126
+ let(:url) { 'https://gitlab.com/snippets/19471'}
127
+ let(:converted) { 'https://gitlab.com/snippets/19471/raw'}
128
+ it do
129
+ expect(debugger.convert_to_text(url)).to eq(converted)
130
+ end
131
+ end
132
+
133
+ describe 'raw' do
134
+ let(:url) { 'https://gitlab.com/snippets/19471/raw'}
135
+ let(:converted) { 'https://gitlab.com/snippets/19471/raw'}
136
+ it do
137
+ expect(debugger.convert_to_text(url)).to eq(converted)
138
+ end
139
+ end
140
+ end
141
+ end
142
+ describe 'github' do
143
+ describe 'raw' do
144
+ let(:url) { 'https://gist.githubusercontent.com/logicminds/f9b1ac65a3a440d562b0/raw'}
145
+ let(:converted) { 'https://gist.githubusercontent.com/logicminds/f9b1ac65a3a440d562b0/raw' }
146
+ it do
147
+ expect(debugger.convert_to_text(url)).to eq(converted)
148
+ end
149
+ end
150
+ describe 'raw' do
151
+ let(:url) { 'https://gist.githubusercontent.com/logicminds/f9b1ac65a3a440d562b0'}
152
+ let(:converted) { 'https://gist.githubusercontent.com/logicminds/f9b1ac65a3a440d562b0.txt' }
153
+ it do
154
+ expect(debugger.convert_to_text(url)).to eq(converted)
155
+ end
156
+ end
157
+ describe 'raw gist' do
158
+ let(:url) {'https://gist.githubusercontent.com/logicminds/f9b1ac65a3a440d562b0/raw/c8f6be52da5b2b0eeaabb9aa75832b75793d35d1/controls.pp'}
159
+ let(:converted) {'https://gist.githubusercontent.com/logicminds/f9b1ac65a3a440d562b0/raw/c8f6be52da5b2b0eeaabb9aa75832b75793d35d1/controls.pp'}
160
+ it do
161
+ expect(debugger.convert_to_text(url)).to eq(converted)
162
+ end
163
+ end
164
+ describe 'raw non gist' do
165
+ let(:url) { 'https://raw.githubusercontent.com/nwops/puppet-debugger/master/lib/puppet-debugger.rb'}
166
+ let(:converted) { 'https://raw.githubusercontent.com/nwops/puppet-debugger/master/lib/puppet-debugger.rb' }
167
+ it do
168
+ expect(debugger.convert_to_text(url)).to eq(converted)
169
+ end
170
+
171
+ end
172
+
173
+ describe 'blob' do
174
+ let(:url) { 'https://github.com/nwops/puppet-debugger/blob/master/lib/puppet-debugger.rb'}
175
+ let(:converted) { 'https://github.com/nwops/puppet-debugger/raw/master/lib/puppet-debugger.rb' }
176
+ it do
177
+ expect(debugger.convert_to_text(url)).to eq(converted)
178
+ end
179
+ end
180
+
181
+ describe 'gist' do
182
+ let(:url) { 'https://gist.github.com/logicminds/f9b1ac65a3a440d562b0'}
183
+ let(:converted) { 'https://gist.github.com/logicminds/f9b1ac65a3a440d562b0.txt' }
184
+ it do
185
+ expect(debugger.convert_to_text(url)).to eq(converted)
186
+ end
187
+ end
188
+ end
189
+ end
190
+ end
data/test_matrix.rb ADDED
@@ -0,0 +1,42 @@
1
+ require 'yaml'
2
+ require 'fileutils'
3
+ @threads = {}
4
+
5
+ def run_container(image, puppet_version)
6
+ pversion = puppet_version.match(/([\d\.]+)/)[0]
7
+ ruby_version = image.split(':').last
8
+ dir = File.join('.','local_test_results', pversion, ruby_version)
9
+ real_dir = File.expand_path(dir)
10
+ FileUtils.rm_rf(real_dir)
11
+ FileUtils.mkdir_p(real_dir)
12
+ cmd = "docker run -e OUT_DIR='#{dir}' -e RUBY_VERSION='#{ruby_version}' -e PUPPET_GEM_VERSION='#{puppet_version}' --rm -ti -v ${PWD}:/module --workdir /module #{image} /bin/bash run_container_test.sh"
13
+ File.write(File.join(real_dir, 'command.txt'), cmd)
14
+ output = `#{cmd}`
15
+ if $?.success?
16
+ File.write(File.join(dir, 'success.txt'), output)
17
+ else
18
+ File.write(File.join(dir, 'error.txt'), output)
19
+ end
20
+ end
21
+
22
+ def ci_data
23
+ @ci_data ||= YAML.load_file(File.expand_path('.gitlab-ci.yml'))
24
+ end
25
+
26
+ def matrix
27
+ unless @matrix
28
+ @matrix = {}
29
+ ci_data.each do |id, data|
30
+ @matrix[id] = data if id =~ /^puppet/
31
+ end
32
+ end
33
+ @matrix
34
+ end
35
+
36
+ matrix.each do |id, item|
37
+ @threads[id] = Thread.new do
38
+ run_container(item['image'], item['variables']['PUPPET_GEM_VERSION'])
39
+ end
40
+ end
41
+
42
+ @threads.each {|id, thr| thr.join } # wait on thread to finish
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: puppet-debugger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ platform: ruby
6
+ authors:
7
+ - Corey Osman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: puppet
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: facterdb
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.3'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: awesome_print
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rdoc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.12'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.12'
69
+ description: A interactive command line tool for evaluating the puppet language
70
+ email: corey@nwops.io
71
+ executables:
72
+ - pdb
73
+ extensions: []
74
+ extra_rdoc_files:
75
+ - CHANGELOG.md
76
+ - LICENSE.txt
77
+ - README.md
78
+ files:
79
+ - ".document"
80
+ - ".gitignore"
81
+ - ".gitlab-ci.yml"
82
+ - ".rspec"
83
+ - CHANGELOG.md
84
+ - Gemfile
85
+ - Gemfile.lock
86
+ - LICENSE.txt
87
+ - README.md
88
+ - Rakefile
89
+ - bin/pdb
90
+ - lib/awesome_print/ext/awesome_puppet.rb
91
+ - lib/puppet-debugger.rb
92
+ - lib/puppet-debugger/cli.rb
93
+ - lib/puppet-debugger/code/code_file.rb
94
+ - lib/puppet-debugger/code/code_range.rb
95
+ - lib/puppet-debugger/code/loc.rb
96
+ - lib/puppet-debugger/debugger_code.rb
97
+ - lib/puppet-debugger/support.rb
98
+ - lib/puppet-debugger/support/compiler.rb
99
+ - lib/puppet-debugger/support/environment.rb
100
+ - lib/puppet-debugger/support/errors.rb
101
+ - lib/puppet-debugger/support/facts.rb
102
+ - lib/puppet-debugger/support/functions.rb
103
+ - lib/puppet-debugger/support/input_responders.rb
104
+ - lib/puppet-debugger/support/node.rb
105
+ - lib/puppet-debugger/support/play.rb
106
+ - lib/puppet-debugger/support/scope.rb
107
+ - lib/trollop.rb
108
+ - lib/version.rb
109
+ - puppet-debugger.gemspec
110
+ - run_container_test.sh
111
+ - spec/facts_spec.rb
112
+ - spec/fixtures/environments/production/manifests/site.pp
113
+ - spec/fixtures/invalid_node_obj.yaml
114
+ - spec/fixtures/node_obj.yaml
115
+ - spec/fixtures/sample_manifest.pp
116
+ - spec/fixtures/sample_start_debugger.pp
117
+ - spec/pdb_spec.rb
118
+ - spec/puppet-debugger_spec.rb
119
+ - spec/remote_node_spec.rb
120
+ - spec/spec_helper.rb
121
+ - spec/support_spec.rb
122
+ - test_matrix.rb
123
+ homepage: http://github.com/nwops/puppet-debugger
124
+ licenses:
125
+ - MIT
126
+ metadata:
127
+ allowed_push_host: https://rubygems.org
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.6.8
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: A repl for the puppet language
148
+ test_files: []