puppet-retrospec 0.11.0 → 0.12.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 (71) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +17 -0
  3. data/CHANGELOG.md +11 -0
  4. data/DEVELOPMENT.md +3 -0
  5. data/Gemfile +10 -9
  6. data/Gemfile.lock +2 -0
  7. data/README.md +211 -273
  8. data/Rakefile +8 -8
  9. data/VERSION +1 -1
  10. data/lib/retrospec-puppet.rb +3 -3
  11. data/lib/retrospec/plugins/v1/plugin/conditional.rb +5 -6
  12. data/lib/retrospec/plugins/v1/plugin/exceptions.rb +17 -0
  13. data/lib/retrospec/plugins/v1/plugin/generators.rb +7 -0
  14. data/lib/retrospec/plugins/v1/plugin/generators/fact_generator.rb +18 -10
  15. data/lib/retrospec/plugins/v1/plugin/generators/function_generator.rb +187 -0
  16. data/lib/retrospec/plugins/v1/plugin/generators/module_generator.rb +25 -26
  17. data/lib/retrospec/plugins/v1/plugin/generators/{facter.rb → parsers/facter.rb} +28 -35
  18. data/lib/retrospec/plugins/v1/plugin/generators/parsers/function.rb +91 -0
  19. data/lib/retrospec/plugins/v1/plugin/generators/parsers/type.rb +79 -0
  20. data/lib/retrospec/plugins/v1/plugin/generators/provider_generator.rb +107 -0
  21. data/lib/retrospec/plugins/v1/plugin/generators/schema_generator.rb +221 -0
  22. data/lib/retrospec/plugins/v1/plugin/generators/type_generator.rb +118 -0
  23. data/lib/retrospec/plugins/v1/plugin/helpers.rb +3 -7
  24. data/lib/retrospec/plugins/v1/plugin/puppet.rb +141 -60
  25. data/lib/retrospec/plugins/v1/plugin/puppet_module.rb +29 -26
  26. data/lib/retrospec/plugins/v1/plugin/resource.rb +6 -7
  27. data/lib/retrospec/plugins/v1/plugin/spec_object.rb +5 -8
  28. data/lib/retrospec/plugins/v1/plugin/template_helpers.rb +9 -10
  29. data/lib/retrospec/plugins/v1/plugin/templates/clone-hook +15 -8
  30. data/lib/retrospec/plugins/v1/plugin/type_code.rb +4 -4
  31. data/lib/retrospec/plugins/v1/plugin/variable_store.rb +26 -30
  32. data/lib/retrospec/plugins/v1/plugin/version.rb +1 -1
  33. data/puppet-retrospec.gemspec +43 -4
  34. data/spec/fixtures/facts/oracle_controls.rb +38 -0
  35. data/spec/fixtures/fixture_modules/required_parameters/manifests/init.pp +8 -0
  36. data/spec/fixtures/fixture_modules/sample_module/lib/facter/fix_installed.rb +11 -0
  37. data/spec/fixtures/fixture_modules/sample_module/lib/puppet/functions/awesome_parser.rb +13 -0
  38. data/spec/fixtures/fixture_modules/sample_module/lib/puppet/functions/reduce.rb +31 -0
  39. data/spec/fixtures/fixture_modules/sample_module/lib/puppet/parser/functions/bad_sha1.rb +6 -0
  40. data/spec/fixtures/fixture_modules/sample_module/lib/puppet/parser/functions/defined.rb +94 -0
  41. data/spec/fixtures/fixture_modules/sample_module/lib/puppet/parser/functions/sha1.rb +6 -0
  42. data/spec/fixtures/fixture_modules/sample_module/spec/unit/facter/fix_installed_spec.rb +21 -0
  43. data/spec/fixtures/modules/tomcat/files/.gitkeep +0 -0
  44. data/spec/fixtures/modules/tomcat/templates/.gitkeep +0 -0
  45. data/spec/fixtures/modules/tomcat/tests/.gitkeep +0 -0
  46. data/spec/fixtures/providers/bmc/ipmitool.rb +188 -0
  47. data/spec/fixtures/providers/bmcuser/ipmitool.rb +140 -0
  48. data/spec/fixtures/types/bmc.rb +102 -0
  49. data/spec/fixtures/types/bmcuser.rb +46 -0
  50. data/spec/fixtures/types/db_opatch.rb +93 -0
  51. data/spec/integration/retrospec_spec.rb +1 -3
  52. data/spec/spec_helper.rb +33 -6
  53. data/spec/unit/conditional_spec.rb +12 -15
  54. data/spec/unit/generators/fact_generater_spec.rb +49 -17
  55. data/spec/unit/generators/function_generator_spec.rb +301 -0
  56. data/spec/unit/generators/function_spec.rb +67 -0
  57. data/spec/unit/generators/parsers/fact_spec.rb +62 -0
  58. data/spec/unit/generators/parsers/provider_spec.rb +44 -0
  59. data/spec/unit/generators/parsers/type_spec.rb +93 -0
  60. data/spec/unit/generators/provider_generator_spec.rb +120 -0
  61. data/spec/unit/generators/schema_generator_spec.rb +122 -0
  62. data/spec/unit/generators/type_generator_spec.rb +173 -0
  63. data/spec/unit/module_spec.rb +7 -10
  64. data/spec/unit/plugin_spec.rb +213 -15
  65. data/spec/unit/puppet-retrospec_spec.rb +81 -100
  66. data/spec/unit/resource_spec.rb +16 -17
  67. data/spec/unit/spec_object_spec.rb +46 -0
  68. data/spec/unit/type_code_spec.rb +9 -11
  69. data/spec/unit/variable_store_spec.rb +41 -43
  70. metadata +54 -4
  71. data/spec/unit/generators/fact_spec.rb +0 -58
@@ -0,0 +1,173 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'type generator' do
4
+ before :each do
5
+ FileUtils.rm_rf(type_spec_dir)
6
+ end
7
+
8
+ after :each do
9
+ FileUtils.rm_rf(File.dirname(File.dirname(generator.type_name_path))) # ensure the file does not exist
10
+ FileUtils.rm_rf(File.dirname(generator.type_spec_dir))
11
+ end
12
+
13
+ let(:type_name) do
14
+ 'vhost'
15
+ end
16
+
17
+ let(:type_spec_dir) do
18
+ File.join(module_path, 'spec', 'unit', 'puppet', 'type')
19
+ end
20
+
21
+ let(:provider_dir) do
22
+ File.join(module_path, 'lib', 'puppet', 'provider')
23
+ end
24
+
25
+ let(:type_dir) do
26
+ File.join(module_path, 'lib', 'puppet', 'type')
27
+ end
28
+
29
+ let(:provider_spec_dir) do
30
+ File.join(module_path, 'spec', 'unit', 'puppet', 'provider')
31
+ end
32
+
33
+ let(:module_path) do
34
+ File.join(fixture_modules_path, 'tomcat')
35
+ end
36
+
37
+ let(:context) do
38
+ { :module_path => module_path, :template_dir => retrospec_templates_path}
39
+ end
40
+
41
+ let(:args) do
42
+ ['-p', 'param_one', 'param_two','-a', 'config1',
43
+ 'config2', '-n', type_name]
44
+ end
45
+
46
+ let(:cli_opts) do
47
+ Retrospec::Puppet::Generators::TypeGenerator.run_cli(context, args)
48
+ end
49
+
50
+ let(:generator) do
51
+ Retrospec::Puppet::Generators::TypeGenerator.new(module_path, cli_opts)
52
+ end
53
+
54
+ it 'returns type dir' do
55
+ expect(generator.type_dir).to eq(type_dir)
56
+ end
57
+
58
+ it 'returns module path' do
59
+ expect(generator.type_spec_dir).to eq(type_spec_dir)
60
+ end
61
+
62
+ it 'can return type name' do
63
+ expect(generator.type_name).to eq('vhost')
64
+ end
65
+
66
+ it 'can generate a type file' do
67
+ expect(generator.generate_type_files).to eq('/Users/cosman/github/puppet-retrospec/spec/fixtures/modules/tomcat/lib/puppet/type/vhost.rb')
68
+ expect(File.exist?(File.join(generator.type_dir, "#{generator.type_name}.rb")))
69
+ end
70
+
71
+ it 'can generate a spec file' do
72
+ allow(generator).to receive(:type_dir).and_return(fixtures_type_path)
73
+ allow(generator).to receive(:type_name_path).and_return(File.join(type_dir, "#{generator.type_name}.rb"))
74
+ files = [File.join(type_spec_dir, 'bmc_spec.rb'),
75
+ File.join(type_spec_dir, 'bmcuser_spec.rb'),
76
+ File.join(type_spec_dir, 'db_opatch_spec.rb')]
77
+ expect(generator.generate_type_spec_files).to eq(files)
78
+ end
79
+
80
+ describe 'cli' do
81
+ let(:context) do
82
+ { :module_path => module_path, :template_dir => File.expand_path(File.join(ENV['HOME'], '.retrospec', 'repos', 'retrospec-puppet-templates')) }
83
+ end
84
+
85
+ let(:type_name) do
86
+ 'vhost'
87
+ end
88
+
89
+ let(:args) do
90
+ ['-p', 'param_one', 'param_two','-a', 'prop_one',
91
+ 'prop_two', '-n', type_name]
92
+ end
93
+
94
+ let(:cli_opts) do
95
+ cli_opts = Retrospec::Puppet::Generators::TypeGenerator.run_cli(context, args)
96
+ end
97
+
98
+ let(:generator) do
99
+ Retrospec::Puppet::Generators::TypeGenerator.new(cli_opts[:module_path], cli_opts)
100
+ end
101
+
102
+ after :each do
103
+ FileUtils.rm_rf(File.dirname(File.dirname(generator.type_name_path))) # ensure the file does not exist
104
+ FileUtils.rm_rf(File.dirname(generator.type_spec_dir))
105
+ end
106
+
107
+ it 'can run the cli options' do
108
+ # specify the parameters
109
+ expect(cli_opts).to be_an_instance_of Hash
110
+ expect(cli_opts[:properties]).to eq(%w(prop_one prop_two))
111
+ expect(cli_opts[:parameters]).to eq(%w(param_one param_two))
112
+ expect(cli_opts[:name]).to eq('vhost')
113
+ end
114
+
115
+ it 'generate type file with correct number of properties' do
116
+ file = generator.generate_type_files
117
+ require file
118
+ t = Puppet::Type.type(:vhost)
119
+ expect(t.properties.count). to eq(3)
120
+ end
121
+
122
+ context 'parameters' do
123
+ let(:args) do
124
+ ['-p', 'param_one', 'param_two','-a', 'prop_one',
125
+ 'prop_two', '-n', 'vhost']
126
+ end
127
+ it 'generate type file with correct number of parameters' do
128
+ file = generator.generate_type_files
129
+ require file
130
+ t = Puppet::Type.type(:vhost)
131
+ expect(t.parameters.count). to eq(2)
132
+ end
133
+ end
134
+
135
+ context 'providers' do
136
+ let(:args) do
137
+ ['-p', 'param_one', 'param_two','-a', 'prop_one',
138
+ 'prop_two', '-n', type_name, '--providers', 'default1', 'default2']
139
+ end
140
+
141
+ it 'generate type' do
142
+ file = generator.generate_type_files
143
+ require file
144
+ t = Puppet::Type.type(:vhost)
145
+ expect(File.exist?(file)).to eq(true)
146
+ end
147
+
148
+ it 'generate providers' do
149
+ file = generator.generate_type_files
150
+ p_vhost = File.join(provider_dir, 'vhost')
151
+ expect(File.exist?(File.join(p_vhost, 'default1.rb'))).to eq(true)
152
+ expect(File.exist?(File.join(p_vhost, 'default2.rb'))).to eq(true)
153
+ expect(generator.context.providers).to eq(%w(default1 default2))
154
+ end
155
+ end
156
+
157
+ describe 'existing type' do
158
+ let(:type_name) do
159
+ 'package'
160
+ end
161
+
162
+ before :each do
163
+ FileUtils.rm_rf(type_spec_dir)
164
+ FileUtils.rm_rf(type_dir)
165
+ end
166
+
167
+ # it 'raise error' do
168
+ # expect{Retrospec::Puppet::Generators::TypeGenerator.new(module_path,
169
+ # cli_opts)}.to raise_exception Retrospec::Puppet::Generators::CoreTypeException
170
+ # end
171
+ end
172
+ end
173
+ end
@@ -1,14 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'Utilities::Module' do
4
-
5
4
  before :each do
6
5
  clean_up_spec_dir(@path)
7
- @opts = {:module_path => @path, :enable_beaker_tests => false,
8
- :enable_user_templates => false, :template_dir => nil }
6
+ @opts = { :module_path => @path, :enable_beaker_tests => false,
7
+ :enable_user_templates => false, :template_dir => nil }
9
8
  @module = Utilities::PuppetModule.instance
10
9
  @module.module_path = @opts[:module_path]
11
-
12
10
  end
13
11
 
14
12
  before :all do
@@ -23,7 +21,7 @@ describe 'Utilities::Module' do
23
21
  end
24
22
 
25
23
  it 'should create tmp module path' do
26
- expect(File.exists?(@module.tmp_modules_dir)).to be true
24
+ expect(File.exist?(@module.tmp_modules_dir)).to be true
27
25
  end
28
26
 
29
27
  it 'should create a temp modules dir' do
@@ -34,7 +32,7 @@ describe 'Utilities::Module' do
34
32
  it 'should create a temp modules dir' do
35
33
  tomcat_path = @module.create_tmp_module_path(@opts[:module_path])
36
34
  expect(tomcat_path).to match(/modules/)
37
- expect(File.exists?(tomcat_path)).to be true
35
+ expect(File.exist?(tomcat_path)).to be true
38
36
  end
39
37
 
40
38
  it 'should set the module path' do
@@ -43,13 +41,12 @@ describe 'Utilities::Module' do
43
41
 
44
42
  it 'should create a link in the temp modules directory' do
45
43
  tmp_path = @module.create_tmp_module_path(@opts[:module_path])
46
- expect(File.exists?(tmp_path)).to eq(true)
44
+ expect(File.exist?(tmp_path)).to eq(true)
47
45
  expect(tmp_path).to eq(File.join(@module.tmp_modules_dir, @module.module_name))
48
46
  end
49
47
 
50
48
  it 'should find types' do
51
49
  expect(@module.types).to be_instance_of(Array)
52
- expect(@module.types.map {|t| t.name}.length).to eq(18)
50
+ expect(@module.types.map(&:name).length).to eq(18)
53
51
  end
54
-
55
- end
52
+ end
@@ -1,30 +1,228 @@
1
1
  require 'spec_helper'
2
2
  require 'retrospec'
3
3
 
4
- describe "puppet" do
5
- let(:plugin) do
6
- Retrospec::Plugins::V1::Puppet.new('/tmp/testplugin_dir', {:name => 'testplugin', :config1 => 'test'})
7
- end
4
+ describe 'puppet' do
8
5
 
6
+ it 'can show the version' do
7
+ expect(Retrospec::Puppet::VERSION).to be_instance_of(String)
8
+ end
9
9
  let(:global_opts) do
10
- {:module_path => '/tmp/testplugin_dir'}
10
+ {}
11
11
  end
12
12
 
13
- before :each do
14
- FileUtils.rm_rf('/tmp/testplugin_dir')
13
+ let(:plugin_config) do
14
+ {}
15
15
  end
16
16
 
17
- it 'can show the version' do
18
- expect(Retrospec::Puppet::VERSION).to eq('0.10.0')
17
+ let(:args) do
18
+ []
19
+ end
20
+
21
+ let(:global_config) do
22
+ {}
19
23
  end
20
24
 
21
- # disabling for now until we can stub gets
22
- xit 'can run cli and create new module' do
23
- expect(Retrospec::Plugins::V1::Puppet.run_cli(global_opts, {},{}, ['new_module'])).to eq(nil)
25
+ let(:retrospec) do
26
+ Retrospec::Plugins::V1::Puppet.run_cli(global_opts, global_config, plugin_config, args)
27
+ end
28
+
29
+ describe 'new_module' do
30
+
31
+ let(:module_path) do
32
+ '/tmp/testabc123'
33
+ end
34
+
35
+ before(:all) do
36
+ ENV['RETROSPEC_PUPPET_AUTO_GENERATE'] = 'true'
37
+ end
38
+
39
+ let(:plugin_config) do
40
+ {
41
+ 'plugins::puppet::template_dir' => retrospec_templates_path,
42
+ 'plugins::puppet::author' => 'test_name',
43
+ 'plugins::puppet::default_license' => 'Apache-3.0'
44
+ }
45
+ end
46
+
47
+
48
+ describe 'without module path' do
49
+ before(:each) do
50
+ FileUtils.rm_rf('/tmp/testabc123')
51
+ end
52
+
53
+ let(:module_path) do
54
+ '/tmp'
55
+ end
56
+
57
+ let(:global_opts) do
58
+ {:module_path => module_path }
59
+ end
60
+
61
+ let(:args) do
62
+ ['new_module', '-n', 'testabc123']
63
+ end
64
+
65
+ it 'should create a module when it does not exist' do
66
+ retrospec
67
+ expect(File.exist?(File.join(module_path, 'testabc123', 'manifests', 'init.pp'))).to eq(true)
68
+ expect(File.exist?(File.join(module_path, 'testabc123', 'metadata.json'))).to eq(true)
69
+ expect(File.exist?(File.join(module_path, 'testabc123', 'testabc123_schema.yaml'))).to eq(true)
70
+ metadata = JSON.parse(File.read(File.join(module_path, 'testabc123', 'metadata.json')))
71
+ expect(metadata['author']).to eq('test_name')
72
+ expect(metadata['license']).to eq('Apache-3.0')
73
+ end
74
+ end
75
+
76
+ describe 'with path' do
77
+ let(:module_path) do
78
+ '/tmp/testabc124'
79
+ end
80
+
81
+ let(:global_opts) do
82
+ {:module_path => module_path }
83
+ end
84
+
85
+ before(:all) do
86
+ FileUtils.rm_rf('/tmp/testabc124')
87
+ end
88
+
89
+ let(:args) do
90
+ ['new_module', '-n', 'testabc124']
91
+ end
92
+
93
+ it 'should create a module when it does not exist' do
94
+ retrospec
95
+ expect(File.exist?(File.join(module_path, 'manifests', 'init.pp'))).to eq(true)
96
+ expect(File.exist?(File.join(module_path, 'metadata.json'))).to eq(true)
97
+ expect(File.exist?(File.join(module_path, 'testabc124_schema.yaml'))).to eq(true)
98
+ metadata = JSON.parse(File.read(File.join(module_path, 'metadata.json')))
99
+ expect(metadata['author']).to eq('test_name')
100
+ expect(metadata['license']).to eq('Apache-3.0')
101
+ end
102
+ end
24
103
  end
25
104
 
26
- xit 'can run cli' do
27
- Retrospec::Plugins::V1::Puppet.run_cli(global_opts, {},{}, ['new_module'])
28
- expect(Retrospec::Plugins::V1::Puppet.run_cli(global_opts, {},{}, [])).to eq(nil)
105
+ describe 'generator functions' do
106
+ let(:module_path) do
107
+ '/tmp/testabc123'
108
+ end
109
+
110
+ before(:all) do
111
+ ENV['RETROSPEC_PUPPET_AUTO_GENERATE'] = 'true'
112
+ end
113
+
114
+ let(:plugin_config) do
115
+ {
116
+ 'plugins::puppet::template_dir' => retrospec_templates_path,
117
+ 'plugins::puppet::author' => 'test_name'
118
+ }
119
+ end
120
+
121
+ let(:global_opts) do
122
+ {:module_path => module_path }
123
+ end
124
+
125
+ before(:each) do
126
+ FileUtils.rm_rf(module_path)
127
+ # ensure the module exists
128
+ Retrospec::Plugins::V1::Puppet.run_cli(global_opts,
129
+ global_config, plugin_config,
130
+ ['new_module', '-n', 'testabc123'])
131
+ end
132
+
133
+ describe 'new_fact' do
134
+
135
+ let(:args) do
136
+ ['new_fact', '-n', 'test_fact']
137
+ end
138
+
139
+ it 'should create spec and rb file' do
140
+ retrospec
141
+ expect(File.exist?(File.join(module_path,'lib', 'facter', 'test_fact.rb'))).to eq(true)
142
+ expect(File.exist?(File.join(module_path, 'spec', 'unit', 'facter', 'test_fact_spec.rb'))).to eq(true)
143
+ end
144
+ end
145
+
146
+ describe 'new_type' do
147
+ let(:type_name) do
148
+ 'type_a'
149
+ end
150
+ let(:type_dir) do
151
+ File.join(module_path,'lib', 'puppet', 'type')
152
+ end
153
+
154
+ let(:type_spec_dir) do
155
+ File.join(module_path, 'spec', 'unit', 'puppet', 'type')
156
+ end
157
+
158
+ let(:args) do
159
+ ['new_type', '-n', type_name]
160
+ end
161
+
162
+ it 'should create spec and rb file' do
163
+ retrospec
164
+ expect(File.exist?(File.join(type_dir, "#{type_name}.rb"))).to eq(true)
165
+ expect(File.exist?(File.join(type_spec_dir, "#{type_name}_spec.rb"))).to eq(true)
166
+ end
167
+
168
+ describe 'core type' do
169
+ let(:type_name) do
170
+ 'package'
171
+ end
172
+
173
+ it 'should raise error' do
174
+ retrospec
175
+ expect(File.exist?(File.join(type_dir, "#{type_name}.rb"))).to eq(false)
176
+ expect(File.exist?(File.join(type_spec_dir, "#{type_name}_spec.rb"))).to eq(false)
177
+ end
178
+ end
179
+ end
180
+ describe 'new_provider' do
181
+
182
+ let(:args) do
183
+ ['new_provider', '-n', 'pname', '--type', 'type_a']
184
+ end
185
+
186
+ it 'should create spec and rb file' do
187
+ retrospec
188
+ expect(File.exist?(File.join(module_path,'lib', 'puppet', 'provider', 'type_a', 'pname.rb'))).to eq(true)
189
+ expect(File.exist?(File.join(module_path, 'spec', 'unit', 'puppet', 'provider', 'type_a', 'pname_spec.rb'))).to eq(true)
190
+ end
191
+ end
192
+
193
+ describe 'new_function' do
194
+
195
+ describe 'v3' do
196
+ let(:args) do
197
+ ['new_function', '-n', 'test_func_v3', '--type', 'v3']
198
+ end
199
+
200
+ it 'should create v3 function' do
201
+ retrospec
202
+ expect(File.exist?(File.join(module_path,'lib', 'puppet','parser', 'functions', 'test_func_v3.rb'))).to eq(true)
203
+ end
204
+
205
+ it 'should create v3 function spec file' do
206
+ retrospec
207
+ expect(File.exist?(File.join(module_path, 'spec', 'functions', 'test_func_v3_spec.rb'))).to eq(true)
208
+ end
209
+
210
+ end
211
+ describe 'v4' do
212
+ let(:args) do
213
+ ['new_function', '-n', 'test_func_v4', '--type', 'v4']
214
+ end
215
+
216
+ it 'should create v4 function' do
217
+ retrospec
218
+ expect(File.exist?(File.join(module_path,'lib', 'puppet', 'functions', 'test_func_v4.rb'))).to eq(true)
219
+ end
220
+
221
+ it 'should create v4 function spec file' do
222
+ retrospec
223
+ expect(File.exist?(File.join(module_path, 'spec', 'functions', 'test_func_v4_spec.rb'))).to eq(true)
224
+ end
225
+ end
226
+ end
29
227
  end
30
228
  end