Merge pull request #156 from ghoneycutt/cr-patch

create resources
This commit is contained in:
Bryan Jen 2016-01-06 11:28:22 -07:00
commit 35b5dfc04c
6 changed files with 234 additions and 11 deletions

View file

@ -1,3 +1,7 @@
fixtures:
repositories:
stdlib:
repo: 'git://github.com/puppetlabs/puppetlabs-stdlib.git'
ref: '4.2.0'
symlinks:
inifile: "#{source_dir}"

17
Gemfile
View file

@ -11,11 +11,18 @@ def location_for(place, fake_version = nil)
end
group :development, :unit_tests do
gem 'rspec-core', '3.1.7', :require => false
gem 'puppetlabs_spec_helper', :require => false
gem 'simplecov', :require => false
gem 'puppet_facts', :require => false
gem 'json', :require => false
# rspec must be v2 for ruby 1.8.7
if RUBY_VERSION >= '1.8.7' and RUBY_VERSION < '1.9'
gem 'rspec', '~> 2.0'
else
gem 'rspec-core', '3.1.7', :require => false
end
gem 'puppetlabs_spec_helper', :require => false
gem 'puppet-lint', :require => false
gem 'simplecov', :require => false
gem 'puppet_facts', :require => false
gem 'json', :require => false
gem 'pry', :require => false
end
group :system_tests do

46
manifests/init.pp Normal file
View file

@ -0,0 +1,46 @@
# == Class: inifile
#
# Use create_resources() to allow the specification of ini_setting and
# ini_subsetting entries.
#
class inifile (
$ini_settings = undef,
$ini_subsettings = undef,
$ini_settings_hiera_merge = true,
$ini_subsettings_hiera_merge = true,
) {
if is_string($ini_settings_hiera_merge) == true {
$ini_settings_hiera_merge_bool = str2bool($ini_settings_hiera_merge)
} else {
$ini_settings_hiera_merge_bool = $ini_settings_hiera_merge
}
validate_bool($ini_settings_hiera_merge_bool)
if is_string($ini_subsettings_hiera_merge) == true {
$ini_subsettings_hiera_merge_bool = str2bool($ini_subsettings_hiera_merge)
} else {
$ini_subsettings_hiera_merge_bool = $ini_subsettings_hiera_merge
}
validate_bool($ini_subsettings_hiera_merge_bool)
if $ini_settings != undef {
if $ini_settings_hiera_merge_bool == true {
$ini_settings_real = hiera_hash('inifile::ini_settings')
} else {
$ini_settings_real = $ini_settings
}
validate_hash($ini_settings_real)
create_resources('ini_setting',$ini_settings_real)
}
if $ini_subsettings != undef {
if $ini_subsettings_hiera_merge_bool == true {
$ini_subsettings_real = hiera_hash('inifile::ini_subsettings')
} else {
$ini_subsettings_real = $ini_subsettings
}
validate_hash($ini_subsettings_real)
create_resources('ini_subsetting',$ini_subsettings_real)
}
}

View file

@ -7,9 +7,6 @@
"source": "https://github.com/puppetlabs/puppetlabs-inifile",
"project_page": "https://github.com/puppetlabs/puppetlabs-inifile",
"issues_url": "https://tickets.puppetlabs.com/browse/MODULES",
"dependencies": [
],
"operatingsystem_support": [
{
"operatingsystem": "RedHat",
@ -101,5 +98,8 @@
"name": "puppet",
"version_requirement": ">= 3.0.0 < 5.0.0"
}
],
"dependencies": [
{"name":"puppetlabs/stdlib","version_requirement":">= 4.2.0"}
]
}

View file

@ -2,9 +2,9 @@ require 'spec_helper'
# We can't really test much here, apart from the type roundtrips though the
# parser OK.
describe 'inherit_test1' do
it do
it {
should contain_inherit_ini_setting('valid_type').with({
'value' => 'true'
'value' => 'true',
})
end
}
end

166
spec/classes/init_spec.rb Normal file
View file

@ -0,0 +1,166 @@
require 'spec_helper'
describe 'inifile' do
describe 'with default options' do
it { should compile.with_all_deps }
it { should contain_class('inifile') }
end
describe 'with parameter ini_settings_hiera_merge' do
context 'set to an invalid type (non-string and a non-boolean)' do
let(:params) { { :ini_settings_hiera_merge => ['invalid','type'] } }
it 'should fail' do
expect {
should contain_class('inifile')
}.to raise_error(Puppet::Error,/\["invalid", "type"\] is not a boolean./)
end
end
['true',true,'false',false].each do |value|
context "set to #{value}" do
let(:params) { { :ini_settings_hiera_merge => value } }
it { should contain_class('inifile') }
end
end
end
describe 'with parameter ini_settings' do
context 'set to an invalid type (non-hash)' do
let(:params) do
{
:ini_settings => ['invalid','type'],
:ini_settings_hiera_merge => false,
}
end
it 'should fail' do
expect {
should contain_class('inifile')
}.to raise_error(Puppet::Error,/\["invalid", "type"\] is not a Hash./)
end
end
context 'set to a valid hash' do
let(:params) { { :ini_settings_hiera_merge => false,
:ini_settings => {
'sample setting' => {
'ensure' => 'absent',
'path' => '/tmp/foo.ini',
'section' => 'foo',
'setting' => 'foosetting',
'value' => 'FOO!',
},
'colorize_git' => {
'ensure' => 'present',
'path' => '/root/.gitconfig',
'section' => 'color',
'setting' => 'ui',
'value' => 'auto',
}
} } }
it { should contain_class('inifile') }
it {
should contain_ini_setting('sample setting').with({
'ensure' => 'absent',
'path' => '/tmp/foo.ini',
'section' => 'foo',
'setting' => 'foosetting',
'value' => 'FOO!',
})
}
it {
should contain_ini_setting('colorize_git').with({
'ensure' => 'present',
'path' => '/root/.gitconfig',
'section' => 'color',
'setting' => 'ui',
'value' => 'auto',
})
}
end
end
describe 'with parameter ini_subsettings_hiera_merge' do
context 'set to an invalid type (non-string and a non-boolean)' do
let(:params) { { :ini_subsettings_hiera_merge => ['invalid','type'] } }
it 'should fail' do
expect {
should contain_class('inifile')
}.to raise_error(Puppet::Error,/\["invalid", "type"\] is not a boolean./)
end
end
['true',true,'false',false].each do |value|
context "set to #{value}" do
let(:params) { { :ini_subsettings_hiera_merge => value } }
it { should contain_class('inifile') }
end
end
end
describe 'with parameter ini_subsettings' do
context 'set to an invalid type (non-hash)' do
let(:params) do
{
:ini_subsettings => ['invalid','type'],
:ini_subsettings_hiera_merge => false,
}
end
it 'should fail' do
expect {
should contain_class('inifile')
}.to raise_error(Puppet::Error,/\["invalid", "type"\] is not a Hash./)
end
end
context 'set to a valid hash' do
let(:params) { { :ini_subsettings_hiera_merge => false,
:ini_subsettings => {
'sample setting' => {
'ensure' => 'absent',
'path' => '/tmp/foo.ini',
'section' => 'foo',
'setting' => 'foosetting',
'value' => 'FOO!',
},
'colorize_git' => {
'ensure' => 'present',
'path' => '/root/.gitconfig',
'section' => 'color',
'setting' => 'ui',
'value' => 'auto',
}
} } }
it { should contain_class('inifile') }
it {
should contain_ini_subsetting('sample setting').with({
'ensure' => 'absent',
'path' => '/tmp/foo.ini',
'section' => 'foo',
'setting' => 'foosetting',
'value' => 'FOO!',
})
}
it {
should contain_ini_subsetting('colorize_git').with({
'ensure' => 'present',
'path' => '/root/.gitconfig',
'section' => 'color',
'setting' => 'ui',
'value' => 'auto',
})
}
end
end
end