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,58 @@
|
|
1
|
+
#! /usr/bin/env ruby -S rspec
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe "the to_bytes function" do
|
6
|
+
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
7
|
+
|
8
|
+
it "should exist" do
|
9
|
+
Puppet::Parser::Functions.function("to_bytes").should == "function_to_bytes"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should raise a ParseError if there is less than 1 arguments" do
|
13
|
+
lambda { scope.function_to_bytes([]) }.should( raise_error(Puppet::ParseError))
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should convert kB to B" do
|
17
|
+
result = scope.function_to_bytes(["4 kB"])
|
18
|
+
result.should(eq(4096))
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should work without B in unit" do
|
22
|
+
result = scope.function_to_bytes(["4 k"])
|
23
|
+
result.should(eq(4096))
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should work without a space before unit" do
|
27
|
+
result = scope.function_to_bytes(["4k"])
|
28
|
+
result.should(eq(4096))
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should work without a unit" do
|
32
|
+
result = scope.function_to_bytes(["5678"])
|
33
|
+
result.should(eq(5678))
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should convert fractions" do
|
37
|
+
result = scope.function_to_bytes(["1.5 kB"])
|
38
|
+
result.should(eq(1536))
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should convert scientific notation" do
|
42
|
+
result = scope.function_to_bytes(["1.5e2 B"])
|
43
|
+
result.should(eq(150))
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should do nothing with a positive number" do
|
47
|
+
result = scope.function_to_bytes([5678])
|
48
|
+
result.should(eq(5678))
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should should raise a ParseError if input isn't a number" do
|
52
|
+
lambda { scope.function_to_bytes(["foo"]) }.should( raise_error(Puppet::ParseError))
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should should raise a ParseError if prefix is unknown" do
|
56
|
+
lambda { scope.function_to_bytes(["5 uB"]) }.should( raise_error(Puppet::ParseError))
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#! /usr/bin/env ruby -S rspec
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "the type function" do
|
5
|
+
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
6
|
+
it "should exist" do
|
7
|
+
Puppet::Parser::Functions.function("type").should == "function_type"
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should raise a ParseError if there is less than 1 arguments" do
|
11
|
+
lambda { scope.function_type([]) }.should( raise_error(Puppet::ParseError))
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should return string when given a string" do
|
15
|
+
result = scope.function_type(["aaabbbbcccc"])
|
16
|
+
result.should(eq('string'))
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return array when given an array" do
|
20
|
+
result = scope.function_type([["aaabbbbcccc","asdf"]])
|
21
|
+
result.should(eq('array'))
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should return hash when given a hash" do
|
25
|
+
result = scope.function_type([{"a"=>1,"b"=>2}])
|
26
|
+
result.should(eq('hash'))
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should return integer when given an integer" do
|
30
|
+
result = scope.function_type(["1"])
|
31
|
+
result.should(eq('integer'))
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should return float when given a float" do
|
35
|
+
result = scope.function_type(["1.34"])
|
36
|
+
result.should(eq('float'))
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should return boolean when given a boolean" do
|
40
|
+
result = scope.function_type([true])
|
41
|
+
result.should(eq('boolean'))
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#! /usr/bin/env ruby -S rspec
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "the unique function" do
|
5
|
+
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
6
|
+
|
7
|
+
it "should exist" do
|
8
|
+
Puppet::Parser::Functions.function("unique").should == "function_unique"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should raise a ParseError if there is less than 1 arguments" do
|
12
|
+
lambda { scope.function_unique([]) }.should( raise_error(Puppet::ParseError))
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should remove duplicate elements in a string" do
|
16
|
+
result = scope.function_unique(["aabbc"])
|
17
|
+
result.should(eq('abc'))
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should remove duplicate elements in an array" do
|
21
|
+
result = scope.function_unique([["a","a","b","b","c"]])
|
22
|
+
result.should(eq(['a','b','c']))
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#! /usr/bin/env ruby -S rspec
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "the upcase function" do
|
5
|
+
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
6
|
+
|
7
|
+
it "should exist" do
|
8
|
+
Puppet::Parser::Functions.function("upcase").should == "function_upcase"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should raise a ParseError if there is less than 1 arguments" do
|
12
|
+
lambda { scope.function_upcase([]) }.should( raise_error(Puppet::ParseError))
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should upcase a string" do
|
16
|
+
result = scope.function_upcase(["abc"])
|
17
|
+
result.should(eq('ABC'))
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should do nothing if a string is already upcase" do
|
21
|
+
result = scope.function_upcase(["ABC"])
|
22
|
+
result.should(eq('ABC'))
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#! /usr/bin/env ruby -S rspec
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "the uriescape function" do
|
5
|
+
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
6
|
+
|
7
|
+
it "should exist" do
|
8
|
+
Puppet::Parser::Functions.function("uriescape").should == "function_uriescape"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should raise a ParseError if there is less than 1 arguments" do
|
12
|
+
lambda { scope.function_uriescape([]) }.should( raise_error(Puppet::ParseError))
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should uriescape a string" do
|
16
|
+
result = scope.function_uriescape([":/?#[]@!$&'()*+,;= "])
|
17
|
+
result.should(eq('%3A%2F%3F%23%5B%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D%20'))
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should do nothing if a string is already safe" do
|
21
|
+
result = scope.function_uriescape(["ABCdef"])
|
22
|
+
result.should(eq('ABCdef'))
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Puppet::Parser::Functions.function(:validate_absolute_path) do
|
4
|
+
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
5
|
+
|
6
|
+
# The subject of these examples is the method itself.
|
7
|
+
subject do
|
8
|
+
# This makes sure the function is loaded within each test
|
9
|
+
function_name = Puppet::Parser::Functions.function(:validate_absolute_path)
|
10
|
+
scope.method(function_name)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "Valid Paths" do
|
14
|
+
def self.valid_paths
|
15
|
+
%w{
|
16
|
+
C:/
|
17
|
+
C:\\
|
18
|
+
C:\\WINDOWS\\System32
|
19
|
+
C:/windows/system32
|
20
|
+
X:/foo/bar
|
21
|
+
X:\\foo\\bar
|
22
|
+
/var/tmp
|
23
|
+
/var/lib/puppet
|
24
|
+
/var/opt/../lib/puppet
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
context "Without Puppet::Util.absolute_path? (e.g. Puppet <= 2.6)" do
|
29
|
+
before :each do
|
30
|
+
# The intent here is to mock Puppet to behave like Puppet 2.6 does.
|
31
|
+
# Puppet 2.6 does not have the absolute_path? method. This is only a
|
32
|
+
# convenience test, stdlib should be run with the Puppet 2.6.x in the
|
33
|
+
# $LOAD_PATH in addition to 2.7.x and master.
|
34
|
+
Puppet::Util.expects(:respond_to?).with(:absolute_path?).returns(false)
|
35
|
+
end
|
36
|
+
valid_paths.each do |path|
|
37
|
+
it "validate_absolute_path(#{path.inspect}) should not fail" do
|
38
|
+
expect { subject.call [path] }.not_to raise_error Puppet::ParseError
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "Puppet without mocking" do
|
44
|
+
valid_paths.each do |path|
|
45
|
+
it "validate_absolute_path(#{path.inspect}) should not fail" do
|
46
|
+
expect { subject.call [path] }.not_to raise_error Puppet::ParseError
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe 'Invalid paths' do
|
53
|
+
context 'Garbage inputs' do
|
54
|
+
[
|
55
|
+
nil,
|
56
|
+
[ nil ],
|
57
|
+
{ 'foo' => 'bar' },
|
58
|
+
{ },
|
59
|
+
'',
|
60
|
+
].each do |path|
|
61
|
+
it "validate_absolute_path(#{path.inspect}) should fail" do
|
62
|
+
expect { subject.call [path] }.to raise_error Puppet::ParseError
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'Relative paths' do
|
68
|
+
%w{
|
69
|
+
relative1
|
70
|
+
.
|
71
|
+
..
|
72
|
+
./foo
|
73
|
+
../foo
|
74
|
+
etc/puppetlabs/puppet
|
75
|
+
opt/puppet/bin
|
76
|
+
}.each do |path|
|
77
|
+
it "validate_absolute_path(#{path.inspect}) should fail" do
|
78
|
+
expect { subject.call [path] }.to raise_error Puppet::ParseError
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
#! /usr/bin/env ruby -S rspec
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Puppet::Parser::Functions.function(:validate_array) do
|
6
|
+
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
7
|
+
describe 'when calling validate_array from puppet' do
|
8
|
+
|
9
|
+
%w{ true false }.each do |the_string|
|
10
|
+
it "should not compile when #{the_string} is a string" do
|
11
|
+
Puppet[:code] = "validate_array('#{the_string}')"
|
12
|
+
expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not an Array/)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should not compile when #{the_string} is a bare word" do
|
16
|
+
Puppet[:code] = "validate_array(#{the_string})"
|
17
|
+
expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not an Array/)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should compile when multiple array arguments are passed" do
|
22
|
+
Puppet[:code] = <<-'ENDofPUPPETcode'
|
23
|
+
$foo = [ ]
|
24
|
+
$bar = [ 'one', 'two' ]
|
25
|
+
validate_array($foo, $bar)
|
26
|
+
ENDofPUPPETcode
|
27
|
+
scope.compiler.compile
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should not compile when an undef variable is passed" do
|
31
|
+
Puppet[:code] = <<-'ENDofPUPPETcode'
|
32
|
+
$foo = undef
|
33
|
+
validate_array($foo)
|
34
|
+
ENDofPUPPETcode
|
35
|
+
expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not an Array/)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Puppet::Parser::Functions.function(:validate_augeas), :if => Puppet.features.augeas? do
|
4
|
+
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
5
|
+
|
6
|
+
# The subject of these examplres is the method itself.
|
7
|
+
subject do
|
8
|
+
# This makes sure the function is loaded within each test
|
9
|
+
function_name = Puppet::Parser::Functions.function(:validate_augeas)
|
10
|
+
scope.method(function_name)
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'Using Puppet::Parser::Scope.new' do
|
14
|
+
|
15
|
+
describe 'Garbage inputs' do
|
16
|
+
inputs = [
|
17
|
+
[ nil ],
|
18
|
+
[ [ nil ] ],
|
19
|
+
[ { 'foo' => 'bar' } ],
|
20
|
+
[ { } ],
|
21
|
+
[ '' ],
|
22
|
+
[ "one", "one", "MSG to User", "4th arg" ],
|
23
|
+
]
|
24
|
+
|
25
|
+
inputs.each do |input|
|
26
|
+
it "validate_augeas(#{input.inspect}) should fail" do
|
27
|
+
expect { subject.call [input] }.to raise_error Puppet::ParseError
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'Valid inputs' do
|
33
|
+
inputs = [
|
34
|
+
[ "root:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns' ],
|
35
|
+
[ "proc /proc proc nodev,noexec,nosuid 0 0\n", 'Fstab.lns'],
|
36
|
+
]
|
37
|
+
|
38
|
+
inputs.each do |input|
|
39
|
+
it "validate_augeas(#{input.inspect}) should not fail" do
|
40
|
+
expect { subject.call input }.not_to raise_error
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "Valid inputs which should raise an exception without a message" do
|
46
|
+
# The intent here is to make sure valid inputs raise exceptions when they
|
47
|
+
# don't specify an error message to display. This is the behvior in
|
48
|
+
# 2.2.x and prior.
|
49
|
+
inputs = [
|
50
|
+
[ "root:x:0:0:root\n", 'Passwd.lns' ],
|
51
|
+
[ "127.0.1.1\n", 'Hosts.lns' ],
|
52
|
+
]
|
53
|
+
|
54
|
+
inputs.each do |input|
|
55
|
+
it "validate_augeas(#{input.inspect}) should fail" do
|
56
|
+
expect { subject.call input }.to raise_error /validate_augeas.*?matched less than it should/
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "Nicer Error Messages" do
|
62
|
+
# The intent here is to make sure the function returns the 3rd argument
|
63
|
+
# in the exception thrown
|
64
|
+
inputs = [
|
65
|
+
[ "root:x:0:0:root\n", 'Passwd.lns', [], 'Failed to validate passwd content' ],
|
66
|
+
[ "127.0.1.1\n", 'Hosts.lns', [], 'Wrong hosts content' ],
|
67
|
+
]
|
68
|
+
|
69
|
+
inputs.each do |input|
|
70
|
+
it "validate_augeas(#{input.inspect}) should fail" do
|
71
|
+
expect { subject.call input }.to raise_error /#{input[2]}/
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "Passing simple unit tests" do
|
77
|
+
inputs = [
|
78
|
+
[ "root:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns', ['$file/foobar']],
|
79
|
+
[ "root:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns', ['$file/root/shell[.="/bin/sh"]', 'foobar']],
|
80
|
+
]
|
81
|
+
|
82
|
+
inputs.each do |input|
|
83
|
+
it "validate_augeas(#{input.inspect}) should fail" do
|
84
|
+
expect { subject.call input }.not_to raise_error
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "Failing simple unit tests" do
|
90
|
+
inputs = [
|
91
|
+
[ "foobar:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns', ['$file/foobar']],
|
92
|
+
[ "root:x:0:0:root:/root:/bin/sh\n", 'Passwd.lns', ['$file/root/shell[.="/bin/sh"]', 'foobar']],
|
93
|
+
]
|
94
|
+
|
95
|
+
inputs.each do |input|
|
96
|
+
it "validate_augeas(#{input.inspect}) should fail" do
|
97
|
+
expect { subject.call input }.to raise_error /testing path/
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#! /usr/bin/env/ruby -S rspec
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Puppet::Parser::Functions.function(:validate_bool) do
|
6
|
+
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
7
|
+
describe 'when calling validate_bool from puppet' do
|
8
|
+
|
9
|
+
%w{ true false }.each do |the_string|
|
10
|
+
|
11
|
+
it "should not compile when #{the_string} is a string" do
|
12
|
+
Puppet[:code] = "validate_bool('#{the_string}')"
|
13
|
+
expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a boolean/)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should compile when #{the_string} is a bare word" do
|
17
|
+
Puppet[:code] = "validate_bool(#{the_string})"
|
18
|
+
scope.compiler.compile
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should not compile when an arbitrary string is passed" do
|
24
|
+
Puppet[:code] = 'validate_bool("jeff and dan are awesome")'
|
25
|
+
expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a boolean/)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should not compile when no arguments are passed" do
|
29
|
+
Puppet[:code] = 'validate_bool()'
|
30
|
+
expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /wrong number of arguments/)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should compile when multiple boolean arguments are passed" do
|
34
|
+
Puppet[:code] = <<-'ENDofPUPPETcode'
|
35
|
+
$foo = true
|
36
|
+
$bar = false
|
37
|
+
validate_bool($foo, $bar, true, false)
|
38
|
+
ENDofPUPPETcode
|
39
|
+
scope.compiler.compile
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should compile when multiple boolean arguments are passed" do
|
43
|
+
Puppet[:code] = <<-'ENDofPUPPETcode'
|
44
|
+
$foo = true
|
45
|
+
$bar = false
|
46
|
+
validate_bool($foo, $bar, true, false, 'jeff')
|
47
|
+
ENDofPUPPETcode
|
48
|
+
expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a boolean/)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|