puppetmodule-stdlib 4.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (200) hide show
  1. data/CHANGELOG +253 -0
  2. data/CONTRIBUTING.md +65 -0
  3. data/Gemfile +33 -0
  4. data/LICENSE +19 -0
  5. data/Modulefile +11 -0
  6. data/README.markdown +1173 -0
  7. data/README_DEVELOPER.markdown +35 -0
  8. data/RELEASE_PROCESS.markdown +24 -0
  9. data/Rakefile +2 -0
  10. data/lib/facter/pe_version.rb +53 -0
  11. data/lib/facter/puppet_vardir.rb +26 -0
  12. data/lib/facter/root_home.rb +19 -0
  13. data/lib/facter/util/puppet_settings.rb +21 -0
  14. data/lib/puppet/parser/functions/abs.rb +36 -0
  15. data/lib/puppet/parser/functions/any2array.rb +33 -0
  16. data/lib/puppet/parser/functions/bool2num.rb +49 -0
  17. data/lib/puppet/parser/functions/capitalize.rb +34 -0
  18. data/lib/puppet/parser/functions/chomp.rb +35 -0
  19. data/lib/puppet/parser/functions/chop.rb +37 -0
  20. data/lib/puppet/parser/functions/concat.rb +37 -0
  21. data/lib/puppet/parser/functions/count.rb +22 -0
  22. data/lib/puppet/parser/functions/defined_with_params.rb +35 -0
  23. data/lib/puppet/parser/functions/delete.rb +46 -0
  24. data/lib/puppet/parser/functions/delete_at.rb +49 -0
  25. data/lib/puppet/parser/functions/downcase.rb +33 -0
  26. data/lib/puppet/parser/functions/empty.rb +28 -0
  27. data/lib/puppet/parser/functions/ensure_packages.rb +24 -0
  28. data/lib/puppet/parser/functions/ensure_resource.rb +35 -0
  29. data/lib/puppet/parser/functions/flatten.rb +33 -0
  30. data/lib/puppet/parser/functions/floor.rb +20 -0
  31. data/lib/puppet/parser/functions/fqdn_rotate.rb +46 -0
  32. data/lib/puppet/parser/functions/get_module_path.rb +17 -0
  33. data/lib/puppet/parser/functions/getparam.rb +35 -0
  34. data/lib/puppet/parser/functions/getvar.rb +26 -0
  35. data/lib/puppet/parser/functions/grep.rb +33 -0
  36. data/lib/puppet/parser/functions/has_interface_with.rb +52 -0
  37. data/lib/puppet/parser/functions/has_ip_address.rb +25 -0
  38. data/lib/puppet/parser/functions/has_ip_network.rb +25 -0
  39. data/lib/puppet/parser/functions/has_key.rb +28 -0
  40. data/lib/puppet/parser/functions/hash.rb +41 -0
  41. data/lib/puppet/parser/functions/is_array.rb +22 -0
  42. data/lib/puppet/parser/functions/is_domain_name.rb +47 -0
  43. data/lib/puppet/parser/functions/is_float.rb +27 -0
  44. data/lib/puppet/parser/functions/is_function_available.rb +23 -0
  45. data/lib/puppet/parser/functions/is_hash.rb +22 -0
  46. data/lib/puppet/parser/functions/is_integer.rb +27 -0
  47. data/lib/puppet/parser/functions/is_ip_address.rb +32 -0
  48. data/lib/puppet/parser/functions/is_mac_address.rb +27 -0
  49. data/lib/puppet/parser/functions/is_numeric.rb +27 -0
  50. data/lib/puppet/parser/functions/is_string.rb +26 -0
  51. data/lib/puppet/parser/functions/join.rb +41 -0
  52. data/lib/puppet/parser/functions/join_keys_to_values.rb +47 -0
  53. data/lib/puppet/parser/functions/keys.rb +26 -0
  54. data/lib/puppet/parser/functions/loadyaml.rb +20 -0
  55. data/lib/puppet/parser/functions/lstrip.rb +33 -0
  56. data/lib/puppet/parser/functions/max.rb +21 -0
  57. data/lib/puppet/parser/functions/member.rb +44 -0
  58. data/lib/puppet/parser/functions/merge.rb +33 -0
  59. data/lib/puppet/parser/functions/min.rb +21 -0
  60. data/lib/puppet/parser/functions/num2bool.rb +43 -0
  61. data/lib/puppet/parser/functions/parsejson.rb +24 -0
  62. data/lib/puppet/parser/functions/parseyaml.rb +24 -0
  63. data/lib/puppet/parser/functions/pick.rb +29 -0
  64. data/lib/puppet/parser/functions/prefix.rb +45 -0
  65. data/lib/puppet/parser/functions/range.rb +80 -0
  66. data/lib/puppet/parser/functions/reject.rb +31 -0
  67. data/lib/puppet/parser/functions/reverse.rb +28 -0
  68. data/lib/puppet/parser/functions/rstrip.rb +32 -0
  69. data/lib/puppet/parser/functions/shuffle.rb +46 -0
  70. data/lib/puppet/parser/functions/size.rb +48 -0
  71. data/lib/puppet/parser/functions/sort.rb +27 -0
  72. data/lib/puppet/parser/functions/squeeze.rb +36 -0
  73. data/lib/puppet/parser/functions/str2bool.rb +46 -0
  74. data/lib/puppet/parser/functions/str2saltedsha512.rb +32 -0
  75. data/lib/puppet/parser/functions/strftime.rb +107 -0
  76. data/lib/puppet/parser/functions/strip.rb +39 -0
  77. data/lib/puppet/parser/functions/suffix.rb +45 -0
  78. data/lib/puppet/parser/functions/swapcase.rb +39 -0
  79. data/lib/puppet/parser/functions/time.rb +49 -0
  80. data/lib/puppet/parser/functions/to_bytes.rb +28 -0
  81. data/lib/puppet/parser/functions/type.rb +50 -0
  82. data/lib/puppet/parser/functions/unique.rb +51 -0
  83. data/lib/puppet/parser/functions/upcase.rb +41 -0
  84. data/lib/puppet/parser/functions/uriescape.rb +36 -0
  85. data/lib/puppet/parser/functions/validate_absolute_path.rb +56 -0
  86. data/lib/puppet/parser/functions/validate_array.rb +33 -0
  87. data/lib/puppet/parser/functions/validate_augeas.rb +81 -0
  88. data/lib/puppet/parser/functions/validate_bool.rb +34 -0
  89. data/lib/puppet/parser/functions/validate_cmd.rb +47 -0
  90. data/lib/puppet/parser/functions/validate_hash.rb +33 -0
  91. data/lib/puppet/parser/functions/validate_re.rb +40 -0
  92. data/lib/puppet/parser/functions/validate_slength.rb +52 -0
  93. data/lib/puppet/parser/functions/validate_string.rb +33 -0
  94. data/lib/puppet/parser/functions/values.rb +39 -0
  95. data/lib/puppet/parser/functions/values_at.rb +98 -0
  96. data/lib/puppet/parser/functions/zip.rb +65 -0
  97. data/lib/puppet/provider/file_line/ruby.rb +59 -0
  98. data/lib/puppet/type/anchor.rb +41 -0
  99. data/lib/puppet/type/file_line.rb +70 -0
  100. data/manifests/init.pp +20 -0
  101. data/manifests/stages.pp +43 -0
  102. data/spec/functions/defined_with_params_spec.rb +37 -0
  103. data/spec/functions/ensure_packages_spec.rb +42 -0
  104. data/spec/functions/ensure_resource_spec.rb +40 -0
  105. data/spec/functions/getparam_spec.rb +34 -0
  106. data/spec/monkey_patches/alias_should_to_must.rb +8 -0
  107. data/spec/monkey_patches/publicize_methods.rb +10 -0
  108. data/spec/spec.opts +6 -0
  109. data/spec/spec_helper.rb +28 -0
  110. data/spec/unit/facter/pe_version_spec.rb +76 -0
  111. data/spec/unit/facter/root_home_spec.rb +40 -0
  112. data/spec/unit/facter/util/puppet_settings_spec.rb +35 -0
  113. data/spec/unit/puppet/parser/functions/abs_spec.rb +25 -0
  114. data/spec/unit/puppet/parser/functions/any2array_spec.rb +55 -0
  115. data/spec/unit/puppet/parser/functions/bool2num_spec.rb +24 -0
  116. data/spec/unit/puppet/parser/functions/capitalize_spec.rb +19 -0
  117. data/spec/unit/puppet/parser/functions/chomp_spec.rb +19 -0
  118. data/spec/unit/puppet/parser/functions/chop_spec.rb +19 -0
  119. data/spec/unit/puppet/parser/functions/concat_spec.rb +15 -0
  120. data/spec/unit/puppet/parser/functions/count_spec.rb +31 -0
  121. data/spec/unit/puppet/parser/functions/delete_at_spec.rb +19 -0
  122. data/spec/unit/puppet/parser/functions/delete_spec.rb +38 -0
  123. data/spec/unit/puppet/parser/functions/downcase_spec.rb +24 -0
  124. data/spec/unit/puppet/parser/functions/empty_spec.rb +23 -0
  125. data/spec/unit/puppet/parser/functions/flatten_spec.rb +27 -0
  126. data/spec/unit/puppet/parser/functions/floor_spec.rb +39 -0
  127. data/spec/unit/puppet/parser/functions/fqdn_rotate_spec.rb +33 -0
  128. data/spec/unit/puppet/parser/functions/get_module_path_spec.rb +46 -0
  129. data/spec/unit/puppet/parser/functions/getvar_spec.rb +37 -0
  130. data/spec/unit/puppet/parser/functions/grep_spec.rb +19 -0
  131. data/spec/unit/puppet/parser/functions/has_interface_with_spec.rb +64 -0
  132. data/spec/unit/puppet/parser/functions/has_ip_address_spec.rb +39 -0
  133. data/spec/unit/puppet/parser/functions/has_ip_network_spec.rb +36 -0
  134. data/spec/unit/puppet/parser/functions/has_key_spec.rb +42 -0
  135. data/spec/unit/puppet/parser/functions/hash_spec.rb +19 -0
  136. data/spec/unit/puppet/parser/functions/is_array_spec.rb +29 -0
  137. data/spec/unit/puppet/parser/functions/is_domain_name_spec.rb +64 -0
  138. data/spec/unit/puppet/parser/functions/is_float_spec.rb +33 -0
  139. data/spec/unit/puppet/parser/functions/is_function_available.rb +31 -0
  140. data/spec/unit/puppet/parser/functions/is_hash_spec.rb +29 -0
  141. data/spec/unit/puppet/parser/functions/is_integer_spec.rb +34 -0
  142. data/spec/unit/puppet/parser/functions/is_ip_address_spec.rb +39 -0
  143. data/spec/unit/puppet/parser/functions/is_mac_address_spec.rb +29 -0
  144. data/spec/unit/puppet/parser/functions/is_numeric_spec.rb +39 -0
  145. data/spec/unit/puppet/parser/functions/is_string_spec.rb +34 -0
  146. data/spec/unit/puppet/parser/functions/join_keys_to_values_spec.rb +40 -0
  147. data/spec/unit/puppet/parser/functions/join_spec.rb +19 -0
  148. data/spec/unit/puppet/parser/functions/keys_spec.rb +21 -0
  149. data/spec/unit/puppet/parser/functions/lstrip_spec.rb +19 -0
  150. data/spec/unit/puppet/parser/functions/max_spec.rb +27 -0
  151. data/spec/unit/puppet/parser/functions/member_spec.rb +24 -0
  152. data/spec/unit/puppet/parser/functions/merge_spec.rb +47 -0
  153. data/spec/unit/puppet/parser/functions/min_spec.rb +27 -0
  154. data/spec/unit/puppet/parser/functions/num2bool_spec.rb +67 -0
  155. data/spec/unit/puppet/parser/functions/parsejson_spec.rb +22 -0
  156. data/spec/unit/puppet/parser/functions/parseyaml_spec.rb +24 -0
  157. data/spec/unit/puppet/parser/functions/pick_spec.rb +34 -0
  158. data/spec/unit/puppet/parser/functions/prefix_spec.rb +19 -0
  159. data/spec/unit/puppet/parser/functions/range_spec.rb +34 -0
  160. data/spec/unit/puppet/parser/functions/reject_spec.rb +20 -0
  161. data/spec/unit/puppet/parser/functions/reverse_spec.rb +19 -0
  162. data/spec/unit/puppet/parser/functions/rstrip_spec.rb +24 -0
  163. data/spec/unit/puppet/parser/functions/shuffle_spec.rb +24 -0
  164. data/spec/unit/puppet/parser/functions/size_spec.rb +24 -0
  165. data/spec/unit/puppet/parser/functions/sort_spec.rb +24 -0
  166. data/spec/unit/puppet/parser/functions/squeeze_spec.rb +24 -0
  167. data/spec/unit/puppet/parser/functions/str2bool_spec.rb +31 -0
  168. data/spec/unit/puppet/parser/functions/str2saltedsha512_spec.rb +45 -0
  169. data/spec/unit/puppet/parser/functions/strftime_spec.rb +29 -0
  170. data/spec/unit/puppet/parser/functions/strip_spec.rb +18 -0
  171. data/spec/unit/puppet/parser/functions/suffix_spec.rb +19 -0
  172. data/spec/unit/puppet/parser/functions/swapcase_spec.rb +19 -0
  173. data/spec/unit/puppet/parser/functions/time_spec.rb +29 -0
  174. data/spec/unit/puppet/parser/functions/to_bytes_spec.rb +58 -0
  175. data/spec/unit/puppet/parser/functions/type_spec.rb +43 -0
  176. data/spec/unit/puppet/parser/functions/unique_spec.rb +24 -0
  177. data/spec/unit/puppet/parser/functions/upcase_spec.rb +24 -0
  178. data/spec/unit/puppet/parser/functions/uriescape_spec.rb +24 -0
  179. data/spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb +83 -0
  180. data/spec/unit/puppet/parser/functions/validate_array_spec.rb +38 -0
  181. data/spec/unit/puppet/parser/functions/validate_augeas_spec.rb +102 -0
  182. data/spec/unit/puppet/parser/functions/validate_bool_spec.rb +51 -0
  183. data/spec/unit/puppet/parser/functions/validate_cmd_spec.rb +81 -0
  184. data/spec/unit/puppet/parser/functions/validate_hash_spec.rb +43 -0
  185. data/spec/unit/puppet/parser/functions/validate_re_spec.rb +76 -0
  186. data/spec/unit/puppet/parser/functions/validate_slength_spec.rb +48 -0
  187. data/spec/unit/puppet/parser/functions/validate_string_spec.rb +60 -0
  188. data/spec/unit/puppet/parser/functions/values_at_spec.rb +38 -0
  189. data/spec/unit/puppet/parser/functions/values_spec.rb +31 -0
  190. data/spec/unit/puppet/parser/functions/zip_spec.rb +15 -0
  191. data/spec/unit/puppet/provider/file_line/ruby_spec.rb +127 -0
  192. data/spec/unit/puppet/type/anchor_spec.rb +11 -0
  193. data/spec/unit/puppet/type/file_line_spec.rb +69 -0
  194. data/spec/watchr.rb +86 -0
  195. data/tests/file_line.pp +9 -0
  196. data/tests/has_interface_with.pp +10 -0
  197. data/tests/has_ip_address.pp +3 -0
  198. data/tests/has_ip_network.pp +4 -0
  199. data/tests/init.pp +1 -0
  200. 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,8 @@
1
+ require 'rspec'
2
+
3
+ class Object
4
+ # This is necessary because the RAL has a 'should'
5
+ # method.
6
+ alias :must :should
7
+ alias :must_not :should_not
8
+ 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
@@ -0,0 +1,6 @@
1
+ --format
2
+ s
3
+ --colour
4
+ --loadby
5
+ mtime
6
+ --backtrace
@@ -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