puppet 4.7.1 → 4.8.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of puppet might be problematic. Click here for more details.
- data/Gemfile +0 -3
- data/MAINTAINERS +76 -0
- data/README.md +0 -6
- data/Rakefile +2 -2
- data/lib/puppet/agent.rb +3 -3
- data/lib/puppet/application/apply.rb +1 -1
- data/lib/puppet/configurer.rb +2 -2
- data/lib/puppet/data_providers.rb +1 -0
- data/lib/puppet/data_providers/data_adapter.rb +1 -0
- data/lib/puppet/data_providers/data_function_support.rb +1 -0
- data/lib/puppet/data_providers/function_env_data_provider.rb +1 -0
- data/lib/puppet/data_providers/function_module_data_provider.rb +1 -0
- data/lib/puppet/data_providers/hiera_config.rb +1 -0
- data/lib/puppet/data_providers/hiera_env_data_provider.rb +1 -0
- data/lib/puppet/data_providers/hiera_interpolate.rb +1 -0
- data/lib/puppet/data_providers/hiera_module_data_provider.rb +1 -0
- data/lib/puppet/data_providers/hiera_support.rb +1 -2
- data/lib/puppet/data_providers/json_data_provider_factory.rb +2 -0
- data/lib/puppet/data_providers/yaml_data_provider_factory.rb +2 -0
- data/lib/puppet/defaults.rb +20 -1
- data/lib/puppet/environments.rb +5 -2
- data/lib/puppet/face/catalog.rb +1 -1
- data/lib/puppet/face/epp.rb +57 -11
- data/lib/puppet/face/module/install.rb +6 -6
- data/lib/puppet/functions.rb +23 -24
- data/lib/puppet/functions/alert.rb +14 -0
- data/lib/puppet/functions/binary_file.rb +25 -0
- data/lib/puppet/functions/break.rb +22 -0
- data/lib/puppet/functions/contain.rb +33 -0
- data/lib/puppet/functions/crit.rb +14 -0
- data/lib/puppet/functions/debug.rb +14 -0
- data/lib/puppet/functions/emerg.rb +14 -0
- data/lib/puppet/functions/epp.rb +1 -1
- data/lib/puppet/functions/err.rb +14 -0
- data/lib/puppet/functions/find_file.rb +31 -0
- data/lib/puppet/functions/include.rb +21 -0
- data/lib/puppet/functions/info.rb +14 -0
- data/lib/puppet/functions/new.rb +1 -1
- data/lib/puppet/functions/next.rb +23 -0
- data/lib/puppet/functions/notice.rb +14 -0
- data/lib/puppet/functions/regsubst.rb +12 -16
- data/lib/puppet/functions/require.rb +37 -0
- data/lib/puppet/functions/return.rb +22 -0
- data/lib/puppet/functions/strftime.rb +35 -0
- data/lib/puppet/functions/warning.rb +14 -0
- data/lib/puppet/generate/models/type/type.rb +4 -0
- data/lib/puppet/generate/templates/type/pcore.erb +2 -1
- data/lib/puppet/indirector/face.rb +6 -1
- data/lib/puppet/network/http/error.rb +2 -2
- data/lib/puppet/network/http/handler.rb +2 -2
- data/lib/puppet/node/environment.rb +11 -0
- data/lib/puppet/parser/ast.rb +5 -0
- data/lib/puppet/parser/ast/pops_bridge.rb +17 -4
- data/lib/puppet/parser/compiler.rb +29 -1
- data/lib/puppet/parser/functions.rb +6 -0
- data/lib/puppet/parser/functions/assert_type.rb +1 -1
- data/lib/puppet/parser/functions/binary_file.rb +24 -0
- data/lib/puppet/parser/functions/break.rb +39 -0
- data/lib/puppet/parser/functions/contain.rb +7 -15
- data/lib/puppet/parser/functions/defined.rb +2 -2
- data/lib/puppet/parser/functions/dig.rb +1 -1
- data/lib/puppet/parser/functions/each.rb +1 -1
- data/lib/puppet/parser/functions/epp.rb +2 -2
- data/lib/puppet/parser/functions/filter.rb +1 -1
- data/lib/puppet/parser/functions/find_file.rb +28 -0
- data/lib/puppet/parser/functions/hiera.rb +4 -4
- data/lib/puppet/parser/functions/hiera_array.rb +1 -1
- data/lib/puppet/parser/functions/hiera_hash.rb +1 -1
- data/lib/puppet/parser/functions/hiera_include.rb +1 -1
- data/lib/puppet/parser/functions/include.rb +4 -8
- data/lib/puppet/parser/functions/inline_epp.rb +1 -1
- data/lib/puppet/parser/functions/lest.rb +1 -1
- data/lib/puppet/parser/functions/lookup.rb +4 -2
- data/lib/puppet/parser/functions/map.rb +1 -1
- data/lib/puppet/parser/functions/match.rb +1 -1
- data/lib/puppet/parser/functions/new.rb +414 -18
- data/lib/puppet/parser/functions/next.rb +38 -0
- data/lib/puppet/parser/functions/reduce.rb +1 -1
- data/lib/puppet/parser/functions/regsubst.rb +4 -2
- data/lib/puppet/parser/functions/require.rb +4 -27
- data/lib/puppet/parser/functions/return.rb +71 -0
- data/lib/puppet/parser/functions/reverse_each.rb +1 -1
- data/lib/puppet/parser/functions/scanf.rb +13 -8
- data/lib/puppet/parser/functions/slice.rb +1 -1
- data/lib/puppet/parser/functions/split.rb +1 -1
- data/lib/puppet/parser/functions/step.rb +1 -1
- data/lib/puppet/parser/functions/strftime.rb +185 -0
- data/lib/puppet/parser/functions/then.rb +1 -1
- data/lib/puppet/parser/functions/type.rb +1 -1
- data/lib/puppet/parser/functions/with.rb +3 -3
- data/lib/puppet/parser/resource.rb +8 -5
- data/lib/puppet/parser/scope.rb +1 -1
- data/lib/puppet/plugins/configuration.rb +8 -0
- data/lib/puppet/plugins/data_providers.rb +1 -0
- data/lib/puppet/plugins/data_providers/data_provider.rb +7 -28
- data/lib/puppet/plugins/data_providers/registry.rb +1 -0
- data/lib/puppet/pops.rb +4 -0
- data/lib/puppet/pops/evaluator/access_operator.rb +36 -5
- data/lib/puppet/pops/evaluator/closure.rb +81 -12
- data/lib/puppet/pops/evaluator/compare_operator.rb +24 -1
- data/lib/puppet/pops/evaluator/evaluator_impl.rb +29 -5
- data/lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb +1 -1
- data/lib/puppet/pops/evaluator/runtime3_converter.rb +53 -62
- data/lib/puppet/pops/evaluator/runtime3_support.rb +15 -6
- data/lib/puppet/pops/functions/dispatch.rb +9 -2
- data/lib/puppet/pops/functions/dispatcher.rb +3 -1
- data/lib/puppet/pops/functions/function.rb +19 -2
- data/lib/puppet/pops/issues.rb +9 -0
- data/lib/puppet/pops/label_provider.rb +2 -2
- data/lib/puppet/pops/loader/loader.rb +17 -0
- data/lib/puppet/pops/loader/static_loader.rb +0 -41
- data/lib/puppet/pops/lookup.rb +12 -0
- data/lib/puppet/pops/lookup/context.rb +86 -0
- data/lib/puppet/pops/lookup/explainer.rb +46 -6
- data/lib/puppet/pops/lookup/invocation.rb +19 -0
- data/lib/puppet/pops/lookup/sub_lookup.rb +1 -1
- data/lib/puppet/pops/model/factory.rb +20 -8
- data/lib/puppet/pops/model/model_label_provider.rb +3 -0
- data/lib/puppet/pops/model/model_meta.rb +2 -0
- data/lib/puppet/pops/model/model_tree_dumper.rb +14 -0
- data/lib/puppet/pops/parser/egrammar.ra +11 -6
- data/lib/puppet/pops/parser/eparser.rb +1112 -1086
- data/lib/puppet/pops/parser/heredoc_support.rb +1 -2
- data/lib/puppet/pops/pcore.rb +1 -0
- data/lib/puppet/pops/puppet_stack.rb +3 -3
- data/lib/puppet/pops/resource/param.rb +5 -1
- data/lib/puppet/pops/resource/resource_type_impl.rb +8 -4
- data/lib/puppet/pops/resource/resource_type_set.pcore +1 -0
- data/lib/puppet/pops/serialization/abstract_reader.rb +19 -2
- data/lib/puppet/pops/serialization/abstract_writer.rb +16 -3
- data/lib/puppet/pops/serialization/deserializer.rb +5 -1
- data/lib/puppet/pops/serialization/extension.rb +2 -0
- data/lib/puppet/pops/serialization/json.rb +76 -26
- data/lib/puppet/pops/serialization/serializer.rb +5 -1
- data/lib/puppet/pops/serialization/time_factory.rb +2 -1
- data/lib/puppet/pops/time/timespan.rb +718 -0
- data/lib/puppet/pops/time/timestamp.rb +148 -0
- data/lib/puppet/pops/types/p_binary_type.rb +220 -0
- data/lib/puppet/pops/types/p_object_type.rb +12 -6
- data/lib/puppet/pops/types/p_sensitive_type.rb +5 -1
- data/lib/puppet/pops/types/p_timespan_type.rb +141 -0
- data/lib/puppet/pops/types/p_timestamp_type.rb +69 -0
- data/lib/puppet/pops/types/string_converter.rb +62 -0
- data/lib/puppet/pops/types/type_asserter.rb +1 -1
- data/lib/puppet/pops/types/type_calculator.rb +17 -3
- data/lib/puppet/pops/types/type_factory.rb +35 -1
- data/lib/puppet/pops/types/type_formatter.rb +64 -11
- data/lib/puppet/pops/types/type_mismatch_describer.rb +110 -61
- data/lib/puppet/pops/types/type_parser.rb +18 -4
- data/lib/puppet/pops/types/types.rb +98 -63
- data/lib/puppet/pops/validation.rb +9 -1
- data/lib/puppet/pops/validation/checker4_0.rb +7 -0
- data/lib/puppet/property.rb +1 -1
- data/lib/puppet/provider.rb +3 -6
- data/lib/puppet/provider/mcx/mcxcontent.rb +1 -1
- data/lib/puppet/provider/mount/parsed.rb +18 -4
- data/lib/puppet/provider/nameservice/directoryservice.rb +15 -7
- data/lib/puppet/provider/package/gem.rb +6 -1
- data/lib/puppet/provider/package/pip.rb +0 -1
- data/lib/puppet/provider/package/pkg.rb +5 -1
- data/lib/puppet/provider/package/pkgng.rb +1 -1
- data/lib/puppet/provider/package/yum.rb +10 -0
- data/lib/puppet/provider/service/launchd.rb +1 -0
- data/lib/puppet/provider/user/directoryservice.rb +6 -6
- data/lib/puppet/provider/yumrepo/inifile.rb +1 -1
- data/lib/puppet/provider/zpool/zpool.rb +1 -1
- data/lib/puppet/resource.rb +54 -12
- data/lib/puppet/resource/capability_finder.rb +15 -9
- data/lib/puppet/resource/catalog.rb +25 -6
- data/lib/puppet/resource/type.rb +3 -1
- data/lib/puppet/settings.rb +1 -1
- data/lib/puppet/settings/environment_conf.rb +12 -4
- data/lib/puppet/syntax_checkers/base64.rb +41 -0
- data/lib/puppet/syntax_checkers/json.rb +0 -2
- data/lib/puppet/transaction.rb +6 -0
- data/lib/puppet/transaction/additional_resource_generator.rb +5 -0
- data/lib/puppet/transaction/report.rb +7 -2
- data/lib/puppet/type.rb +2 -1
- data/lib/puppet/type/file/checksum.rb +1 -0
- data/lib/puppet/type/file/content.rb +4 -4
- data/lib/puppet/type/mount.rb +44 -0
- data/lib/puppet/type/ssh_authorized_key.rb +1 -1
- data/lib/puppet/type/tidy.rb +3 -0
- data/lib/puppet/type/user.rb +12 -6
- data/lib/puppet/util/log.rb +25 -0
- data/lib/puppet/util/plist.rb +8 -3
- data/lib/puppet/version.rb +1 -1
- data/lib/puppet_x.rb +7 -1
- data/spec/integration/application/apply_spec.rb +118 -0
- data/spec/integration/parser/compiler_spec.rb +28 -0
- data/spec/integration/parser/pcore_resource_spec.rb +40 -3
- data/spec/integration/provider/mount_spec.rb +2 -1
- data/spec/integration/util/windows/principal_spec.rb +2 -2
- data/spec/integration/util/windows/registry_spec.rb +4 -4
- data/spec/lib/puppet_spec/compiler.rb +5 -1
- data/spec/lib/puppet_spec/unindent.rb +5 -0
- data/spec/shared_contexts/types_setup.rb +6 -0
- data/spec/shared_examples/rhel_package_provider.rb +16 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/unit/agent_spec.rb +11 -0
- data/spec/unit/application/lookup_spec.rb +94 -3
- data/spec/unit/capability_spec.rb +22 -0
- data/spec/unit/configurer_spec.rb +8 -0
- data/spec/unit/face/epp_face_spec.rb +22 -3
- data/spec/unit/functions/assert_type_spec.rb +3 -3
- data/spec/unit/functions/binary_file_spec.rb +46 -0
- data/spec/unit/functions/break_spec.rb +89 -0
- data/spec/unit/{parser/functions → functions}/contain_spec.rb +68 -3
- data/spec/unit/functions/find_file_spec.rb +69 -0
- data/spec/unit/functions/include_spec.rb +175 -0
- data/spec/unit/functions/logging_spec.rb +54 -0
- data/spec/unit/functions/lookup_spec.rb +3 -3
- data/spec/unit/functions/new_spec.rb +105 -5
- data/spec/unit/functions/next_spec.rb +93 -0
- data/spec/unit/functions/require_spec.rb +83 -0
- data/spec/unit/functions/return_spec.rb +105 -0
- data/spec/unit/{parser/functions → functions}/shared.rb +14 -11
- data/spec/unit/functions/strftime_spec.rb +152 -0
- data/spec/unit/functions4_spec.rb +22 -0
- data/spec/unit/indirector/face_spec.rb +10 -2
- data/spec/unit/network/http/error_spec.rb +1 -2
- data/spec/unit/network/http/handler_spec.rb +6 -5
- data/spec/unit/parser/functions/hiera_array_spec.rb +1 -1
- data/spec/unit/parser/functions/hiera_hash_spec.rb +1 -1
- data/spec/unit/parser/functions/hiera_include_spec.rb +1 -1
- data/spec/unit/parser/functions/hiera_spec.rb +1 -1
- data/spec/unit/parser/functions/lookup_spec.rb +1 -1
- data/spec/unit/parser/functions/regsubst_spec.rb +1 -1
- data/spec/unit/parser/functions/split_spec.rb +1 -1
- data/spec/unit/pops/evaluator/access_ops_spec.rb +81 -1
- data/spec/unit/pops/evaluator/arithmetic_ops_spec.rb +170 -0
- data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +29 -4
- data/spec/unit/pops/evaluator/runtime3_converter_spec.rb +112 -4
- data/spec/unit/pops/loaders/dependency_loader_spec.rb +12 -0
- data/spec/unit/pops/loaders/static_loader_spec.rb +0 -26
- data/spec/unit/pops/lookup/context_spec.rb +149 -0
- data/spec/unit/pops/parser/parse_functions_spec.rb +19 -0
- data/spec/unit/pops/parser/parse_lambda_spec.rb +19 -0
- data/spec/unit/pops/puppet_stack_spec.rb +1 -1
- data/spec/unit/pops/resource/resource_type_impl_spec.rb +74 -0
- data/spec/unit/pops/serialization/packer_spec.rb +34 -14
- data/spec/unit/pops/serialization/serialization_spec.rb +67 -5
- data/spec/unit/pops/time/timespan_spec.rb +121 -0
- data/spec/unit/pops/types/p_binary_type_spec.rb +243 -0
- data/spec/unit/pops/types/p_object_type_spec.rb +7 -7
- data/spec/unit/pops/types/p_sensitive_type_spec.rb +1 -1
- data/spec/unit/pops/types/p_timespan_type_spec.rb +273 -0
- data/spec/unit/pops/types/p_timestamp_type_spec.rb +311 -0
- data/spec/unit/pops/types/p_type_set_type_spec.rb +13 -13
- data/spec/unit/pops/types/ruby_generator_spec.rb +12 -12
- data/spec/unit/pops/types/string_converter_spec.rb +89 -0
- data/spec/unit/pops/types/type_asserter_spec.rb +3 -3
- data/spec/unit/pops/types/type_calculator_spec.rb +113 -5
- data/spec/unit/pops/types/type_formatter_spec.rb +40 -0
- data/spec/unit/pops/types/type_mismatch_describer_spec.rb +49 -38
- data/spec/unit/pops/types/type_parser_spec.rb +87 -4
- data/spec/unit/pops/types/types_spec.rb +1 -1
- data/spec/unit/pops/validator/validator_spec.rb +23 -0
- data/spec/unit/provider/mount/parsed_spec.rb +47 -29
- data/spec/unit/provider/package/pkg_spec.rb +109 -99
- data/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +1 -0
- data/spec/unit/provider/user/aix_spec.rb +1 -1
- data/spec/unit/provider/user/directoryservice_spec.rb +101 -30
- data/spec/unit/resource/capability_finder_spec.rb +29 -7
- data/spec/unit/resource/catalog_spec.rb +127 -0
- data/spec/unit/ssl/certificate_request_spec.rb +1 -1
- data/spec/unit/transaction/additional_resource_generator_spec.rb +30 -0
- data/spec/unit/transaction/persistence_spec.rb +1 -6
- data/spec/unit/transaction/report_spec.rb +23 -0
- data/spec/unit/transaction_spec.rb +38 -0
- data/spec/unit/type/mount_spec.rb +5 -0
- data/spec/unit/util/plist_spec.rb +14 -2
- metadata +71 -12
- data/spec/integration/parser/functions/require_spec.rb +0 -43
- data/spec/unit/parser/functions/include_spec.rb +0 -55
- data/spec/unit/parser/functions/require_spec.rb +0 -68
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'puppet_spec/compiler'
|
3
|
+
|
4
|
+
describe 'the log function' do
|
5
|
+
include PuppetSpec::Compiler
|
6
|
+
|
7
|
+
def collect_logs(code)
|
8
|
+
Puppet[:code] = code
|
9
|
+
node = Puppet::Node.new('logtest')
|
10
|
+
compiler = Puppet::Parser::Compiler.new(node)
|
11
|
+
node.environment.check_for_reparse
|
12
|
+
logs = []
|
13
|
+
Puppet::Util::Log.with_destination(Puppet::Test::LogCollector.new(logs)) do
|
14
|
+
compiler.compile
|
15
|
+
end
|
16
|
+
logs
|
17
|
+
end
|
18
|
+
|
19
|
+
def expect_log(code, log_level, message)
|
20
|
+
logs = collect_logs(code)
|
21
|
+
expect(logs.size).to eql(1)
|
22
|
+
expect(logs[0].level).to eql(log_level)
|
23
|
+
expect(logs[0].message).to eql(message)
|
24
|
+
end
|
25
|
+
|
26
|
+
before(:each) do
|
27
|
+
Puppet[:log_level] = 'debug'
|
28
|
+
end
|
29
|
+
|
30
|
+
Puppet::Util::Log.levels.each do |level|
|
31
|
+
context "for log level '#{level}'" do
|
32
|
+
it 'can be called' do
|
33
|
+
expect_log("#{level.to_s}('yay')", level, 'yay')
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'joins multiple arguments using space' do
|
37
|
+
# Not using the evaluator would result in yay {"a"=>"b", "c"=>"d"}
|
38
|
+
expect_log("#{level.to_s}('a', 'b', 3)", level, 'a b 3')
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'uses the evaluator to format output' do
|
42
|
+
# Not using the evaluator would result in yay {"a"=>"b", "c"=>"d"}
|
43
|
+
expect_log("#{level.to_s}('yay', {a => b, c => d})", level, 'yay {a => b, c => d}')
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'returns undef value' do
|
47
|
+
logs = collect_logs("notice(type(#{level.to_s}('yay')))")
|
48
|
+
expect(logs.size).to eql(2)
|
49
|
+
expect(logs[1].level).to eql(:notice)
|
50
|
+
expect(logs[1].message).to eql('Undef')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -170,7 +170,7 @@ describe "when performing lookup" do
|
|
170
170
|
it 'will not accept a succesful lookup of an undef value when the type rejects it' do
|
171
171
|
expect do
|
172
172
|
assemble_and_compile('${r}', "'abc::n'", 'String')
|
173
|
-
end.to raise_error(Puppet::ParseError, /Found value
|
173
|
+
end.to raise_error(Puppet::ParseError, /Found value has wrong type, expects a String value, got Undef/)
|
174
174
|
end
|
175
175
|
|
176
176
|
it 'will raise an exception when value is not found for array key and no default is provided' do
|
@@ -249,7 +249,7 @@ describe "when performing lookup" do
|
|
249
249
|
expect do
|
250
250
|
assemble_and_compile('${r[a]}_${r[b]}', "'abc::x'", 'Hash[String,String]', 'undef', "{'a' => 'dflt_x', 'b' => 32}")
|
251
251
|
end.to raise_error(Puppet::ParseError,
|
252
|
-
/Default value
|
252
|
+
/Default value has wrong type, entry 'b' expects a String value, got Integer/)
|
253
253
|
end
|
254
254
|
end
|
255
255
|
|
@@ -283,7 +283,7 @@ describe "when performing lookup" do
|
|
283
283
|
expect do
|
284
284
|
assemble_and_compile_with_block('${r[a]}_${r[b]}', "{'a' => 'dflt_x', 'b' => 32}", "'abc::x'", 'Hash[String,String]')
|
285
285
|
end.to raise_error(Puppet::ParseError,
|
286
|
-
/Value returned from default block
|
286
|
+
/Value returned from default block has wrong type, entry 'b' expects a String value, got Integer/)
|
287
287
|
end
|
288
288
|
|
289
289
|
it 'receives a single name parameter' do
|
@@ -28,7 +28,7 @@ describe 'the new function' do
|
|
28
28
|
$x = Integer.new(undef)
|
29
29
|
notify { "one${x}word": }
|
30
30
|
MANIFEST
|
31
|
-
)}.to raise_error(Puppet::Error, /
|
31
|
+
)}.to raise_error(Puppet::Error, /expects an Integer value, got Undef/)
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'errors if converted value is not assignable to the type' do
|
@@ -36,7 +36,7 @@ describe 'the new function' do
|
|
36
36
|
$x = Integer[1,5].new('42')
|
37
37
|
notify { "one${x}word": }
|
38
38
|
MANIFEST
|
39
|
-
)}.to raise_error(Puppet::Error, /
|
39
|
+
)}.to raise_error(Puppet::Error, /expects an Integer\[1, 5\] value, got Integer\[42, 42\]/)
|
40
40
|
end
|
41
41
|
|
42
42
|
context 'when invoked on NotUndef' do
|
@@ -90,6 +90,34 @@ describe 'the new function' do
|
|
90
90
|
)).to have_resource('Notify[Integer, 1]')
|
91
91
|
end
|
92
92
|
|
93
|
+
it "produces an absolute value when third argument is 'true'" do
|
94
|
+
expect(eval_and_collect_notices(<<-MANIFEST
|
95
|
+
notice(Integer.new(-42, 10, true))
|
96
|
+
MANIFEST
|
97
|
+
)).to eql(['42'])
|
98
|
+
end
|
99
|
+
|
100
|
+
it "does not produce an absolute value when third argument is 'false'" do
|
101
|
+
expect(eval_and_collect_notices(<<-MANIFEST
|
102
|
+
notice(Integer.new(-42, 10, false))
|
103
|
+
MANIFEST
|
104
|
+
)).to eql(['-42'])
|
105
|
+
end
|
106
|
+
|
107
|
+
it "produces an absolute value from hash {from => val, abs => true}" do
|
108
|
+
expect(eval_and_collect_notices(<<-MANIFEST
|
109
|
+
notice(Integer.new({from => -42, abs => true}))
|
110
|
+
MANIFEST
|
111
|
+
)).to eql(['42'])
|
112
|
+
end
|
113
|
+
|
114
|
+
it "does not produce an absolute value from hash {from => val, abs => false}" do
|
115
|
+
expect(eval_and_collect_notices(<<-MANIFEST
|
116
|
+
notice(Integer.new({from => -42, abs => false}))
|
117
|
+
MANIFEST
|
118
|
+
)).to eql(['-42'])
|
119
|
+
end
|
120
|
+
|
93
121
|
context 'when prefixed by a sign' do
|
94
122
|
{ '+1' => 1,
|
95
123
|
'-1' => -1,
|
@@ -362,6 +390,34 @@ describe 'the new function' do
|
|
362
390
|
MANIFEST
|
363
391
|
)).to have_resource('Notify[Integer, 42]')
|
364
392
|
end
|
393
|
+
|
394
|
+
it "produces an absolute value when second argument is 'true'" do
|
395
|
+
expect(eval_and_collect_notices(<<-MANIFEST
|
396
|
+
notice(Numeric.new(-42.3, true))
|
397
|
+
MANIFEST
|
398
|
+
)).to eql(['42.3'])
|
399
|
+
end
|
400
|
+
|
401
|
+
it "does not produce an absolute value when second argument is 'false'" do
|
402
|
+
expect(eval_and_collect_notices(<<-MANIFEST
|
403
|
+
notice(Numeric.new(-42.3, false))
|
404
|
+
MANIFEST
|
405
|
+
)).to eql(['-42.3'])
|
406
|
+
end
|
407
|
+
|
408
|
+
it "produces an absolute value from hash {from => val, abs => true}" do
|
409
|
+
expect(eval_and_collect_notices(<<-MANIFEST
|
410
|
+
notice(Numeric.new({from => -42.3, abs => true}))
|
411
|
+
MANIFEST
|
412
|
+
)).to eql(['42.3'])
|
413
|
+
end
|
414
|
+
|
415
|
+
it "does not produce an absolute value from hash {from => val, abs => false}" do
|
416
|
+
expect(eval_and_collect_notices(<<-MANIFEST
|
417
|
+
notice(Numeric.new({from => -42.3, abs => false}))
|
418
|
+
MANIFEST
|
419
|
+
)).to eql(['-42.3'])
|
420
|
+
end
|
365
421
|
end
|
366
422
|
|
367
423
|
context 'when invoked on Float' do
|
@@ -397,6 +453,34 @@ describe 'the new function' do
|
|
397
453
|
MANIFEST
|
398
454
|
)).to have_resource('Notify[Float, 42.0]')
|
399
455
|
end
|
456
|
+
|
457
|
+
it "produces an absolute value when second argument is 'true'" do
|
458
|
+
expect(eval_and_collect_notices(<<-MANIFEST
|
459
|
+
notice(Float.new(-42.3, true))
|
460
|
+
MANIFEST
|
461
|
+
)).to eql(['42.3'])
|
462
|
+
end
|
463
|
+
|
464
|
+
it "does not produce an absolute value when second argument is 'false'" do
|
465
|
+
expect(eval_and_collect_notices(<<-MANIFEST
|
466
|
+
notice(Float.new(-42.3, false))
|
467
|
+
MANIFEST
|
468
|
+
)).to eql(['-42.3'])
|
469
|
+
end
|
470
|
+
|
471
|
+
it "produces an absolute value from hash {from => val, abs => true}" do
|
472
|
+
expect(eval_and_collect_notices(<<-MANIFEST
|
473
|
+
notice(Float.new({from => -42.3, abs => true}))
|
474
|
+
MANIFEST
|
475
|
+
)).to eql(['42.3'])
|
476
|
+
end
|
477
|
+
|
478
|
+
it "does not produce an absolute value from hash {from => val, abs => false}" do
|
479
|
+
expect(eval_and_collect_notices(<<-MANIFEST
|
480
|
+
notice(Float.new({from => -42.3, abs => false}))
|
481
|
+
MANIFEST
|
482
|
+
)).to eql(['-42.3'])
|
483
|
+
end
|
400
484
|
end
|
401
485
|
|
402
486
|
context 'when invoked on Boolean' do
|
@@ -441,7 +525,7 @@ describe 'the new function' do
|
|
441
525
|
expect{compile_to_catalog(<<-"MANIFEST"
|
442
526
|
$x = Boolean.new(undef)
|
443
527
|
MANIFEST
|
444
|
-
)}.to raise_error(Puppet::Error, /
|
528
|
+
)}.to raise_error(Puppet::Error, /expects a Boolean value, got Undef/)
|
445
529
|
end
|
446
530
|
end
|
447
531
|
|
@@ -488,6 +572,22 @@ describe 'the new function' do
|
|
488
572
|
)).to have_resource(result)
|
489
573
|
end
|
490
574
|
end
|
575
|
+
|
576
|
+
it 'produces an array of byte integer values when given a Binary' do
|
577
|
+
expect(compile_to_catalog(<<-MANIFEST
|
578
|
+
$x = Array.new(Binary('ABC', '%s'))
|
579
|
+
notify { "${type($x, generalized)}, $x": }
|
580
|
+
MANIFEST
|
581
|
+
)).to have_resource('Notify[Array[Integer], [65, 66, 67]]')
|
582
|
+
end
|
583
|
+
|
584
|
+
it 'wraps a binary when given extra argument true' do
|
585
|
+
expect(compile_to_catalog(<<-MANIFEST
|
586
|
+
$x = Array[Any].new(Binary('ABC', '%s'), true)
|
587
|
+
notify { "${type($x, generalized)}, $x": }
|
588
|
+
MANIFEST
|
589
|
+
)).to have_resource('Notify[Array[Binary], [QUJD]]')
|
590
|
+
end
|
491
591
|
end
|
492
592
|
|
493
593
|
context 'when invoked on Tuple' do
|
@@ -507,7 +607,7 @@ describe 'the new function' do
|
|
507
607
|
expect{compile_to_catalog(<<-"MANIFEST"
|
508
608
|
$x = Tuple[Integer,6].new(3)
|
509
609
|
MANIFEST
|
510
|
-
)}.to raise_error(Puppet::Error, /
|
610
|
+
)}.to raise_error(Puppet::Error, /expects size to be at least 6, got 3/)
|
511
611
|
end
|
512
612
|
end
|
513
613
|
|
@@ -558,7 +658,7 @@ describe 'the new function' do
|
|
558
658
|
expect{compile_to_catalog(<<-"MANIFEST"
|
559
659
|
$x = Struct[{a => Integer[2]}].new({a => 0})
|
560
660
|
MANIFEST
|
561
|
-
)}.to raise_error(Puppet::Error, /entry 'a'
|
661
|
+
)}.to raise_error(Puppet::Error, /entry 'a' expects an Integer\[2, default\]/)
|
562
662
|
end
|
563
663
|
end
|
564
664
|
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'puppet_spec/compiler'
|
4
|
+
require 'matchers/resource'
|
5
|
+
|
6
|
+
describe 'the next function' do
|
7
|
+
include PuppetSpec::Compiler
|
8
|
+
include Matchers::Resource
|
9
|
+
|
10
|
+
context 'exits a block yielded to iteratively' do
|
11
|
+
it 'with a given value as result for this iteration' do
|
12
|
+
expect(compile_to_catalog(<<-CODE)).to have_resource('Notify[[100, 4, 6]]')
|
13
|
+
$result = String([1,2,3].map |$x| { if $x == 1 { next(100) } $x*2 })
|
14
|
+
notify { $result: }
|
15
|
+
CODE
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'with undef value as result for this iteration when next is not given an argument' do
|
19
|
+
expect(compile_to_catalog(<<-CODE)).to have_resource('Notify[[undef, 4, 6]]')
|
20
|
+
$result = String([1,2,3].map |$x| { if $x == 1 { next() } $x*2 })
|
21
|
+
notify { $result: }
|
22
|
+
CODE
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'can be called without parentheses around the argument' do
|
27
|
+
expect(compile_to_catalog(<<-CODE)).to have_resource('Notify[[100, 4, 6]]')
|
28
|
+
$result = String([1,2,3].map |$x| { if $x == 1 { next 100 } $x*2 })
|
29
|
+
notify { $result: }
|
30
|
+
CODE
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'has the same effect as a return when called from within a block not used in an iteration' do
|
34
|
+
expect(compile_to_catalog(<<-CODE)).to have_resource('Notify[100]')
|
35
|
+
$result = String(with(1) |$x| { if $x == 1 { next(100) } 200 })
|
36
|
+
notify { $result: }
|
37
|
+
CODE
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'has the same effect as a return when called from within a function' do
|
41
|
+
expect(compile_to_catalog(<<-CODE)).to have_resource('Notify[[102, 200, 300]]')
|
42
|
+
function do_next() {
|
43
|
+
next(100)
|
44
|
+
}
|
45
|
+
$result = String([1,2,3].map |$x| { if $x == 1 { next do_next()+2 } $x*do_next() })
|
46
|
+
notify { $result: }
|
47
|
+
CODE
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'provides early exit from a class and keeps the class' do
|
51
|
+
expect(eval_and_collect_notices(<<-CODE)).to eql(['a', 'c', 'true', 'true'])
|
52
|
+
class notices_c { notice 'c' }
|
53
|
+
class does_next {
|
54
|
+
notice 'a'
|
55
|
+
if 1 == 1 { next() } # avoid making next line statically unreachable
|
56
|
+
notice 'b'
|
57
|
+
}
|
58
|
+
# include two classes to check that next does not do an early return from
|
59
|
+
# the include function.
|
60
|
+
include(does_next, notices_c)
|
61
|
+
notice defined(does_next)
|
62
|
+
notice defined(notices_c)
|
63
|
+
CODE
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'provides early exit from a user defined resource and keeps the resource' do
|
67
|
+
expect(eval_and_collect_notices(<<-CODE)).to eql(['the_doer_of_next', 'copy_cat', 'true', 'true'])
|
68
|
+
define does_next {
|
69
|
+
notice $title
|
70
|
+
if 1 == 1 { next() } # avoid making next line statically unreachable
|
71
|
+
notice 'b'
|
72
|
+
}
|
73
|
+
define checker {
|
74
|
+
notice defined(Does_next['the_doer_of_next'])
|
75
|
+
notice defined(Does_next['copy_cat'])
|
76
|
+
}
|
77
|
+
# create two instances to ensure next does not break the entire
|
78
|
+
# resource expression
|
79
|
+
does_next { ['the_doer_of_next', 'copy_cat']: }
|
80
|
+
checker { 'needed_because_evaluation_order': }
|
81
|
+
CODE
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'can not be called from top scope' do
|
85
|
+
expect do
|
86
|
+
compile_to_catalog(<<-CODE)
|
87
|
+
# line 1
|
88
|
+
# line 2
|
89
|
+
next()
|
90
|
+
CODE
|
91
|
+
end.to raise_error(/next\(\) from context where this is illegal at unknown:3 on node.*/)
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'puppet_spec/compiler'
|
4
|
+
require 'puppet/parser/functions'
|
5
|
+
require 'matchers/containment_matchers'
|
6
|
+
require 'matchers/resource'
|
7
|
+
require 'matchers/include_in_order'
|
8
|
+
require 'unit/functions/shared'
|
9
|
+
|
10
|
+
|
11
|
+
describe 'The "require" function' do
|
12
|
+
include PuppetSpec::Compiler
|
13
|
+
include ContainmentMatchers
|
14
|
+
include Matchers::Resource
|
15
|
+
|
16
|
+
before(:each) do
|
17
|
+
compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("foo"))
|
18
|
+
@scope = compiler.topscope
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'includes a class that is not already included' do
|
22
|
+
catalog = compile_to_catalog(<<-MANIFEST)
|
23
|
+
class required {
|
24
|
+
notify { "required": }
|
25
|
+
}
|
26
|
+
require required
|
27
|
+
MANIFEST
|
28
|
+
|
29
|
+
expect(catalog.classes).to include("required")
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'sets the require attribute on the requiring resource' do
|
33
|
+
catalog = compile_to_catalog(<<-MANIFEST)
|
34
|
+
class required {
|
35
|
+
notify { "required": }
|
36
|
+
}
|
37
|
+
class requiring {
|
38
|
+
require required
|
39
|
+
}
|
40
|
+
include requiring
|
41
|
+
MANIFEST
|
42
|
+
|
43
|
+
requiring = catalog.resource("Class", "requiring")
|
44
|
+
expect(requiring["require"]).to be_instance_of(Array)
|
45
|
+
expect(requiring["require"][0]).to be_instance_of(Puppet::Resource)
|
46
|
+
expect(requiring["require"][0].to_s).to eql("Class[Required]")
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'appends to the require attribute on the requiring resource if it already has requirements' do
|
50
|
+
catalog = compile_to_catalog(<<-MANIFEST)
|
51
|
+
|
52
|
+
class required { }
|
53
|
+
class also_required { }
|
54
|
+
|
55
|
+
class requiring {
|
56
|
+
require required
|
57
|
+
require also_required
|
58
|
+
}
|
59
|
+
include requiring
|
60
|
+
MANIFEST
|
61
|
+
|
62
|
+
requiring = catalog.resource("Class", "requiring")
|
63
|
+
expect(requiring["require"]).to be_instance_of(Array)
|
64
|
+
expect(requiring["require"][0]).to be_instance_of(Puppet::Resource)
|
65
|
+
expect(requiring["require"][0].to_s).to eql("Class[Required]")
|
66
|
+
expect(requiring["require"][1]).to be_instance_of(Puppet::Resource)
|
67
|
+
expect(requiring["require"][1].to_s).to eql("Class[Also_required]")
|
68
|
+
end
|
69
|
+
|
70
|
+
it "includes the class when using a fully qualified anchored name" do
|
71
|
+
catalog = compile_to_catalog(<<-MANIFEST)
|
72
|
+
class required {
|
73
|
+
notify { "required": }
|
74
|
+
}
|
75
|
+
require ::required
|
76
|
+
MANIFEST
|
77
|
+
|
78
|
+
expect(catalog.classes).to include("required")
|
79
|
+
end
|
80
|
+
|
81
|
+
it_should_behave_like 'all functions transforming relative to absolute names', :require
|
82
|
+
it_should_behave_like 'an inclusion function, regardless of the type of class reference,', :require
|
83
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'puppet_spec/compiler'
|
4
|
+
require 'matchers/resource'
|
5
|
+
|
6
|
+
describe 'the return function' do
|
7
|
+
include PuppetSpec::Compiler
|
8
|
+
include Matchers::Resource
|
9
|
+
|
10
|
+
context 'returns from outer function when called from nested block' do
|
11
|
+
it 'with a given value as function result' do
|
12
|
+
expect(compile_to_catalog(<<-CODE)).to have_resource('Notify[100]')
|
13
|
+
function please_return() {
|
14
|
+
[1,2,3].map |$x| { if $x == 1 { return(100) } 200 }
|
15
|
+
300
|
16
|
+
}
|
17
|
+
notify { String(please_return()): }
|
18
|
+
CODE
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'with undef value as function result when not given an argument' do
|
22
|
+
expect(compile_to_catalog(<<-CODE)).to have_resource('Notify[xy]')
|
23
|
+
function please_return() {
|
24
|
+
[1,2,3].map |$x| { if $x == 1 { return() } 200 }
|
25
|
+
300
|
26
|
+
}
|
27
|
+
notify { "x${please_return}y": }
|
28
|
+
CODE
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'can be called without parentheses around the argument' do
|
33
|
+
expect(compile_to_catalog(<<-CODE)).to have_resource('Notify[100]')
|
34
|
+
function please_return() {
|
35
|
+
if 1 == 1 { return 100 }
|
36
|
+
200
|
37
|
+
}
|
38
|
+
notify { String(please_return()): }
|
39
|
+
CODE
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'provides early exit from a class and keeps the class' do
|
43
|
+
expect(eval_and_collect_notices(<<-CODE)).to eql(['a', 'c', 'true', 'true'])
|
44
|
+
class notices_c { notice 'c' }
|
45
|
+
class does_next {
|
46
|
+
notice 'a'
|
47
|
+
if 1 == 1 { return() } # avoid making next line statically unreachable
|
48
|
+
notice 'b'
|
49
|
+
}
|
50
|
+
# include two classes to check that next does not do an early return from
|
51
|
+
# the include function.
|
52
|
+
include(does_next, notices_c)
|
53
|
+
notice defined(does_next)
|
54
|
+
notice defined(notices_c)
|
55
|
+
CODE
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'provides early exit from a user defined resource and keeps the resource' do
|
59
|
+
expect(eval_and_collect_notices(<<-CODE)).to eql(['the_doer_of_next', 'copy_cat', 'true', 'true'])
|
60
|
+
define does_next {
|
61
|
+
notice $title
|
62
|
+
if 1 == 1 { return() } # avoid making next line statically unreachable
|
63
|
+
notice 'b'
|
64
|
+
}
|
65
|
+
define checker {
|
66
|
+
notice defined(Does_next['the_doer_of_next'])
|
67
|
+
notice defined(Does_next['copy_cat'])
|
68
|
+
}
|
69
|
+
# create two instances to ensure next does not break the entire
|
70
|
+
# resource expression
|
71
|
+
does_next { ['the_doer_of_next', 'copy_cat']: }
|
72
|
+
checker { 'needed_because_evaluation_order': }
|
73
|
+
CODE
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'can be called when nested in a function to make that function return' do
|
77
|
+
expect(eval_and_collect_notices(<<-CODE)).to eql(['100'])
|
78
|
+
function nested_return() {
|
79
|
+
with(1) |$x| { with($x) |$x| {return(100) }}
|
80
|
+
}
|
81
|
+
notice nested_return()
|
82
|
+
CODE
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'can not be called nested from top scope' do
|
86
|
+
expect do
|
87
|
+
compile_to_catalog(<<-CODE)
|
88
|
+
# line 1
|
89
|
+
# line 2
|
90
|
+
$result = with(1) |$x| { with($x) |$x| {return(100) }}
|
91
|
+
notice $result
|
92
|
+
CODE
|
93
|
+
end.to raise_error(/return\(\) from context where this is illegal at unknown:3 on node.*/)
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'can not be called from top scope' do
|
97
|
+
expect do
|
98
|
+
compile_to_catalog(<<-CODE)
|
99
|
+
# line 1
|
100
|
+
# line 2
|
101
|
+
return()
|
102
|
+
CODE
|
103
|
+
end.to raise_error(/return\(\) from context where this is illegal at unknown:3 on node.*/)
|
104
|
+
end
|
105
|
+
end
|