puppetmodule-stdlib 4.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +253 -0
- data/CONTRIBUTING.md +65 -0
- data/Gemfile +33 -0
- data/LICENSE +19 -0
- data/Modulefile +11 -0
- data/README.markdown +1173 -0
- data/README_DEVELOPER.markdown +35 -0
- data/RELEASE_PROCESS.markdown +24 -0
- data/Rakefile +2 -0
- data/lib/facter/pe_version.rb +53 -0
- data/lib/facter/puppet_vardir.rb +26 -0
- data/lib/facter/root_home.rb +19 -0
- data/lib/facter/util/puppet_settings.rb +21 -0
- data/lib/puppet/parser/functions/abs.rb +36 -0
- data/lib/puppet/parser/functions/any2array.rb +33 -0
- data/lib/puppet/parser/functions/bool2num.rb +49 -0
- data/lib/puppet/parser/functions/capitalize.rb +34 -0
- data/lib/puppet/parser/functions/chomp.rb +35 -0
- data/lib/puppet/parser/functions/chop.rb +37 -0
- data/lib/puppet/parser/functions/concat.rb +37 -0
- data/lib/puppet/parser/functions/count.rb +22 -0
- data/lib/puppet/parser/functions/defined_with_params.rb +35 -0
- data/lib/puppet/parser/functions/delete.rb +46 -0
- data/lib/puppet/parser/functions/delete_at.rb +49 -0
- data/lib/puppet/parser/functions/downcase.rb +33 -0
- data/lib/puppet/parser/functions/empty.rb +28 -0
- data/lib/puppet/parser/functions/ensure_packages.rb +24 -0
- data/lib/puppet/parser/functions/ensure_resource.rb +35 -0
- data/lib/puppet/parser/functions/flatten.rb +33 -0
- data/lib/puppet/parser/functions/floor.rb +20 -0
- data/lib/puppet/parser/functions/fqdn_rotate.rb +46 -0
- data/lib/puppet/parser/functions/get_module_path.rb +17 -0
- data/lib/puppet/parser/functions/getparam.rb +35 -0
- data/lib/puppet/parser/functions/getvar.rb +26 -0
- data/lib/puppet/parser/functions/grep.rb +33 -0
- data/lib/puppet/parser/functions/has_interface_with.rb +52 -0
- data/lib/puppet/parser/functions/has_ip_address.rb +25 -0
- data/lib/puppet/parser/functions/has_ip_network.rb +25 -0
- data/lib/puppet/parser/functions/has_key.rb +28 -0
- data/lib/puppet/parser/functions/hash.rb +41 -0
- data/lib/puppet/parser/functions/is_array.rb +22 -0
- data/lib/puppet/parser/functions/is_domain_name.rb +47 -0
- data/lib/puppet/parser/functions/is_float.rb +27 -0
- data/lib/puppet/parser/functions/is_function_available.rb +23 -0
- data/lib/puppet/parser/functions/is_hash.rb +22 -0
- data/lib/puppet/parser/functions/is_integer.rb +27 -0
- data/lib/puppet/parser/functions/is_ip_address.rb +32 -0
- data/lib/puppet/parser/functions/is_mac_address.rb +27 -0
- data/lib/puppet/parser/functions/is_numeric.rb +27 -0
- data/lib/puppet/parser/functions/is_string.rb +26 -0
- data/lib/puppet/parser/functions/join.rb +41 -0
- data/lib/puppet/parser/functions/join_keys_to_values.rb +47 -0
- data/lib/puppet/parser/functions/keys.rb +26 -0
- data/lib/puppet/parser/functions/loadyaml.rb +20 -0
- data/lib/puppet/parser/functions/lstrip.rb +33 -0
- data/lib/puppet/parser/functions/max.rb +21 -0
- data/lib/puppet/parser/functions/member.rb +44 -0
- data/lib/puppet/parser/functions/merge.rb +33 -0
- data/lib/puppet/parser/functions/min.rb +21 -0
- data/lib/puppet/parser/functions/num2bool.rb +43 -0
- data/lib/puppet/parser/functions/parsejson.rb +24 -0
- data/lib/puppet/parser/functions/parseyaml.rb +24 -0
- data/lib/puppet/parser/functions/pick.rb +29 -0
- data/lib/puppet/parser/functions/prefix.rb +45 -0
- data/lib/puppet/parser/functions/range.rb +80 -0
- data/lib/puppet/parser/functions/reject.rb +31 -0
- data/lib/puppet/parser/functions/reverse.rb +28 -0
- data/lib/puppet/parser/functions/rstrip.rb +32 -0
- data/lib/puppet/parser/functions/shuffle.rb +46 -0
- data/lib/puppet/parser/functions/size.rb +48 -0
- data/lib/puppet/parser/functions/sort.rb +27 -0
- data/lib/puppet/parser/functions/squeeze.rb +36 -0
- data/lib/puppet/parser/functions/str2bool.rb +46 -0
- data/lib/puppet/parser/functions/str2saltedsha512.rb +32 -0
- data/lib/puppet/parser/functions/strftime.rb +107 -0
- data/lib/puppet/parser/functions/strip.rb +39 -0
- data/lib/puppet/parser/functions/suffix.rb +45 -0
- data/lib/puppet/parser/functions/swapcase.rb +39 -0
- data/lib/puppet/parser/functions/time.rb +49 -0
- data/lib/puppet/parser/functions/to_bytes.rb +28 -0
- data/lib/puppet/parser/functions/type.rb +50 -0
- data/lib/puppet/parser/functions/unique.rb +51 -0
- data/lib/puppet/parser/functions/upcase.rb +41 -0
- data/lib/puppet/parser/functions/uriescape.rb +36 -0
- data/lib/puppet/parser/functions/validate_absolute_path.rb +56 -0
- data/lib/puppet/parser/functions/validate_array.rb +33 -0
- data/lib/puppet/parser/functions/validate_augeas.rb +81 -0
- data/lib/puppet/parser/functions/validate_bool.rb +34 -0
- data/lib/puppet/parser/functions/validate_cmd.rb +47 -0
- data/lib/puppet/parser/functions/validate_hash.rb +33 -0
- data/lib/puppet/parser/functions/validate_re.rb +40 -0
- data/lib/puppet/parser/functions/validate_slength.rb +52 -0
- data/lib/puppet/parser/functions/validate_string.rb +33 -0
- data/lib/puppet/parser/functions/values.rb +39 -0
- data/lib/puppet/parser/functions/values_at.rb +98 -0
- data/lib/puppet/parser/functions/zip.rb +65 -0
- data/lib/puppet/provider/file_line/ruby.rb +59 -0
- data/lib/puppet/type/anchor.rb +41 -0
- data/lib/puppet/type/file_line.rb +70 -0
- data/manifests/init.pp +20 -0
- data/manifests/stages.pp +43 -0
- data/spec/functions/defined_with_params_spec.rb +37 -0
- data/spec/functions/ensure_packages_spec.rb +42 -0
- data/spec/functions/ensure_resource_spec.rb +40 -0
- data/spec/functions/getparam_spec.rb +34 -0
- data/spec/monkey_patches/alias_should_to_must.rb +8 -0
- data/spec/monkey_patches/publicize_methods.rb +10 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +28 -0
- data/spec/unit/facter/pe_version_spec.rb +76 -0
- data/spec/unit/facter/root_home_spec.rb +40 -0
- data/spec/unit/facter/util/puppet_settings_spec.rb +35 -0
- data/spec/unit/puppet/parser/functions/abs_spec.rb +25 -0
- data/spec/unit/puppet/parser/functions/any2array_spec.rb +55 -0
- data/spec/unit/puppet/parser/functions/bool2num_spec.rb +24 -0
- data/spec/unit/puppet/parser/functions/capitalize_spec.rb +19 -0
- data/spec/unit/puppet/parser/functions/chomp_spec.rb +19 -0
- data/spec/unit/puppet/parser/functions/chop_spec.rb +19 -0
- data/spec/unit/puppet/parser/functions/concat_spec.rb +15 -0
- data/spec/unit/puppet/parser/functions/count_spec.rb +31 -0
- data/spec/unit/puppet/parser/functions/delete_at_spec.rb +19 -0
- data/spec/unit/puppet/parser/functions/delete_spec.rb +38 -0
- data/spec/unit/puppet/parser/functions/downcase_spec.rb +24 -0
- data/spec/unit/puppet/parser/functions/empty_spec.rb +23 -0
- data/spec/unit/puppet/parser/functions/flatten_spec.rb +27 -0
- data/spec/unit/puppet/parser/functions/floor_spec.rb +39 -0
- data/spec/unit/puppet/parser/functions/fqdn_rotate_spec.rb +33 -0
- data/spec/unit/puppet/parser/functions/get_module_path_spec.rb +46 -0
- data/spec/unit/puppet/parser/functions/getvar_spec.rb +37 -0
- data/spec/unit/puppet/parser/functions/grep_spec.rb +19 -0
- data/spec/unit/puppet/parser/functions/has_interface_with_spec.rb +64 -0
- data/spec/unit/puppet/parser/functions/has_ip_address_spec.rb +39 -0
- data/spec/unit/puppet/parser/functions/has_ip_network_spec.rb +36 -0
- data/spec/unit/puppet/parser/functions/has_key_spec.rb +42 -0
- data/spec/unit/puppet/parser/functions/hash_spec.rb +19 -0
- data/spec/unit/puppet/parser/functions/is_array_spec.rb +29 -0
- data/spec/unit/puppet/parser/functions/is_domain_name_spec.rb +64 -0
- data/spec/unit/puppet/parser/functions/is_float_spec.rb +33 -0
- data/spec/unit/puppet/parser/functions/is_function_available.rb +31 -0
- data/spec/unit/puppet/parser/functions/is_hash_spec.rb +29 -0
- data/spec/unit/puppet/parser/functions/is_integer_spec.rb +34 -0
- data/spec/unit/puppet/parser/functions/is_ip_address_spec.rb +39 -0
- data/spec/unit/puppet/parser/functions/is_mac_address_spec.rb +29 -0
- data/spec/unit/puppet/parser/functions/is_numeric_spec.rb +39 -0
- data/spec/unit/puppet/parser/functions/is_string_spec.rb +34 -0
- data/spec/unit/puppet/parser/functions/join_keys_to_values_spec.rb +40 -0
- data/spec/unit/puppet/parser/functions/join_spec.rb +19 -0
- data/spec/unit/puppet/parser/functions/keys_spec.rb +21 -0
- data/spec/unit/puppet/parser/functions/lstrip_spec.rb +19 -0
- data/spec/unit/puppet/parser/functions/max_spec.rb +27 -0
- data/spec/unit/puppet/parser/functions/member_spec.rb +24 -0
- data/spec/unit/puppet/parser/functions/merge_spec.rb +47 -0
- data/spec/unit/puppet/parser/functions/min_spec.rb +27 -0
- data/spec/unit/puppet/parser/functions/num2bool_spec.rb +67 -0
- data/spec/unit/puppet/parser/functions/parsejson_spec.rb +22 -0
- data/spec/unit/puppet/parser/functions/parseyaml_spec.rb +24 -0
- data/spec/unit/puppet/parser/functions/pick_spec.rb +34 -0
- data/spec/unit/puppet/parser/functions/prefix_spec.rb +19 -0
- data/spec/unit/puppet/parser/functions/range_spec.rb +34 -0
- data/spec/unit/puppet/parser/functions/reject_spec.rb +20 -0
- data/spec/unit/puppet/parser/functions/reverse_spec.rb +19 -0
- data/spec/unit/puppet/parser/functions/rstrip_spec.rb +24 -0
- data/spec/unit/puppet/parser/functions/shuffle_spec.rb +24 -0
- data/spec/unit/puppet/parser/functions/size_spec.rb +24 -0
- data/spec/unit/puppet/parser/functions/sort_spec.rb +24 -0
- data/spec/unit/puppet/parser/functions/squeeze_spec.rb +24 -0
- data/spec/unit/puppet/parser/functions/str2bool_spec.rb +31 -0
- data/spec/unit/puppet/parser/functions/str2saltedsha512_spec.rb +45 -0
- data/spec/unit/puppet/parser/functions/strftime_spec.rb +29 -0
- data/spec/unit/puppet/parser/functions/strip_spec.rb +18 -0
- data/spec/unit/puppet/parser/functions/suffix_spec.rb +19 -0
- data/spec/unit/puppet/parser/functions/swapcase_spec.rb +19 -0
- data/spec/unit/puppet/parser/functions/time_spec.rb +29 -0
- data/spec/unit/puppet/parser/functions/to_bytes_spec.rb +58 -0
- data/spec/unit/puppet/parser/functions/type_spec.rb +43 -0
- data/spec/unit/puppet/parser/functions/unique_spec.rb +24 -0
- data/spec/unit/puppet/parser/functions/upcase_spec.rb +24 -0
- data/spec/unit/puppet/parser/functions/uriescape_spec.rb +24 -0
- data/spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb +83 -0
- data/spec/unit/puppet/parser/functions/validate_array_spec.rb +38 -0
- data/spec/unit/puppet/parser/functions/validate_augeas_spec.rb +102 -0
- data/spec/unit/puppet/parser/functions/validate_bool_spec.rb +51 -0
- data/spec/unit/puppet/parser/functions/validate_cmd_spec.rb +81 -0
- data/spec/unit/puppet/parser/functions/validate_hash_spec.rb +43 -0
- data/spec/unit/puppet/parser/functions/validate_re_spec.rb +76 -0
- data/spec/unit/puppet/parser/functions/validate_slength_spec.rb +48 -0
- data/spec/unit/puppet/parser/functions/validate_string_spec.rb +60 -0
- data/spec/unit/puppet/parser/functions/values_at_spec.rb +38 -0
- data/spec/unit/puppet/parser/functions/values_spec.rb +31 -0
- data/spec/unit/puppet/parser/functions/zip_spec.rb +15 -0
- data/spec/unit/puppet/provider/file_line/ruby_spec.rb +127 -0
- data/spec/unit/puppet/type/anchor_spec.rb +11 -0
- data/spec/unit/puppet/type/file_line_spec.rb +69 -0
- data/spec/watchr.rb +86 -0
- data/tests/file_line.pp +9 -0
- data/tests/has_interface_with.pp +10 -0
- data/tests/has_ip_address.pp +3 -0
- data/tests/has_ip_network.pp +4 -0
- data/tests/init.pp +1 -0
- metadata +252 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
#! /usr/bin/env ruby -S rspec
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
require 'rspec-puppet'
|
5
|
+
describe 'defined_with_params' do
|
6
|
+
describe 'when a resource is not specified' do
|
7
|
+
it { should run.with_params().and_raise_error(ArgumentError) }
|
8
|
+
end
|
9
|
+
describe 'when compared against a resource with no attributes' do
|
10
|
+
let :pre_condition do
|
11
|
+
'user { "dan": }'
|
12
|
+
end
|
13
|
+
it do
|
14
|
+
should run.with_params('User[dan]', {}).and_return(true)
|
15
|
+
should run.with_params('User[bob]', {}).and_return(false)
|
16
|
+
should run.with_params('User[dan]', {'foo' => 'bar'}).and_return(false)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'when compared against a resource with attributes' do
|
21
|
+
let :pre_condition do
|
22
|
+
'user { "dan": ensure => present, shell => "/bin/csh", managehome => false}'
|
23
|
+
end
|
24
|
+
it do
|
25
|
+
should run.with_params('User[dan]', {}).and_return(true)
|
26
|
+
should run.with_params('User[dan]', '').and_return(true)
|
27
|
+
should run.with_params('User[dan]', {'ensure' => 'present'}
|
28
|
+
).and_return(true)
|
29
|
+
should run.with_params('User[dan]',
|
30
|
+
{'ensure' => 'present', 'managehome' => false}
|
31
|
+
).and_return(true)
|
32
|
+
should run.with_params('User[dan]',
|
33
|
+
{'ensure' => 'absent', 'managehome' => false}
|
34
|
+
).and_return(false)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'rspec-puppet'
|
5
|
+
|
6
|
+
describe 'ensure_packages' do
|
7
|
+
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
8
|
+
|
9
|
+
describe 'argument handling' do
|
10
|
+
it 'fails with no arguments' do
|
11
|
+
should run.with_params().and_raise_error(Puppet::ParseError)
|
12
|
+
end
|
13
|
+
it 'requires an array' do
|
14
|
+
lambda { scope.function_ensure_packages([['foo']]) }.should_not raise_error
|
15
|
+
end
|
16
|
+
it 'fails when given a string' do
|
17
|
+
should run.with_params('foo').and_raise_error(Puppet::ParseError)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'given a catalog containing Package[puppet]{ensure => absent}' do
|
22
|
+
let :pre_condition do
|
23
|
+
'package { puppet: ensure => absent }'
|
24
|
+
end
|
25
|
+
|
26
|
+
# NOTE: should run.with_params has the side effect of making the compiler
|
27
|
+
# available to the test harness.
|
28
|
+
it 'has no effect on Package[puppet]' do
|
29
|
+
should run.with_params(['puppet'])
|
30
|
+
rsrc = compiler.catalog.resource('Package[puppet]')
|
31
|
+
rsrc.to_hash.should == {:ensure => "absent"}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'given a clean catalog' do
|
36
|
+
it 'declares package resources with ensure => present' do
|
37
|
+
should run.with_params(['facter'])
|
38
|
+
rsrc = compiler.catalog.resource('Package[facter]')
|
39
|
+
rsrc.to_hash.should == {:name => "facter", :ensure => "present"}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#! /usr/bin/env ruby -S rspec
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
require 'rspec-puppet'
|
5
|
+
describe 'ensure_resource' do
|
6
|
+
describe 'when a type or title is not specified' do
|
7
|
+
it do
|
8
|
+
should run.with_params().and_raise_error(ArgumentError)
|
9
|
+
should run.with_params(['type']).and_raise_error(ArgumentError)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
describe 'when compared against a resource with no attributes' do
|
13
|
+
let :pre_condition do
|
14
|
+
'user { "dan": }'
|
15
|
+
end
|
16
|
+
it do
|
17
|
+
should run.with_params('user', 'dan', {})
|
18
|
+
compiler.catalog.resource('User[dan]').to_s.should == 'User[dan]'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'when compared against a resource with attributes' do
|
23
|
+
let :pre_condition do
|
24
|
+
'user { "dan": ensure => present, shell => "/bin/csh", managehome => false}'
|
25
|
+
end
|
26
|
+
it do
|
27
|
+
# these first three should not fail
|
28
|
+
should run.with_params('User', 'dan', {})
|
29
|
+
should run.with_params('User', 'dan', '')
|
30
|
+
should run.with_params('User', 'dan', {'ensure' => 'present'})
|
31
|
+
should run.with_params('User', 'dan',
|
32
|
+
{'ensure' => 'present', 'managehome' => false}
|
33
|
+
)
|
34
|
+
# test that this fails
|
35
|
+
should run.with_params('User', 'dan',
|
36
|
+
{'ensure' => 'absent', 'managehome' => false}
|
37
|
+
).and_raise_error(Puppet::Error)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#! /usr/bin/env ruby -S rspec
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
require 'rspec-puppet'
|
5
|
+
describe 'getparam' do
|
6
|
+
describe 'when a resource is not specified' do
|
7
|
+
it do
|
8
|
+
should run.with_params().and_raise_error(ArgumentError)
|
9
|
+
should run.with_params('User[dan]').and_raise_error(ArgumentError)
|
10
|
+
should run.with_params('User[dan]', {}).and_raise_error(ArgumentError)
|
11
|
+
should run.with_params('User[dan]', '').and_return('')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
describe 'when compared against a resource with no params' do
|
15
|
+
let :pre_condition do
|
16
|
+
'user { "dan": }'
|
17
|
+
end
|
18
|
+
it do
|
19
|
+
should run.with_params('User[dan]', 'shell').and_return('')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'when compared against a resource with params' do
|
24
|
+
let :pre_condition do
|
25
|
+
'user { "dan": ensure => present, shell => "/bin/sh", managehome => false}'
|
26
|
+
end
|
27
|
+
it do
|
28
|
+
should run.with_params('User[dan]', 'shell').and_return('/bin/sh')
|
29
|
+
should run.with_params('User[dan]', '').and_return('')
|
30
|
+
should run.with_params('User[dan]', 'ensure').and_return('present')
|
31
|
+
should run.with_params('User[dan]', 'managehome').and_return(false)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Some monkey-patching to allow us to test private methods.
|
2
|
+
class Class
|
3
|
+
def publicize_methods(*methods)
|
4
|
+
saved_private_instance_methods = methods.empty? ? self.private_instance_methods : methods
|
5
|
+
|
6
|
+
self.class_eval { public(*saved_private_instance_methods) }
|
7
|
+
yield
|
8
|
+
self.class_eval { private(*saved_private_instance_methods) }
|
9
|
+
end
|
10
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
dir = File.expand_path(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift File.join(dir, 'lib')
|
3
|
+
|
4
|
+
# Don't want puppet getting the command line arguments for rake or autotest
|
5
|
+
ARGV.clear
|
6
|
+
|
7
|
+
require 'puppet'
|
8
|
+
require 'facter'
|
9
|
+
require 'mocha'
|
10
|
+
gem 'rspec', '>=2.0.0'
|
11
|
+
require 'rspec/expectations'
|
12
|
+
|
13
|
+
require 'puppetlabs_spec_helper/module_spec_helper'
|
14
|
+
|
15
|
+
RSpec.configure do |config|
|
16
|
+
# FIXME REVISIT - We may want to delegate to Facter like we do in
|
17
|
+
# Puppet::PuppetSpecInitializer.initialize_via_testhelper(config) because
|
18
|
+
# this behavior is a duplication of the spec_helper in Facter.
|
19
|
+
config.before :each do
|
20
|
+
# Ensure that we don't accidentally cache facts and environment between
|
21
|
+
# test cases. This requires each example group to explicitly load the
|
22
|
+
# facts being exercised with something like
|
23
|
+
# Facter.collection.loader.load(:ipaddress)
|
24
|
+
Facter::Util::Loader.any_instance.stubs(:load_all)
|
25
|
+
Facter.clear
|
26
|
+
Facter.clear_messages
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
#!/usr/bin/env rspec
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe "PE Version specs" do
|
6
|
+
before :each do
|
7
|
+
# Explicitly load the pe_version.rb file which contains generated facts
|
8
|
+
# that cannot be automatically loaded. Puppet 2.x implements
|
9
|
+
# Facter.collection.load while Facter 1.x markes Facter.collection.load as
|
10
|
+
# a private method.
|
11
|
+
if Facter.collection.respond_to? :load
|
12
|
+
Facter.collection.load(:pe_version)
|
13
|
+
else
|
14
|
+
Facter.collection.loader.load(:pe_version)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "If PE is installed" do
|
19
|
+
%w{ 2.6.1 2.10.300 }.each do |version|
|
20
|
+
puppetversion = "2.7.19 (Puppet Enterprise #{version})"
|
21
|
+
context "puppetversion => #{puppetversion}" do
|
22
|
+
before :each do
|
23
|
+
Facter.fact(:puppetversion).stubs(:value).returns(puppetversion)
|
24
|
+
end
|
25
|
+
|
26
|
+
(major,minor,patch) = version.split(".")
|
27
|
+
|
28
|
+
it "Should return true" do
|
29
|
+
Facter.fact(:is_pe).value.should == true
|
30
|
+
end
|
31
|
+
|
32
|
+
it "Should have a version of #{version}" do
|
33
|
+
Facter.fact(:pe_version).value.should == version
|
34
|
+
end
|
35
|
+
|
36
|
+
it "Should have a major version of #{major}" do
|
37
|
+
Facter.fact(:pe_major_version).value.should == major
|
38
|
+
end
|
39
|
+
|
40
|
+
it "Should have a minor version of #{minor}" do
|
41
|
+
Facter.fact(:pe_minor_version).value.should == minor
|
42
|
+
end
|
43
|
+
|
44
|
+
it "Should have a patch version of #{patch}" do
|
45
|
+
Facter.fact(:pe_patch_version).value.should == patch
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "When PE is not installed" do
|
52
|
+
before :each do
|
53
|
+
Facter.fact(:puppetversion).stubs(:value).returns("2.7.19")
|
54
|
+
end
|
55
|
+
|
56
|
+
it "is_pe is false" do
|
57
|
+
Facter.fact(:is_pe).value.should == false
|
58
|
+
end
|
59
|
+
|
60
|
+
it "pe_version is nil" do
|
61
|
+
Facter.fact(:pe_version).value.should be_nil
|
62
|
+
end
|
63
|
+
|
64
|
+
it "pe_major_version is nil" do
|
65
|
+
Facter.fact(:pe_major_version).value.should be_nil
|
66
|
+
end
|
67
|
+
|
68
|
+
it "pe_minor_version is nil" do
|
69
|
+
Facter.fact(:pe_minor_version).value.should be_nil
|
70
|
+
end
|
71
|
+
|
72
|
+
it "Should have a patch version" do
|
73
|
+
Facter.fact(:pe_patch_version).value.should be_nil
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'facter/root_home'
|
3
|
+
|
4
|
+
describe Facter::Util::RootHome do
|
5
|
+
context "solaris" do
|
6
|
+
let(:root_ent) { "root:x:0:0:Super-User:/:/sbin/sh" }
|
7
|
+
let(:expected_root_home) { "/" }
|
8
|
+
|
9
|
+
it "should return /" do
|
10
|
+
Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(root_ent)
|
11
|
+
Facter::Util::RootHome.get_root_home.should == expected_root_home
|
12
|
+
end
|
13
|
+
end
|
14
|
+
context "linux" do
|
15
|
+
let(:root_ent) { "root:x:0:0:root:/root:/bin/bash" }
|
16
|
+
let(:expected_root_home) { "/root" }
|
17
|
+
|
18
|
+
it "should return /root" do
|
19
|
+
Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(root_ent)
|
20
|
+
Facter::Util::RootHome.get_root_home.should == expected_root_home
|
21
|
+
end
|
22
|
+
end
|
23
|
+
context "macosx" do
|
24
|
+
let(:root_ent) { "root:*:0:0:System Administrator:/var/root:/bin/sh" }
|
25
|
+
let(:expected_root_home) { "/var/root" }
|
26
|
+
|
27
|
+
it "should return /var/root" do
|
28
|
+
Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(root_ent)
|
29
|
+
Facter::Util::RootHome.get_root_home.should == expected_root_home
|
30
|
+
end
|
31
|
+
end
|
32
|
+
context "windows" do
|
33
|
+
before :each do
|
34
|
+
Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(nil)
|
35
|
+
end
|
36
|
+
it "should be nil on windows" do
|
37
|
+
Facter::Util::RootHome.get_root_home.should be_nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'facter/util/puppet_settings'
|
3
|
+
|
4
|
+
describe Facter::Util::PuppetSettings do
|
5
|
+
|
6
|
+
describe "#with_puppet" do
|
7
|
+
context "Without Puppet loaded" do
|
8
|
+
before(:each) do
|
9
|
+
Module.expects(:const_get).with("Puppet").raises(NameError)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should be nil' do
|
13
|
+
subject.with_puppet { Puppet[:vardir] }.should be_nil
|
14
|
+
end
|
15
|
+
it 'should not yield to the block' do
|
16
|
+
Puppet.expects(:[]).never
|
17
|
+
subject.with_puppet { Puppet[:vardir] }.should be_nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
context "With Puppet loaded" do
|
21
|
+
module Puppet; end
|
22
|
+
let(:vardir) { "/var/lib/puppet" }
|
23
|
+
|
24
|
+
before :each do
|
25
|
+
Puppet.expects(:[]).with(:vardir).returns vardir
|
26
|
+
end
|
27
|
+
it 'should yield to the block' do
|
28
|
+
subject.with_puppet { Puppet[:vardir] }
|
29
|
+
end
|
30
|
+
it 'should return the nodes vardir' do
|
31
|
+
subject.with_puppet { Puppet[:vardir] }.should eq vardir
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#! /usr/bin/env ruby -S rspec
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe "the abs function" do
|
6
|
+
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
7
|
+
|
8
|
+
it "should exist" do
|
9
|
+
Puppet::Parser::Functions.function("abs").should == "function_abs"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should raise a ParseError if there is less than 1 arguments" do
|
13
|
+
lambda { scope.function_abs([]) }.should( raise_error(Puppet::ParseError))
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should convert a negative number into a positive" do
|
17
|
+
result = scope.function_abs(["-34"])
|
18
|
+
result.should(eq(34))
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should do nothing with a positive number" do
|
22
|
+
result = scope.function_abs(["5678"])
|
23
|
+
result.should(eq(5678))
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
#! /usr/bin/env ruby -S rspec
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "the any2array function" do
|
5
|
+
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
6
|
+
|
7
|
+
it "should exist" do
|
8
|
+
Puppet::Parser::Functions.function("any2array").should == "function_any2array"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should return an empty array if there is less than 1 argument" do
|
12
|
+
result = scope.function_any2array([])
|
13
|
+
result.should(eq([]))
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should convert boolean true to [ true ] " do
|
17
|
+
result = scope.function_any2array([true])
|
18
|
+
result.should(eq([true]))
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should convert one object to [object]" do
|
22
|
+
result = scope.function_any2array(['one'])
|
23
|
+
result.should(eq(['one']))
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should convert multiple objects to [objects]" do
|
27
|
+
result = scope.function_any2array(['one', 'two'])
|
28
|
+
result.should(eq(['one', 'two']))
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should return empty array it was called with" do
|
32
|
+
result = scope.function_any2array([[]])
|
33
|
+
result.should(eq([]))
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should return one-member array it was called with" do
|
37
|
+
result = scope.function_any2array([['string']])
|
38
|
+
result.should(eq(['string']))
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should return multi-member array it was called with" do
|
42
|
+
result = scope.function_any2array([['one', 'two']])
|
43
|
+
result.should(eq(['one', 'two']))
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should return members of a hash it was called with" do
|
47
|
+
result = scope.function_any2array([{ 'key' => 'value' }])
|
48
|
+
result.should(eq(['key', 'value']))
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should return an empty array if it was called with an empty hash" do
|
52
|
+
result = scope.function_any2array([{ }])
|
53
|
+
result.should(eq([]))
|
54
|
+
end
|
55
|
+
end
|