puppet 3.7.1 → 3.7.2
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/ext/build_defaults.yaml +3 -3
- data/ext/debian/control +2 -0
- data/ext/project_data.yaml +2 -2
- data/lib/puppet/application.rb +1 -4
- data/lib/puppet/configurer.rb +6 -4
- data/lib/puppet/environments.rb +47 -3
- data/lib/puppet/indirector/node/exec.rb +1 -1
- data/lib/puppet/indirector/request.rb +1 -2
- data/lib/puppet/module.rb +1 -1
- data/lib/puppet/module_tool.rb +1 -1
- data/lib/puppet/network/http/webrick.rb +17 -7
- data/lib/puppet/node.rb +2 -2
- data/lib/puppet/parser/ast/pops_bridge.rb +1 -11
- data/lib/puppet/parser/compiler.rb +1 -2
- data/lib/puppet/parser/resource.rb +1 -3
- data/lib/puppet/parser/resource/param.rb +1 -1
- data/lib/puppet/parser/type_loader.rb +1 -1
- data/lib/puppet/pops/evaluator/access_operator.rb +3 -11
- data/lib/puppet/pops/evaluator/evaluator_impl.rb +1 -1
- data/lib/puppet/pops/evaluator/runtime3_support.rb +30 -4
- data/lib/puppet/pops/model/factory.rb +16 -1
- data/lib/puppet/pops/parser/egrammar.ra +1 -1
- data/lib/puppet/pops/parser/eparser.rb +1 -1
- data/lib/puppet/pops/parser/parser_support.rb +19 -1
- data/lib/puppet/pops/types/type_calculator.rb +19 -14
- data/lib/puppet/provider/package/pkg.rb +12 -1
- data/lib/puppet/provider/scheduled_task/win32_taskscheduler.rb +15 -16
- data/lib/puppet/provider/ssh_authorized_key/parsed.rb +16 -0
- data/lib/puppet/resource.rb +1 -8
- data/lib/puppet/settings.rb +17 -0
- data/lib/puppet/type/user.rb +11 -1
- data/lib/puppet/util/autoload.rb +10 -6
- data/lib/puppet/util/monkey_patches.rb +2 -2
- data/lib/puppet/version.rb +1 -1
- data/spec/fixtures/unit/provider/package/pkg/dummy_solaris11.certificate_warning +2 -0
- data/spec/fixtures/unit/type/user/authorized_keys +1 -0
- data/spec/integration/application/apply_spec.rb +29 -23
- data/spec/integration/parser/future_compiler_spec.rb +56 -0
- data/spec/integration/type/user_spec.rb +22 -1
- data/spec/lib/puppet_spec/files.rb +1 -0
- data/spec/unit/environments_spec.rb +99 -0
- data/spec/unit/network/http/webrick_spec.rb +21 -2
- data/spec/unit/parser/compiler_spec.rb +19 -1
- data/spec/unit/parser/functions/lookup_spec.rb +13 -12
- data/spec/unit/parser/resource/param_spec.rb +10 -22
- data/spec/unit/parser/resource_spec.rb +0 -4
- data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +30 -5
- data/spec/unit/pops/parser/parse_calls_spec.rb +20 -5
- data/spec/unit/pops/types/type_calculator_spec.rb +61 -0
- data/spec/unit/provider/package/pkg_spec.rb +4 -0
- data/spec/unit/provider/scheduled_task/win32_taskscheduler_spec.rb +47 -14
- data/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +15 -0
- data/spec/unit/type/user_spec.rb +5 -0
- data/spec/unit/util/autoload_spec.rb +33 -14
- data/spec/unit/util/monkey_patches_spec.rb +12 -0
- data/tasks/memwalk.rake +195 -0
- metadata +3216 -3205
- checksums.yaml +0 -7
@@ -440,6 +440,16 @@ describe "Puppet::Parser::Compiler" do
|
|
440
440
|
expect(catalog).to have_resource("Foo[test]").with_parameter(:x, 'say friend')
|
441
441
|
end
|
442
442
|
|
443
|
+
it 'accepts undef as the default for an Optional argument' do
|
444
|
+
catalog = compile_to_catalog(<<-MANIFEST)
|
445
|
+
define foo(Optional[String] $x = undef) {
|
446
|
+
notify { "expected": message => $x == undef }
|
447
|
+
}
|
448
|
+
foo { 'test': }
|
449
|
+
MANIFEST
|
450
|
+
expect(catalog).to have_resource("Notify[expected]").with_parameter(:message, true)
|
451
|
+
end
|
452
|
+
|
443
453
|
it 'accepts anything when parameters are untyped' do
|
444
454
|
expect do
|
445
455
|
catalog = compile_to_catalog(<<-MANIFEST)
|
@@ -458,6 +468,15 @@ describe "Puppet::Parser::Compiler" do
|
|
458
468
|
end.to raise_error(/type Integer, got String/)
|
459
469
|
end
|
460
470
|
|
471
|
+
it 'denies undef for a non-optional type' do
|
472
|
+
expect do
|
473
|
+
catalog = compile_to_catalog(<<-MANIFEST)
|
474
|
+
define foo(Integer $x) { }
|
475
|
+
foo { 'test': x => undef }
|
476
|
+
MANIFEST
|
477
|
+
end.to raise_error(/type Integer, got Undef/)
|
478
|
+
end
|
479
|
+
|
461
480
|
it 'denies non type compliant default argument' do
|
462
481
|
expect do
|
463
482
|
catalog = compile_to_catalog(<<-MANIFEST)
|
@@ -467,6 +486,15 @@ describe "Puppet::Parser::Compiler" do
|
|
467
486
|
end.to raise_error(/type Integer, got String/)
|
468
487
|
end
|
469
488
|
|
489
|
+
it 'denies undef as the default for a non-optional type' do
|
490
|
+
expect do
|
491
|
+
catalog = compile_to_catalog(<<-MANIFEST)
|
492
|
+
define foo(Integer $x = undef) { }
|
493
|
+
foo { 'test': }
|
494
|
+
MANIFEST
|
495
|
+
end.to raise_error(/type Integer, got Undef/)
|
496
|
+
end
|
497
|
+
|
470
498
|
it 'accepts a Resource as a Type' do
|
471
499
|
catalog = compile_to_catalog(<<-MANIFEST)
|
472
500
|
define foo(Type[Bar] $x) {
|
@@ -489,6 +517,16 @@ describe "Puppet::Parser::Compiler" do
|
|
489
517
|
expect(catalog).to have_resource("Class[Foo]").with_parameter(:x, 'say friend')
|
490
518
|
end
|
491
519
|
|
520
|
+
it 'accepts undef as the default for an Optional argument' do
|
521
|
+
catalog = compile_to_catalog(<<-MANIFEST)
|
522
|
+
class foo(Optional[String] $x = undef) {
|
523
|
+
notify { "expected": message => $x == undef }
|
524
|
+
}
|
525
|
+
class { 'foo': }
|
526
|
+
MANIFEST
|
527
|
+
expect(catalog).to have_resource("Notify[expected]").with_parameter(:message, true)
|
528
|
+
end
|
529
|
+
|
492
530
|
it 'accepts anything when parameters are untyped' do
|
493
531
|
expect do
|
494
532
|
catalog = compile_to_catalog(<<-MANIFEST)
|
@@ -507,6 +545,15 @@ describe "Puppet::Parser::Compiler" do
|
|
507
545
|
end.to raise_error(/type Integer, got String/)
|
508
546
|
end
|
509
547
|
|
548
|
+
it 'denies undef for a non-optional type' do
|
549
|
+
expect do
|
550
|
+
catalog = compile_to_catalog(<<-MANIFEST)
|
551
|
+
class foo(Integer $x) { }
|
552
|
+
class { 'foo': x => undef }
|
553
|
+
MANIFEST
|
554
|
+
end.to raise_error(/type Integer, got Undef/)
|
555
|
+
end
|
556
|
+
|
510
557
|
it 'denies non type compliant default argument' do
|
511
558
|
expect do
|
512
559
|
catalog = compile_to_catalog(<<-MANIFEST)
|
@@ -516,6 +563,15 @@ describe "Puppet::Parser::Compiler" do
|
|
516
563
|
end.to raise_error(/type Integer, got String/)
|
517
564
|
end
|
518
565
|
|
566
|
+
it 'denies undef as the default for a non-optional type' do
|
567
|
+
expect do
|
568
|
+
catalog = compile_to_catalog(<<-MANIFEST)
|
569
|
+
class foo(Integer $x = undef) { }
|
570
|
+
class { 'foo': }
|
571
|
+
MANIFEST
|
572
|
+
end.to raise_error(/type Integer, got Undef/)
|
573
|
+
end
|
574
|
+
|
519
575
|
it 'accepts a Resource as a Type' do
|
520
576
|
catalog = compile_to_catalog(<<-MANIFEST)
|
521
577
|
class foo(Type[Bar] $x) {
|
@@ -8,7 +8,13 @@ describe Puppet::Type.type(:user), '(integration)', :unless => Puppet.features.m
|
|
8
8
|
include PuppetSpec::Compiler
|
9
9
|
|
10
10
|
context "when set to purge ssh keys from a file" do
|
11
|
-
let(:tempfile)
|
11
|
+
let(:tempfile) do
|
12
|
+
file_containing('user_spec', <<-EOF)
|
13
|
+
# comment
|
14
|
+
ssh-rsa KEY-DATA key-name
|
15
|
+
ssh-rsa KEY-DATA key name
|
16
|
+
EOF
|
17
|
+
end
|
12
18
|
# must use an existing user, or the generated key resource
|
13
19
|
# will fail on account of an invalid user for the key
|
14
20
|
# - root should be a safe default
|
@@ -32,5 +38,20 @@ describe Puppet::Type.type(:user), '(integration)', :unless => Puppet.features.m
|
|
32
38
|
File.read(tempfile).should_not =~ /key-name/
|
33
39
|
end
|
34
40
|
end
|
41
|
+
|
42
|
+
context "with multiple unnamed keys" do
|
43
|
+
let(:tempfile) do
|
44
|
+
file_containing('user_spec', <<-EOF)
|
45
|
+
# comment
|
46
|
+
ssh-rsa KEY-DATA1
|
47
|
+
ssh-rsa KEY-DATA2
|
48
|
+
EOF
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should purge authorized ssh keys" do
|
52
|
+
apply_compiled_manifest(manifest)
|
53
|
+
File.read(tempfile).should_not =~ /KEY-DATA/
|
54
|
+
end
|
55
|
+
end
|
35
56
|
end
|
36
57
|
end
|
@@ -57,6 +57,7 @@ module PuppetSpec::Files
|
|
57
57
|
dir_contained_in(tmpdir(name), contents_hash)
|
58
58
|
end
|
59
59
|
|
60
|
+
def dir_contained_in(dir, contents_hash) PuppetSpec::Files.dir_contained_in(dir, contents_hash) end
|
60
61
|
def self.dir_contained_in(dir, contents_hash)
|
61
62
|
contents_hash.each do |k,v|
|
62
63
|
if v.is_a?(Hash)
|
@@ -97,6 +97,17 @@ describe Puppet::Environments do
|
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
|
+
it "raises error when environment not found" do
|
101
|
+
directory_tree = FS::MemoryFile.a_directory(File.expand_path("envdir"), [])
|
102
|
+
|
103
|
+
loader_from(:filesystem => [directory_tree],
|
104
|
+
:directory => directory_tree) do |loader|
|
105
|
+
expect do
|
106
|
+
loader.get!("does_not_exist")
|
107
|
+
end.to raise_error(Puppet::Environments::EnvironmentNotFound)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
100
111
|
it "returns nil if an environment can't be found" do
|
101
112
|
directory_tree = FS::MemoryFile.a_directory("envdir", [])
|
102
113
|
|
@@ -106,6 +117,17 @@ describe Puppet::Environments do
|
|
106
117
|
end
|
107
118
|
end
|
108
119
|
|
120
|
+
it "raises error if an environment can't be found" do
|
121
|
+
directory_tree = FS::MemoryFile.a_directory("envdir", [])
|
122
|
+
|
123
|
+
loader_from(:filesystem => [directory_tree],
|
124
|
+
:directory => directory_tree) do |loader|
|
125
|
+
expect do
|
126
|
+
loader.get!("env_not_in_this_list")
|
127
|
+
end.to raise_error(Puppet::Environments::EnvironmentNotFound)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
109
131
|
context "with an environment.conf" do
|
110
132
|
let(:envdir) do
|
111
133
|
FS::MemoryFile.a_directory(File.expand_path("envdir"), [
|
@@ -295,6 +317,49 @@ config_version=$vardir/random/scripts
|
|
295
317
|
with_config_version(File.expand_path('/some/script'))
|
296
318
|
end
|
297
319
|
end
|
320
|
+
|
321
|
+
it "should update environment settings if environment.conf has changed and timeout has expired" do
|
322
|
+
base_dir = File.expand_path("envdir")
|
323
|
+
original_envdir = FS::MemoryFile.a_directory(base_dir, [
|
324
|
+
FS::MemoryFile.a_directory("env3", [
|
325
|
+
FS::MemoryFile.a_regular_file_containing("environment.conf", <<-EOF)
|
326
|
+
manifest=/manifest_orig
|
327
|
+
modulepath=/modules_orig
|
328
|
+
environment_timeout=0
|
329
|
+
EOF
|
330
|
+
]),
|
331
|
+
])
|
332
|
+
|
333
|
+
FS.overlay(original_envdir) do
|
334
|
+
dir_loader = Puppet::Environments::Directories.new(original_envdir, [])
|
335
|
+
loader = Puppet::Environments::Cached.new(dir_loader)
|
336
|
+
Puppet.override(:environments => loader) do
|
337
|
+
original_env = loader.get("env3") # force the environment.conf to be read
|
338
|
+
|
339
|
+
changed_envdir = FS::MemoryFile.a_directory(base_dir, [
|
340
|
+
FS::MemoryFile.a_directory("env3", [
|
341
|
+
FS::MemoryFile.a_regular_file_containing("environment.conf", <<-EOF)
|
342
|
+
manifest=/manifest_changed
|
343
|
+
modulepath=/modules_changed
|
344
|
+
environment_timeout=0
|
345
|
+
EOF
|
346
|
+
]),
|
347
|
+
])
|
348
|
+
|
349
|
+
FS.overlay(changed_envdir) do
|
350
|
+
changed_env = loader.get("env3")
|
351
|
+
|
352
|
+
expect(original_env).to environment(:env3).
|
353
|
+
with_manifest(File.expand_path("/manifest_orig")).
|
354
|
+
with_full_modulepath([File.expand_path("/modules_orig")])
|
355
|
+
|
356
|
+
expect(changed_env).to environment(:env3).
|
357
|
+
with_manifest(File.expand_path("/manifest_changed")).
|
358
|
+
with_full_modulepath([File.expand_path("/modules_changed")])
|
359
|
+
end
|
360
|
+
end
|
361
|
+
end
|
362
|
+
end
|
298
363
|
end
|
299
364
|
end
|
300
365
|
|
@@ -315,6 +380,12 @@ config_version=$vardir/random/scripts
|
|
315
380
|
expect(loader.get(:doesnotexist)).to be_nil
|
316
381
|
end
|
317
382
|
|
383
|
+
it "raises error if environment is not found" do
|
384
|
+
expect do
|
385
|
+
loader.get!(:doesnotexist)
|
386
|
+
end.to raise_error(Puppet::Environments::EnvironmentNotFound)
|
387
|
+
end
|
388
|
+
|
318
389
|
it "gets a basic conf" do
|
319
390
|
conf = loader.get_conf(:static1)
|
320
391
|
expect(conf.modulepath).to eq('')
|
@@ -336,11 +407,34 @@ config_version=$vardir/random/scripts
|
|
336
407
|
end
|
337
408
|
end
|
338
409
|
|
410
|
+
|
411
|
+
describe "cached loaders" do
|
412
|
+
let(:cached1) { Puppet::Node::Environment.create(:cached1, []) }
|
413
|
+
let(:cached2) { Puppet::Node::Environment.create(:cached2, []) }
|
414
|
+
let(:static_loader) { Puppet::Environments::Static.new(cached1, cached2) }
|
415
|
+
let(:loader) { Puppet::Environments::Cached.new(static_loader) }
|
416
|
+
|
417
|
+
it "gets an environment" do
|
418
|
+
expect(loader.get(:cached2)).to eq(cached2)
|
419
|
+
end
|
420
|
+
|
421
|
+
it "returns nil if env not found" do
|
422
|
+
expect(loader.get(:doesnotexist)).to be_nil
|
423
|
+
end
|
424
|
+
|
425
|
+
it "raises error if environment is not found" do
|
426
|
+
expect do
|
427
|
+
loader.get!(:doesnotexist)
|
428
|
+
end.to raise_error(Puppet::Environments::EnvironmentNotFound)
|
429
|
+
end
|
430
|
+
end
|
431
|
+
|
339
432
|
RSpec::Matchers.define :environment do |name|
|
340
433
|
match do |env|
|
341
434
|
env.name == name &&
|
342
435
|
(!@manifest || @manifest == env.manifest) &&
|
343
436
|
(!@modulepath || @modulepath == env.modulepath) &&
|
437
|
+
(!@full_modulepath || @full_modulepath == env.full_modulepath) &&
|
344
438
|
(!@config_version || @config_version == env.config_version)
|
345
439
|
end
|
346
440
|
|
@@ -352,6 +446,10 @@ config_version=$vardir/random/scripts
|
|
352
446
|
@modulepath = modulepath
|
353
447
|
end
|
354
448
|
|
449
|
+
chain :with_full_modulepath do |full_modulepath|
|
450
|
+
@full_modulepath = full_modulepath
|
451
|
+
end
|
452
|
+
|
355
453
|
chain :with_config_version do |config_version|
|
356
454
|
@config_version = config_version
|
357
455
|
end
|
@@ -360,6 +458,7 @@ config_version=$vardir/random/scripts
|
|
360
458
|
"environment #{expected}" +
|
361
459
|
(@manifest ? " with manifest #{@manifest}" : "") +
|
362
460
|
(@modulepath ? " with modulepath [#{@modulepath.join(', ')}]" : "") +
|
461
|
+
(@full_modulepath ? " with full_modulepath [#{@full_modulepath.join(', ')}]" : "") +
|
363
462
|
(@config_version ? " with config_version #{@config_version}" : "")
|
364
463
|
end
|
365
464
|
|
@@ -22,6 +22,10 @@ describe Puppet::Network::HTTP::WEBrick do
|
|
22
22
|
s
|
23
23
|
end
|
24
24
|
|
25
|
+
let(:mock_ssl_context) do
|
26
|
+
stub('ssl_context', :ciphers= => nil)
|
27
|
+
end
|
28
|
+
|
25
29
|
let(:mock_webrick) do
|
26
30
|
stub('webrick',
|
27
31
|
:[] => {},
|
@@ -29,7 +33,8 @@ describe Puppet::Network::HTTP::WEBrick do
|
|
29
33
|
:status => :Running,
|
30
34
|
:mount => nil,
|
31
35
|
:start => nil,
|
32
|
-
:shutdown => nil
|
36
|
+
:shutdown => nil,
|
37
|
+
:ssl_context => mock_ssl_context)
|
33
38
|
end
|
34
39
|
|
35
40
|
before :each do
|
@@ -251,7 +256,15 @@ describe Puppet::Network::HTTP::WEBrick do
|
|
251
256
|
end
|
252
257
|
|
253
258
|
it "should reject SSLv2" do
|
254
|
-
server.setup_ssl[:SSLOptions]
|
259
|
+
options = server.setup_ssl[:SSLOptions]
|
260
|
+
|
261
|
+
expect(options & OpenSSL::SSL::OP_NO_SSLv2).to eq(OpenSSL::SSL::OP_NO_SSLv2)
|
262
|
+
end
|
263
|
+
|
264
|
+
it "should reject SSLv3" do
|
265
|
+
options = server.setup_ssl[:SSLOptions]
|
266
|
+
|
267
|
+
expect(options & OpenSSL::SSL::OP_NO_SSLv3).to eq(OpenSSL::SSL::OP_NO_SSLv3)
|
255
268
|
end
|
256
269
|
|
257
270
|
it "should configure the verification method as 'OpenSSL::SSL::VERIFY_PEER'" do
|
@@ -267,5 +280,11 @@ describe Puppet::Network::HTTP::WEBrick do
|
|
267
280
|
it "should set the certificate name to 'nil'" do
|
268
281
|
server.setup_ssl[:SSLCertName].should be_nil
|
269
282
|
end
|
283
|
+
|
284
|
+
it "specifies the allowable ciphers" do
|
285
|
+
mock_ssl_context.expects(:ciphers=).with(server.class::CIPHERS)
|
286
|
+
|
287
|
+
server.create_server('localhost', '8888')
|
288
|
+
end
|
270
289
|
end
|
271
290
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
#! /usr/bin/env ruby
|
2
1
|
require 'spec_helper'
|
3
2
|
require 'puppet_spec/compiler'
|
3
|
+
require 'matchers/resource'
|
4
4
|
|
5
5
|
class CompilerTestResource
|
6
6
|
attr_accessor :builtin, :virtual, :evaluated, :type, :title
|
@@ -53,6 +53,7 @@ end
|
|
53
53
|
|
54
54
|
describe Puppet::Parser::Compiler do
|
55
55
|
include PuppetSpec::Files
|
56
|
+
include Matchers::Resource
|
56
57
|
|
57
58
|
def resource(type, title)
|
58
59
|
Puppet::Parser::Resource.new(type, title, :scope => @scope)
|
@@ -864,6 +865,23 @@ describe Puppet::Parser::Compiler do
|
|
864
865
|
it "should fail if the class doesn't exist" do
|
865
866
|
expect { compile_to_catalog('', node) }.to raise_error(Puppet::Error, /Could not find class something/)
|
866
867
|
end
|
868
|
+
|
869
|
+
it 'evaluates classes declared with parameters before unparameterized classes' do
|
870
|
+
node = Puppet::Node.new('someone', :classes => { 'app::web' => {}, 'app' => { 'port' => 8080 } })
|
871
|
+
manifest = <<-MANIFEST
|
872
|
+
class app($port = 80) { }
|
873
|
+
|
874
|
+
class app::web($port = $app::port) inherits app {
|
875
|
+
notify { expected: message => "$port" }
|
876
|
+
}
|
877
|
+
MANIFEST
|
878
|
+
|
879
|
+
catalog = compile_to_catalog(manifest, node)
|
880
|
+
|
881
|
+
expect(catalog).to have_resource("Class[App]").with_parameter(:port, 8080)
|
882
|
+
expect(catalog).to have_resource("Class[App::Web]")
|
883
|
+
expect(catalog).to have_resource("Notify[expected]").with_parameter(:message, "8080")
|
884
|
+
end
|
867
885
|
end
|
868
886
|
end
|
869
887
|
end
|
@@ -8,6 +8,7 @@ describe "lookup function" do
|
|
8
8
|
|
9
9
|
before(:each) do
|
10
10
|
Puppet[:binder] = true
|
11
|
+
Puppet[:parser] = 'future'
|
11
12
|
end
|
12
13
|
|
13
14
|
it "must be called with at least a name to lookup" do
|
@@ -46,9 +47,9 @@ describe "lookup function" do
|
|
46
47
|
expect(scope.function_lookup(['a_value'])).to eq('from_hiera')
|
47
48
|
end
|
48
49
|
|
49
|
-
it "returns
|
50
|
+
it "returns nil when the requested value is not bound and undef is accepted" do
|
50
51
|
scope = scope_with_injections_from(bound(bind_single("a_value", "something")))
|
51
|
-
expect(scope.function_lookup(['not_bound_value',{'accept_undef' => true}])).to eq(
|
52
|
+
expect(scope.function_lookup(['not_bound_value',{'accept_undef' => true}])).to eq(nil)
|
52
53
|
end
|
53
54
|
|
54
55
|
it "fails if the requested value is not bound and undef is not allowed" do
|
@@ -84,35 +85,35 @@ describe "lookup function" do
|
|
84
85
|
|
85
86
|
it "yields to a given lambda and returns the result" do
|
86
87
|
scope = scope_with_injections_from(bound(bind_single("a_value", "something")))
|
87
|
-
expect(scope.function_lookup(['a_value', ast_lambda('|$x|{something_else}')])).to eq('something_else')
|
88
|
+
expect(scope.function_lookup(['a_value', ast_lambda(scope, '|$x|{something_else}')])).to eq('something_else')
|
88
89
|
end
|
89
90
|
|
90
91
|
it "fails if given lambda produces undef" do
|
91
92
|
scope = scope_with_injections_from(bound(bind_single("a_value", "something")))
|
92
93
|
expect do
|
93
|
-
scope.function_lookup(['a_value', ast_lambda('|$x|{undef}')])
|
94
|
+
scope.function_lookup(['a_value', ast_lambda(scope, '|$x|{undef}')])
|
94
95
|
end.to raise_error(/did not find a value for the name 'a_value'/)
|
95
96
|
end
|
96
97
|
|
97
98
|
it "yields name and result to a given lambda" do
|
98
99
|
scope = scope_with_injections_from(bound(bind_single("a_value", "something")))
|
99
|
-
expect(scope.function_lookup(['a_value', ast_lambda('|$name, $result|{[$name, $result]}')])).to eq(['a_value', 'something'])
|
100
|
+
expect(scope.function_lookup(['a_value', ast_lambda(scope, '|$name, $result|{[$name, $result]}')])).to eq(['a_value', 'something'])
|
100
101
|
end
|
101
102
|
|
102
103
|
it "yields name and result and default to a given lambda" do
|
103
104
|
scope = scope_with_injections_from(bound(bind_single("a_value", "something")))
|
104
105
|
expect(scope.function_lookup(['a_value', {'default' => 'cigar'},
|
105
|
-
ast_lambda('|$name, $result, $d|{[$name, $result, $d]}')])).to eq(['a_value', 'something', 'cigar'])
|
106
|
+
ast_lambda(scope, '|$name, $result, $d|{[$name, $result, $d]}')])).to eq(['a_value', 'something', 'cigar'])
|
106
107
|
end
|
107
108
|
|
108
109
|
it "yields to a given lambda and returns the result when giving name and type" do
|
109
110
|
scope = scope_with_injections_from(bound(bind_single("a_value", "something")))
|
110
|
-
expect(scope.function_lookup(['a_value', 'String', ast_lambda('|$x|{something_else}')])).to eq('something_else')
|
111
|
+
expect(scope.function_lookup(['a_value', 'String', ast_lambda(scope, '|$x|{something_else}')])).to eq('something_else')
|
111
112
|
end
|
112
113
|
|
113
114
|
it "yields :undef when value is not found and using a lambda" do
|
114
115
|
scope = scope_with_injections_from(bound(bind_single("a_value", "something")))
|
115
|
-
expect(scope.function_lookup(['not_bound_value', ast_lambda('|$x|{ if $x == undef {good} else {bad}}')])).to eq('good')
|
116
|
+
expect(scope.function_lookup(['not_bound_value', ast_lambda(scope, '|$x|{ if $x == undef {good} else {bad}}')])).to eq('good')
|
116
117
|
end
|
117
118
|
|
118
119
|
def scope_with_injections_from(binder)
|
@@ -137,10 +138,10 @@ describe "lookup function" do
|
|
137
138
|
Puppet::Pops::Binder::Binder.new(layered_bindings)
|
138
139
|
end
|
139
140
|
|
140
|
-
def ast_lambda(puppet_source)
|
141
|
+
def ast_lambda(scope, puppet_source)
|
141
142
|
puppet_source = "fake_func() " + puppet_source
|
142
|
-
|
143
|
-
model =
|
144
|
-
|
143
|
+
evaluator = Puppet::Pops::Parser::EvaluatingParser.new()
|
144
|
+
model = evaluator.parse_string(puppet_source, __FILE__).current
|
145
|
+
evaluator.closure(model.body.lambda, scope)
|
145
146
|
end
|
146
147
|
end
|