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,29 @@
|
|
1
|
+
#! /usr/bin/env ruby -S rspec
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "the is_mac_address function" do
|
5
|
+
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
6
|
+
|
7
|
+
it "should exist" do
|
8
|
+
Puppet::Parser::Functions.function("is_mac_address").should == "function_is_mac_address"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should raise a ParseError if there is less than 1 arguments" do
|
12
|
+
lambda { scope.function_is_mac_address([]) }.should( raise_error(Puppet::ParseError))
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return true if a valid mac address" do
|
16
|
+
result = scope.function_is_mac_address(["00:a0:1f:12:7f:a0"])
|
17
|
+
result.should(eq(true))
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should return false if octets are out of range" do
|
21
|
+
result = scope.function_is_mac_address(["00:a0:1f:12:7f:g0"])
|
22
|
+
result.should(eq(false))
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return false if not valid" do
|
26
|
+
result = scope.function_is_mac_address(["not valid"])
|
27
|
+
result.should(eq(false))
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#! /usr/bin/env ruby -S rspec
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "the is_numeric function" do
|
5
|
+
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
6
|
+
|
7
|
+
it "should exist" do
|
8
|
+
Puppet::Parser::Functions.function("is_numeric").should == "function_is_numeric"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should raise a ParseError if there is less than 1 argument" do
|
12
|
+
lambda { scope.function_is_numeric([]) }.should( raise_error(Puppet::ParseError))
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return true if an integer" do
|
16
|
+
result = scope.function_is_numeric(["3"])
|
17
|
+
result.should(eq(true))
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should return true if a float" do
|
21
|
+
result = scope.function_is_numeric(["3.2"])
|
22
|
+
result.should(eq(true))
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return true if an integer is created from an arithmetical operation" do
|
26
|
+
result = scope.function_is_numeric([3*2])
|
27
|
+
result.should(eq(true))
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should return true if a float is created from an arithmetical operation" do
|
31
|
+
result = scope.function_is_numeric([3.2*2])
|
32
|
+
result.should(eq(true))
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should return false if a string" do
|
36
|
+
result = scope.function_is_numeric(["asdf"])
|
37
|
+
result.should(eq(false))
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#! /usr/bin/env ruby -S rspec
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "the is_string function" do
|
5
|
+
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
6
|
+
|
7
|
+
it "should exist" do
|
8
|
+
Puppet::Parser::Functions.function("is_string").should == "function_is_string"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should raise a ParseError if there is less than 1 arguments" do
|
12
|
+
lambda { scope.function_is_string([]) }.should( raise_error(Puppet::ParseError))
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return true if a string" do
|
16
|
+
result = scope.function_is_string(["asdf"])
|
17
|
+
result.should(eq(true))
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should return false if an integer" do
|
21
|
+
result = scope.function_is_string(["3"])
|
22
|
+
result.should(eq(false))
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return false if a float" do
|
26
|
+
result = scope.function_is_string(["3.23"])
|
27
|
+
result.should(eq(false))
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should return false if an array" do
|
31
|
+
result = scope.function_is_string([["a","b","c"]])
|
32
|
+
result.should(eq(false))
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#! /usr/bin/env ruby -S rspec
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "the join_keys_to_values function" do
|
5
|
+
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
6
|
+
|
7
|
+
it "should exist" do
|
8
|
+
Puppet::Parser::Functions.function("join_keys_to_values").should == "function_join_keys_to_values"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should raise a ParseError if there are fewer than two arguments" do
|
12
|
+
lambda { scope.function_join_keys_to_values([{}]) }.should raise_error Puppet::ParseError
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should raise a ParseError if there are greater than two arguments" do
|
16
|
+
lambda { scope.function_join_keys_to_values([{}, 'foo', 'bar']) }.should raise_error Puppet::ParseError
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should raise a TypeError if the first argument is an array" do
|
20
|
+
lambda { scope.function_join_keys_to_values([[1,2], ',']) }.should raise_error TypeError
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should raise a TypeError if the second argument is an array" do
|
24
|
+
lambda { scope.function_join_keys_to_values([{}, [1,2]]) }.should raise_error TypeError
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should raise a TypeError if the second argument is a number" do
|
28
|
+
lambda { scope.function_join_keys_to_values([{}, 1]) }.should raise_error TypeError
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should return an empty array given an empty hash" do
|
32
|
+
result = scope.function_join_keys_to_values([{}, ":"])
|
33
|
+
result.should == []
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should join hash's keys to its values" do
|
37
|
+
result = scope.function_join_keys_to_values([{'a'=>1,2=>'foo',:b=>nil}, ":"])
|
38
|
+
result.should =~ ['a:1','2:foo','b:']
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#! /usr/bin/env ruby -S rspec
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "the join function" do
|
5
|
+
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
6
|
+
|
7
|
+
it "should exist" do
|
8
|
+
Puppet::Parser::Functions.function("join").should == "function_join"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should raise a ParseError if there is less than 1 arguments" do
|
12
|
+
lambda { scope.function_join([]) }.should( raise_error(Puppet::ParseError))
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should join an array into a string" do
|
16
|
+
result = scope.function_join([["a","b","c"], ":"])
|
17
|
+
result.should(eq("a:b:c"))
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#! /usr/bin/env ruby -S rspec
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "the keys function" do
|
5
|
+
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
6
|
+
|
7
|
+
it "should exist" do
|
8
|
+
Puppet::Parser::Functions.function("keys").should == "function_keys"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should raise a ParseError if there is less than 1 arguments" do
|
12
|
+
lambda { scope.function_keys([]) }.should( raise_error(Puppet::ParseError))
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return an array of keys when given a hash" do
|
16
|
+
result = scope.function_keys([{'a'=>1, 'b'=>2}])
|
17
|
+
# =~ performs 'array with same elements' (set) matching
|
18
|
+
# For more info see RSpec::Matchers::MatchArray
|
19
|
+
result.should =~ ['a','b']
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#! /usr/bin/env ruby -S rspec
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "the lstrip function" do
|
5
|
+
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
6
|
+
|
7
|
+
it "should exist" do
|
8
|
+
Puppet::Parser::Functions.function("lstrip").should == "function_lstrip"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should raise a ParseError if there is less than 1 arguments" do
|
12
|
+
lambda { scope.function_lstrip([]) }.should( raise_error(Puppet::ParseError))
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should lstrip a string" do
|
16
|
+
result = scope.function_lstrip([" asdf"])
|
17
|
+
result.should(eq('asdf'))
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#! /usr/bin/env ruby -S rspec
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe "the max function" do
|
6
|
+
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
7
|
+
|
8
|
+
it "should exist" do
|
9
|
+
Puppet::Parser::Functions.function("max").should == "function_max"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should raise a ParseError if there is less than 1 arguments" do
|
13
|
+
lambda { scope.function_max([]) }.should( raise_error(Puppet::ParseError))
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should be able to compare strings" do
|
17
|
+
scope.function_max(["albatross","dog","horse"]).should(eq("horse"))
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should be able to compare numbers" do
|
21
|
+
scope.function_max([6,8,4]).should(eq(8))
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should be able to compare a number with a stringified number" do
|
25
|
+
scope.function_max([1,"2"]).should(eq("2"))
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#! /usr/bin/env ruby -S rspec
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "the member function" do
|
5
|
+
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
6
|
+
|
7
|
+
it "should exist" do
|
8
|
+
Puppet::Parser::Functions.function("member").should == "function_member"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should raise a ParseError if there is less than 1 arguments" do
|
12
|
+
lambda { scope.function_member([]) }.should( raise_error(Puppet::ParseError))
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return true if a member is in an array" do
|
16
|
+
result = scope.function_member([["a","b","c"], "a"])
|
17
|
+
result.should(eq(true))
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should return false if a member is not in an array" do
|
21
|
+
result = scope.function_member([["a","b","c"], "d"])
|
22
|
+
result.should(eq(false))
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
#! /usr/bin/env ruby -S rspec
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Puppet::Parser::Functions.function(:merge) do
|
6
|
+
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
7
|
+
|
8
|
+
describe 'when calling merge from puppet' do
|
9
|
+
it "should not compile when no arguments are passed" do
|
10
|
+
pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
|
11
|
+
Puppet[:code] = '$x = merge()'
|
12
|
+
expect {
|
13
|
+
scope.compiler.compile
|
14
|
+
}.to raise_error(Puppet::ParseError, /wrong number of arguments/)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should not compile when 1 argument is passed" do
|
18
|
+
pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
|
19
|
+
Puppet[:code] = "$my_hash={'one' => 1}\n$x = merge($my_hash)"
|
20
|
+
expect {
|
21
|
+
scope.compiler.compile
|
22
|
+
}.to raise_error(Puppet::ParseError, /wrong number of arguments/)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'when calling merge on the scope instance' do
|
27
|
+
it 'should require all parameters are hashes' do
|
28
|
+
expect { new_hash = scope.function_merge([{}, '2'])}.to raise_error(Puppet::ParseError, /unexpected argument type String/)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should be able to merge two hashes' do
|
32
|
+
new_hash = scope.function_merge([{'one' => '1', 'two' => '1'}, {'two' => '2', 'three' => '2'}])
|
33
|
+
new_hash['one'].should == '1'
|
34
|
+
new_hash['two'].should == '2'
|
35
|
+
new_hash['three'].should == '2'
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should merge multiple hashes' do
|
39
|
+
hash = scope.function_merge([{'one' => 1}, {'one' => '2'}, {'one' => '3'}])
|
40
|
+
hash['one'].should == '3'
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should accept empty hashes' do
|
44
|
+
scope.function_merge([{},{},{}]).should == {}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#! /usr/bin/env ruby -S rspec
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe "the min function" do
|
6
|
+
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
7
|
+
|
8
|
+
it "should exist" do
|
9
|
+
Puppet::Parser::Functions.function("min").should == "function_min"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should raise a ParseError if there is less than 1 arguments" do
|
13
|
+
lambda { scope.function_min([]) }.should( raise_error(Puppet::ParseError))
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should be able to compare strings" do
|
17
|
+
scope.function_min(["albatross","dog","horse"]).should(eq("albatross"))
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should be able to compare numbers" do
|
21
|
+
scope.function_min([6,8,4]).should(eq(4))
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should be able to compare a number with a stringified number" do
|
25
|
+
scope.function_min([1,"2"]).should(eq(1))
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
#! /usr/bin/env ruby -S rspec
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "the num2bool function" do
|
5
|
+
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
6
|
+
|
7
|
+
it "should exist" do
|
8
|
+
Puppet::Parser::Functions.function("num2bool").should == "function_num2bool"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should raise a ParseError if there are no arguments" do
|
12
|
+
lambda { scope.function_num2bool([]) }.should( raise_error(Puppet::ParseError))
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should raise a ParseError if there are more than 1 arguments" do
|
16
|
+
lambda { scope.function_num2bool(["foo","bar"]) }.should( raise_error(Puppet::ParseError))
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should raise a ParseError if passed something non-numeric" do
|
20
|
+
lambda { scope.function_num2bool(["xyzzy"]) }.should( raise_error(Puppet::ParseError))
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should return true if passed string 1" do
|
24
|
+
result = scope.function_num2bool(["1"])
|
25
|
+
result.should(be_true)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should return true if passed string 1.5" do
|
29
|
+
result = scope.function_num2bool(["1.5"])
|
30
|
+
result.should(be_true)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should return true if passed number 1" do
|
34
|
+
result = scope.function_num2bool([1])
|
35
|
+
result.should(be_true)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should return false if passed string 0" do
|
39
|
+
result = scope.function_num2bool(["0"])
|
40
|
+
result.should(be_false)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should return false if passed number 0" do
|
44
|
+
result = scope.function_num2bool([0])
|
45
|
+
result.should(be_false)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should return false if passed string -1" do
|
49
|
+
result = scope.function_num2bool(["-1"])
|
50
|
+
result.should(be_false)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should return false if passed string -1.5" do
|
54
|
+
result = scope.function_num2bool(["-1.5"])
|
55
|
+
result.should(be_false)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should return false if passed number -1" do
|
59
|
+
result = scope.function_num2bool([-1])
|
60
|
+
result.should(be_false)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should return false if passed float -1.5" do
|
64
|
+
result = scope.function_num2bool([-1.5])
|
65
|
+
result.should(be_false)
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#! /usr/bin/env ruby -S rspec
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "the parsejson function" do
|
5
|
+
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
6
|
+
|
7
|
+
it "should exist" do
|
8
|
+
Puppet::Parser::Functions.function("parsejson").should == "function_parsejson"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should raise a ParseError if there is less than 1 arguments" do
|
12
|
+
lambda { scope.function_parsejson([]) }.should( raise_error(Puppet::ParseError))
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should convert JSON to a data structure" do
|
16
|
+
json = <<-EOS
|
17
|
+
["aaa","bbb","ccc"]
|
18
|
+
EOS
|
19
|
+
result = scope.function_parsejson([json])
|
20
|
+
result.should(eq(['aaa','bbb','ccc']))
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#! /usr/bin/env ruby -S rspec
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "the parseyaml function" do
|
5
|
+
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
6
|
+
|
7
|
+
it "should exist" do
|
8
|
+
Puppet::Parser::Functions.function("parseyaml").should == "function_parseyaml"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should raise a ParseError if there is less than 1 arguments" do
|
12
|
+
lambda { scope.function_parseyaml([]) }.should( raise_error(Puppet::ParseError))
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should convert YAML to a data structure" do
|
16
|
+
yaml = <<-EOS
|
17
|
+
- aaa
|
18
|
+
- bbb
|
19
|
+
- ccc
|
20
|
+
EOS
|
21
|
+
result = scope.function_parseyaml([yaml])
|
22
|
+
result.should(eq(['aaa','bbb','ccc']))
|
23
|
+
end
|
24
|
+
end
|