puppet-retrospec 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +17 -0
- data/CHANGELOG.md +11 -0
- data/DEVELOPMENT.md +3 -0
- data/Gemfile +10 -9
- data/Gemfile.lock +2 -0
- data/README.md +211 -273
- data/Rakefile +8 -8
- data/VERSION +1 -1
- data/lib/retrospec-puppet.rb +3 -3
- data/lib/retrospec/plugins/v1/plugin/conditional.rb +5 -6
- data/lib/retrospec/plugins/v1/plugin/exceptions.rb +17 -0
- data/lib/retrospec/plugins/v1/plugin/generators.rb +7 -0
- data/lib/retrospec/plugins/v1/plugin/generators/fact_generator.rb +18 -10
- data/lib/retrospec/plugins/v1/plugin/generators/function_generator.rb +187 -0
- data/lib/retrospec/plugins/v1/plugin/generators/module_generator.rb +25 -26
- data/lib/retrospec/plugins/v1/plugin/generators/{facter.rb → parsers/facter.rb} +28 -35
- data/lib/retrospec/plugins/v1/plugin/generators/parsers/function.rb +91 -0
- data/lib/retrospec/plugins/v1/plugin/generators/parsers/type.rb +79 -0
- data/lib/retrospec/plugins/v1/plugin/generators/provider_generator.rb +107 -0
- data/lib/retrospec/plugins/v1/plugin/generators/schema_generator.rb +221 -0
- data/lib/retrospec/plugins/v1/plugin/generators/type_generator.rb +118 -0
- data/lib/retrospec/plugins/v1/plugin/helpers.rb +3 -7
- data/lib/retrospec/plugins/v1/plugin/puppet.rb +141 -60
- data/lib/retrospec/plugins/v1/plugin/puppet_module.rb +29 -26
- data/lib/retrospec/plugins/v1/plugin/resource.rb +6 -7
- data/lib/retrospec/plugins/v1/plugin/spec_object.rb +5 -8
- data/lib/retrospec/plugins/v1/plugin/template_helpers.rb +9 -10
- data/lib/retrospec/plugins/v1/plugin/templates/clone-hook +15 -8
- data/lib/retrospec/plugins/v1/plugin/type_code.rb +4 -4
- data/lib/retrospec/plugins/v1/plugin/variable_store.rb +26 -30
- data/lib/retrospec/plugins/v1/plugin/version.rb +1 -1
- data/puppet-retrospec.gemspec +43 -4
- data/spec/fixtures/facts/oracle_controls.rb +38 -0
- data/spec/fixtures/fixture_modules/required_parameters/manifests/init.pp +8 -0
- data/spec/fixtures/fixture_modules/sample_module/lib/facter/fix_installed.rb +11 -0
- data/spec/fixtures/fixture_modules/sample_module/lib/puppet/functions/awesome_parser.rb +13 -0
- data/spec/fixtures/fixture_modules/sample_module/lib/puppet/functions/reduce.rb +31 -0
- data/spec/fixtures/fixture_modules/sample_module/lib/puppet/parser/functions/bad_sha1.rb +6 -0
- data/spec/fixtures/fixture_modules/sample_module/lib/puppet/parser/functions/defined.rb +94 -0
- data/spec/fixtures/fixture_modules/sample_module/lib/puppet/parser/functions/sha1.rb +6 -0
- data/spec/fixtures/fixture_modules/sample_module/spec/unit/facter/fix_installed_spec.rb +21 -0
- data/spec/fixtures/modules/tomcat/files/.gitkeep +0 -0
- data/spec/fixtures/modules/tomcat/templates/.gitkeep +0 -0
- data/spec/fixtures/modules/tomcat/tests/.gitkeep +0 -0
- data/spec/fixtures/providers/bmc/ipmitool.rb +188 -0
- data/spec/fixtures/providers/bmcuser/ipmitool.rb +140 -0
- data/spec/fixtures/types/bmc.rb +102 -0
- data/spec/fixtures/types/bmcuser.rb +46 -0
- data/spec/fixtures/types/db_opatch.rb +93 -0
- data/spec/integration/retrospec_spec.rb +1 -3
- data/spec/spec_helper.rb +33 -6
- data/spec/unit/conditional_spec.rb +12 -15
- data/spec/unit/generators/fact_generater_spec.rb +49 -17
- data/spec/unit/generators/function_generator_spec.rb +301 -0
- data/spec/unit/generators/function_spec.rb +67 -0
- data/spec/unit/generators/parsers/fact_spec.rb +62 -0
- data/spec/unit/generators/parsers/provider_spec.rb +44 -0
- data/spec/unit/generators/parsers/type_spec.rb +93 -0
- data/spec/unit/generators/provider_generator_spec.rb +120 -0
- data/spec/unit/generators/schema_generator_spec.rb +122 -0
- data/spec/unit/generators/type_generator_spec.rb +173 -0
- data/spec/unit/module_spec.rb +7 -10
- data/spec/unit/plugin_spec.rb +213 -15
- data/spec/unit/puppet-retrospec_spec.rb +81 -100
- data/spec/unit/resource_spec.rb +16 -17
- data/spec/unit/spec_object_spec.rb +46 -0
- data/spec/unit/type_code_spec.rb +9 -11
- data/spec/unit/variable_store_spec.rb +41 -43
- metadata +54 -4
- data/spec/unit/generators/fact_spec.rb +0 -58
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'function' do
|
4
|
+
|
5
|
+
describe 'v3 function' do
|
6
|
+
let(:function_file) do
|
7
|
+
File.join(sample_module_path, 'lib', 'puppet', 'parser', 'functions', 'sha1.rb')
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:models) do
|
11
|
+
Retrospec::Puppet::Parser::Functions.load_function(function_file)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'can eval' do
|
15
|
+
expect(models.name).to eq(:sha1)
|
16
|
+
expect(models.doc).to eq('Returns a SHA1 hash value from a provided string.')
|
17
|
+
expect(models.type).to eq(:rvalue)
|
18
|
+
expect(models.arity).to eq(1)
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'bad function' do
|
22
|
+
let(:function_file) do
|
23
|
+
File.join(sample_module_path, 'lib', 'puppet', 'parser', 'functions', 'bad_sha1.rb')
|
24
|
+
end
|
25
|
+
it 'should raise error' do
|
26
|
+
expect{models.name}.to raise_error SyntaxError
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'v4 function' do
|
32
|
+
let(:function_file) do
|
33
|
+
File.join(sample_module_path, 'lib', 'puppet', 'functions', 'reduce.rb')
|
34
|
+
end
|
35
|
+
|
36
|
+
let(:models) do
|
37
|
+
Retrospec::Puppet::Functions.load_function(function_file)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'can eval' do
|
41
|
+
expect(models.name).to eq(:reduce)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'returns array of dispatched methods hashes' do
|
45
|
+
expect(models.dispatched_methods).to be_instance_of(Hash)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'returns correct number of dispached methods' do
|
49
|
+
expect(models.dispatched_methods.keys).to eq([:reduce_without_memo, :reduce_with_memo])
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'returns params of dispatched method' do
|
53
|
+
expect(models.dispatched_methods[:reduce_without_memo][:args].count).to eq(2)
|
54
|
+
expect(models.dispatched_methods[:reduce_without_memo][:args].first[:name]).to eq(:param)
|
55
|
+
expect(models.dispatched_methods[:reduce_without_memo][:args].last[:name]).to eq(:block_param)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'returns required methods' do
|
59
|
+
expect(Retrospec::Puppet::Functions.find_required_methods(:reduce, [:reduce_without_memo, :reduce_with_memo])).to eq([:reduce_without_memo, :reduce_with_memo])
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'returns required methods' do
|
63
|
+
expect(Retrospec::Puppet::Functions.find_required_methods(:reduce)).to eq([:reduce])
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "facter" do
|
4
|
+
let(:model) do
|
5
|
+
Retrospec::Puppet::Generators::Facter.load_fact(file)
|
6
|
+
end
|
7
|
+
|
8
|
+
describe 'node_role' do
|
9
|
+
let(:file) do
|
10
|
+
File.join(fixtures_facts_path , 'node_role.rb')
|
11
|
+
end
|
12
|
+
it 'can eval code' do
|
13
|
+
fact_name = model.facts.keys.first
|
14
|
+
expect(fact_name).to eq(:node_role)
|
15
|
+
fact_data = model.facts[fact_name]
|
16
|
+
confines = fact_data.confines
|
17
|
+
model_facts = model.facts[fact_name].used_facts
|
18
|
+
global_used_facts = model.global_used_facts
|
19
|
+
expect(confines).to eq({:kernel=>"Windows", :is_virtual=>true})
|
20
|
+
expect(model_facts).to eq({})
|
21
|
+
expect(global_used_facts).to eq({})
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
describe 'multiple facts' do
|
27
|
+
let(:file) do
|
28
|
+
File.join(fixtures_facts_path , 'datacenter_facts.rb')
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'can eval code with multiple facts' do
|
32
|
+
global_used_facts = model[:global_used_facts]
|
33
|
+
fact_name = model.facts.keys.first
|
34
|
+
fact_data = model.facts[fact_name]
|
35
|
+
confines = fact_data.confines
|
36
|
+
model_facts = fact_data.used_facts
|
37
|
+
expect(fact_name).to eq(:fact1)
|
38
|
+
expect(confines).to eq({:kernel=>"Linux"})
|
39
|
+
expect(model_facts).to eq({})
|
40
|
+
expect(global_used_facts).to eq({})
|
41
|
+
fact_name = model.facts.keys.last
|
42
|
+
fact_data = model.facts[fact_name]
|
43
|
+
confines = fact_data.confines
|
44
|
+
model_facts = fact_data.used_facts
|
45
|
+
expect(fact_name).to eq(:fact2)
|
46
|
+
expect(confines).to eq({:kernel=>"Windows"})
|
47
|
+
expect(model_facts).to eq({})
|
48
|
+
expect(global_used_facts).to eq({})
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe 'fact value' do
|
53
|
+
let(:file) do
|
54
|
+
File.join(fixtures_facts_path , 'facts_with_methods.rb')
|
55
|
+
end
|
56
|
+
it 'can be processed' do
|
57
|
+
expect(model).to_not eq(nil)
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'provider' do
|
4
|
+
let(:provider_file) do
|
5
|
+
File.join(fixtures_provider_path, 'bmc', 'ipmitool.rb')
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:type_file) do
|
9
|
+
File.join(fixtures_type_path, 'bmc.rb')
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:models) do
|
13
|
+
Retrospec::Puppet::Type.load_type(type_file, provider_file)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'can eval code' do
|
17
|
+
expect(models.name).to eq(:ipmitool)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'contains class methods' do
|
21
|
+
expect(models.class_methods).to eq([:ipmitoolcmd, :instances, :prefetch, :laninfo,
|
22
|
+
:convert_vlanid, :convert_ip_source])
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'contains a file' do
|
26
|
+
expect(models.file).to eq(provider_file)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'contains instance methods' do
|
30
|
+
expect(models.instance_methods).to eq([:ipmitoolcmd, :ensure, :ensure=, :ipsource,
|
31
|
+
:ipsource=, :ip, :ip=, :netmask, :netmask=,
|
32
|
+
:gateway, :gateway=, :vlanid, :vlanid=,
|
33
|
+
:provider, :provider=, :flush, :install,
|
34
|
+
:remove, :exists?])
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'contains properties' do
|
38
|
+
expect(models.properties).to eq([:ensure, :ipsource, :ip, :netmask, :gateway, :vlanid])
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'contains parameters' do
|
42
|
+
expect(models.parameters).to eq([:name, :provider])
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'type' do
|
4
|
+
describe 'bmc' do
|
5
|
+
let(:file) do
|
6
|
+
File.join(fixtures_type_path, 'bmc.rb')
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:models) do
|
10
|
+
Retrospec::Puppet::Type.load_type(file)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'can eval code' do
|
14
|
+
models = Retrospec::Puppet::Type.load_type(file)
|
15
|
+
expect(models.name).to eq(:bmc)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'has correct amount of properties' do
|
19
|
+
expect(models.properties).to eq([:ensure, :ipsource, :ip, :netmask, :gateway, :vlanid])
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'has correct amount of parameters' do
|
23
|
+
expect(models.parameters).to eq([:name, :provider])
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'has the correct number of instance methods' do
|
27
|
+
expect(models.instance_methods).to eq([:validaddr?])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'bmcuser' do
|
32
|
+
let(:file) do
|
33
|
+
File.join(fixtures_type_path, 'bmcuser.rb')
|
34
|
+
end
|
35
|
+
|
36
|
+
let(:models) do
|
37
|
+
Retrospec::Puppet::Type.load_type(file)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'can eval code' do
|
41
|
+
models = Retrospec::Puppet::Type.load_type(file)
|
42
|
+
expect(models.name).to eq(:bmcuser)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'has correct amount of properties' do
|
46
|
+
expect(models.properties).to eq([:ensure, :id, :username, :userpass, :privlevel])
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'has correct amount of parameters' do
|
50
|
+
expect(models.parameters).to eq([:name, :force])
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'has the correct number of instance methods' do
|
54
|
+
expect(models.instance_methods).to eq([])
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'opatch' do
|
59
|
+
let(:file) do
|
60
|
+
File.join(fixtures_type_path, 'db_opatch.rb')
|
61
|
+
end
|
62
|
+
|
63
|
+
let(:models) do
|
64
|
+
Retrospec::Puppet::Type.load_type(file)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'can eval code' do
|
68
|
+
models = Retrospec::Puppet::Type.load_type(file)
|
69
|
+
expect(models.name).to eq(:db_opatch)
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'has correct amount of properties' do
|
73
|
+
expect(models.properties).to eq([:ensure, :test_boolean])
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'has correct amount of parameters' do
|
77
|
+
expect(models.parameters).to eq([:name,
|
78
|
+
:patch_id,
|
79
|
+
:os_user,
|
80
|
+
:oracle_product_home_dir,
|
81
|
+
:orainst_dir,
|
82
|
+
:extracted_patch_dir,
|
83
|
+
:ocmrf_file,
|
84
|
+
:opatch_auto,
|
85
|
+
:bundle_sub_patch_id])
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'has the correct number of instance methods' do
|
89
|
+
expect(models.instance_methods).to eq([])
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'provider_generator' do
|
4
|
+
before :each do
|
5
|
+
FileUtils.rm_rf(provider_spec_dir)
|
6
|
+
FileUtils.rm_rf(provider_dir)
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:type_name) do
|
10
|
+
'test_type'
|
11
|
+
end
|
12
|
+
|
13
|
+
after :each do
|
14
|
+
FileUtils.rm_f(generator.provider_name_path) # ensure the file does not exist
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:provider_name) do
|
18
|
+
'default'
|
19
|
+
end
|
20
|
+
|
21
|
+
let(:provider_spec_dir) do
|
22
|
+
File.join(module_path, 'spec', 'unit', 'puppet', 'provider')
|
23
|
+
end
|
24
|
+
|
25
|
+
let(:provider_dir) do
|
26
|
+
File.join(module_path, 'lib', 'puppet', 'provider', type_name)
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:module_path) do
|
30
|
+
File.join(fixture_modules_path, 'tomcat')
|
31
|
+
end
|
32
|
+
|
33
|
+
let(:opts) do
|
34
|
+
['-n', provider_name, '-t', type_name]
|
35
|
+
end
|
36
|
+
|
37
|
+
let(:cli_opts) do
|
38
|
+
cli_opts = Retrospec::Puppet::Generators::ProviderGenerator.run_cli(context, opts)
|
39
|
+
end
|
40
|
+
|
41
|
+
let(:context) do
|
42
|
+
{ :module_path => module_path,
|
43
|
+
:template_dir => retrospec_templates_path }
|
44
|
+
end
|
45
|
+
|
46
|
+
let(:generator) do
|
47
|
+
Retrospec::Puppet::Generators::ProviderGenerator.new(module_path, cli_opts)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'returns provider dir' do
|
51
|
+
expect(generator.provider_dir).to eq(File.join(module_path, 'lib', 'puppet', 'provider'))
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'returns spec directory' do
|
55
|
+
expect(generator.provider_spec_dir).to eq(provider_spec_dir)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'can return provider name' do
|
59
|
+
expect(generator.provider_name).to eq(provider_name)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'can generate a provider file' do
|
63
|
+
expect(generator.generate_provider_files).to eq(File.join(provider_dir, "#{provider_name}.rb"))
|
64
|
+
expect(File.exist?(File.join(provider_dir, "#{provider_name}.rb")))
|
65
|
+
end
|
66
|
+
|
67
|
+
# because these tests were initially designed to only work with a single type name we will have to go
|
68
|
+
# back and rethink how all the names are derived, or possibly structure the fixtures as modules
|
69
|
+
it 'can generate a spec file' do
|
70
|
+
allow(generator).to receive(:provider_dir).and_return(fixtures_provider_path)
|
71
|
+
allow(generator).to receive(:type_dir).and_return(fixtures_type_path)
|
72
|
+
files = [File.join(provider_spec_dir, 'bmc', 'ipmitool_spec.rb'), File.join(provider_spec_dir, 'bmcuser', 'ipmitool_spec.rb')]
|
73
|
+
expect(generator.generate_provider_spec_files).to eq(files)
|
74
|
+
end
|
75
|
+
|
76
|
+
describe 'type_file' do
|
77
|
+
before :each do
|
78
|
+
allow(generator).to receive(:provider_dir).and_return(fixtures_provider_path)
|
79
|
+
allow(generator).to receive(:type_dir).and_return(fixtures_type_path)
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'return path of custom type' do
|
83
|
+
expect(generator.type_file('bmc')).to eq("#{fixtures_type_path}/bmc.rb")
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'return path of core type' do
|
87
|
+
expect(generator.type_file('package')).to eq('puppet/type/package.rb')
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
describe 'cli' do
|
92
|
+
it 'can run the cli options' do
|
93
|
+
# specify the parameters
|
94
|
+
expect(cli_opts).to be_an_instance_of Hash
|
95
|
+
expect(cli_opts[:name]).to eq(provider_name)
|
96
|
+
expect(cli_opts[:type]).to eq(type_name)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
describe 'existing type' do
|
100
|
+
describe 'package' do
|
101
|
+
let(:type_name) do
|
102
|
+
'package'
|
103
|
+
end
|
104
|
+
let(:provider_name) do
|
105
|
+
'ibm_pkg'
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'can generate a spec file' do
|
109
|
+
generator.generate_provider_files
|
110
|
+
files = [File.join(provider_spec_dir, "#{type_name}", "#{provider_name}_spec.rb")]
|
111
|
+
expect(generator.generate_provider_spec_files).to eq(files)
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'can generate a provider file' do
|
115
|
+
expect(generator.generate_provider_files).to eq(File.join(provider_dir, "#{provider_name}.rb"))
|
116
|
+
expect(File.exist?(File.join(provider_dir, "#{provider_name}.rb")))
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'schema_generator' do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
FileUtils.rm(schema_file) if File.exists?(schema_file)
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:generator_opts) do
|
10
|
+
{:name => 'test', :puppet_context => puppet_context, :template_dir => template_dir}
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:module_path) do
|
14
|
+
sample_module_path
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:schema_file) do
|
18
|
+
path = File.join(module_path, 'tomcat_schema.yaml')
|
19
|
+
end
|
20
|
+
|
21
|
+
let(:template_dir) do
|
22
|
+
File.expand_path(File.join(ENV['HOME'], '.retrospec', 'repos', 'retrospec-puppet-templates'))
|
23
|
+
end
|
24
|
+
|
25
|
+
let(:puppet_context) do
|
26
|
+
path = File.join(fixture_modules_path, 'tomcat')
|
27
|
+
opts = { :module_path => path, :enable_beaker_tests => false, :name => 'name-test123',
|
28
|
+
:enable_user_templates => false, :template_dir => template_dir }
|
29
|
+
mod = Retrospec::Plugins::V1::Puppet.new(opts[:module_path], opts)
|
30
|
+
mod.post_init
|
31
|
+
mod.context
|
32
|
+
end
|
33
|
+
|
34
|
+
let(:generator) do
|
35
|
+
Retrospec::Puppet::Generators::SchemaGenerator.new(module_path, generator_opts)
|
36
|
+
end
|
37
|
+
|
38
|
+
let(:hostclass_items) do
|
39
|
+
{
|
40
|
+
"tomcat::catalina_home"=>{"type"=>"any", "required"=>false},
|
41
|
+
"tomcat::user"=>{"type"=>"any", "required"=>false},
|
42
|
+
"tomcat::group"=>{"type"=>"any", "required"=>false},
|
43
|
+
"tomcat::install_from_source"=>{"type"=>"bool", "required"=>false},
|
44
|
+
"tomcat::purge_connectors"=>{"type"=>"bool", "required"=>false},
|
45
|
+
"tomcat::purge_realms"=>{"type"=>"bool", "required"=>false},
|
46
|
+
"tomcat::manage_user"=>{"type"=>"bool", "required"=>false},
|
47
|
+
"tomcat::manage_group"=>{"type"=>"bool", "required"=>false}
|
48
|
+
}
|
49
|
+
end
|
50
|
+
let(:schema_map) do
|
51
|
+
{"type"=>"map",
|
52
|
+
"mapping"=>
|
53
|
+
{
|
54
|
+
"definition" => {
|
55
|
+
"tomcat::war::catalina_base"=>{"type"=>"any", "required"=>false},
|
56
|
+
"tomcat::war::app_base"=>{"type"=>"any", "required"=>false},
|
57
|
+
"tomcat::war::deployment_path"=>{"type"=>"any", "required"=>false},
|
58
|
+
"tomcat::war::war_ensure"=>{"type"=>"str", "required"=>false},
|
59
|
+
"tomcat::war::war_name"=>{"type"=>"any", "required"=>false},
|
60
|
+
"tomcat::war::war_purge"=>{"type"=>"bool", "required"=>false},
|
61
|
+
"tomcat::war::war_source"=>{"type"=>"any", "required"=>false}
|
62
|
+
}
|
63
|
+
}
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should create files without error' do
|
68
|
+
expect(generator.generate_schema_file).to eq(schema_file)
|
69
|
+
expect(File.exists?(schema_file)).to eq(true)
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should contain proper mapping' do
|
73
|
+
schema_file = generator.generate_schema_file
|
74
|
+
sch = YAML.load_file(schema_file)
|
75
|
+
expect(sch.keys).to eq(["type", "mapping"])
|
76
|
+
expect(sch['mapping'].keys).to eq(["hostclass", "definition"])
|
77
|
+
expect(sch['mapping']['hostclass'].keys).to eq(["type", "mapping"])
|
78
|
+
expect(sch['mapping']['definition'].keys).to eq(["type", "mapping"])
|
79
|
+
expect(sch['mapping']['hostclass']['mapping']).to eq(hostclass_items)
|
80
|
+
expect(sch['mapping']['definition']['mapping'].keys.count).to eq(125)
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should produce correct file name' do
|
85
|
+
expect(generator.schema_path).to eq(schema_file)
|
86
|
+
end
|
87
|
+
|
88
|
+
# since the module_spec class is a singleton we can't easily change out the module_path
|
89
|
+
# describe 'required parameter' do
|
90
|
+
# let(:puppet_context) do
|
91
|
+
# path = File.join(fake_fixture_modules, 'required_parameters')
|
92
|
+
# opts = { :module_path => path, :enable_beaker_tests => false, :name => 'name-test123',
|
93
|
+
# :enable_user_templates => false, :template_dir => '/tmp/.retrospec_templates' }
|
94
|
+
# mod = Retrospec::Plugins::V1::Puppet.new(opts[:module_path], opts)
|
95
|
+
# mod.post_init
|
96
|
+
# mod.context
|
97
|
+
# end
|
98
|
+
#
|
99
|
+
# let(:generator) do
|
100
|
+
# Retrospec::Puppet::Generators::SchemaGenerator.new(module_path, generator_opts)
|
101
|
+
# end
|
102
|
+
#
|
103
|
+
# let(:schema_map) do
|
104
|
+
# {"type"=>"map",
|
105
|
+
# "mapping"=>
|
106
|
+
# {"tomcat::catalina_home"=>{"type"=>"any", "required"=>false},
|
107
|
+
# "tomcat::user"=>{"type"=>"any", "required"=>false},
|
108
|
+
# "tomcat::group"=>{"type"=>"any", "required"=>false},
|
109
|
+
# "tomcat::install_from_source"=>{"type"=>"bool", "required"=>false},
|
110
|
+
# "tomcat::purge_connectors"=>{"type"=>"bool", "required"=>false},
|
111
|
+
# "tomcat::purge_realms"=>{"type"=>"bool", "required"=>false},
|
112
|
+
# "tomcat::manage_user"=>{"type"=>"bool", "required"=>false},
|
113
|
+
# "tomcat::manage_group"=>{"type"=>"bool", "required"=>false}
|
114
|
+
# }
|
115
|
+
# }
|
116
|
+
# end
|
117
|
+
# end
|
118
|
+
# it 'should detect when a parameter is required' do
|
119
|
+
# expect(generator.create_map_content).to eq(schema_map)
|
120
|
+
# end
|
121
|
+
|
122
|
+
end
|