module-inifile/spec/functions/create_ini_settings_spec.rb
mh 6eb8f9ca98 introduce create_ini_settings
create_ini_settings is a function that allows you to create
ini_setting resources from a simple hash:

    $settings = {  section1 => {
        setting1 => val1
      },
      section2 => {
        setting2 => val2,
        setting3 => {
          ensure => absent
        }
      }
    }
    $defaults = {
      path => '/tmp/foo.ini'
    }
    create_ini_settings($settings,$defaults)

Will create the following resources

    ini_setting{'[section1] setting1':
      ensure  => present,
      section => 'section1',
      setting => 'setting1',
      value   => 'val1',
      path    => '/tmp/foo.ini',
    }
    ini_setting{'[section2] setting2':
      ensure  => present,
      section => 'section2',
      setting => 'setting2',
      value   => 'val2',
      path    => '/tmp/foo.ini',
    }
    ini_setting{'[section2] setting3':
      ensure  => absent,
      section => 'section2',
      setting => 'setting3',
      path    => '/tmp/foo.ini',
    }

This allows one to create much easier classes
that should be able to manage an arbritary set of
ini-style settings without having to specify each
one of them.
2015-01-28 22:09:34 +01:00

26 lines
930 B
Ruby

#! /usr/bin/env ruby
require 'spec_helper'
require 'rspec-puppet'
describe 'create_ini_settings' do
before :each do
Puppet::Parser::Functions.autoloader.loadall
Puppet::Parser::Functions.function(:create_resources)
end
describe 'argument handling' do
it { should run.with_params.and_raise_error(Puppet::ParseError, /0 for 1 or 2/) }
it { should run.with_params(1,2,3).and_raise_error(Puppet::ParseError, /3 for 1 or 2/) }
it { should run.with_params('foo').and_raise_error(Puppet::ParseError, /Requires all arguments/) }
it { should run.with_params({},'foo').and_raise_error(Puppet::ParseError, /Requires all arguments/) }
it { should run.with_params({}) }
it { should run.with_params({},{}) }
it { should run.with_params({ 1 => 2 }).and_raise_error(Puppet::ParseError, /Section 1 must contain a Hash/) }
end
context 'given a catalog with puppet package => absent' do
end
end