puppet 3.7.3 → 3.7.4

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.

Files changed (57) hide show
  1. data/Gemfile +4 -0
  2. data/ext/build_defaults.yaml +2 -2
  3. data/ext/project_data.yaml +2 -2
  4. data/lib/puppet.rb +1 -1
  5. data/lib/puppet/configurer.rb +7 -4
  6. data/lib/puppet/environments.rb +68 -51
  7. data/lib/puppet/functions/scanf.rb +46 -0
  8. data/lib/puppet/network/http/webrick/rest.rb +3 -0
  9. data/lib/puppet/parser/ast/pops_bridge.rb +2 -1
  10. data/lib/puppet/parser/compiler.rb +11 -3
  11. data/lib/puppet/parser/functions/realize.rb +7 -2
  12. data/lib/puppet/parser/functions/scanf.rb +35 -0
  13. data/lib/puppet/parser/relationship.rb +21 -6
  14. data/lib/puppet/parser/resource.rb +11 -4
  15. data/lib/puppet/pops.rb +7 -0
  16. data/lib/puppet/pops/evaluator/access_operator.rb +1 -6
  17. data/lib/puppet/pops/evaluator/collector_transformer.rb +219 -0
  18. data/lib/puppet/pops/evaluator/collectors/abstract_collector.rb +86 -0
  19. data/lib/puppet/pops/evaluator/collectors/catalog_collector.rb +25 -0
  20. data/lib/puppet/pops/evaluator/collectors/exported_collector.rb +66 -0
  21. data/lib/puppet/pops/evaluator/collectors/fixed_set_collector.rb +37 -0
  22. data/lib/puppet/pops/evaluator/compare_operator.rb +8 -28
  23. data/lib/puppet/pops/evaluator/evaluator_impl.rb +4 -18
  24. data/lib/puppet/pops/evaluator/relationship_operator.rb +4 -0
  25. data/lib/puppet/pops/evaluator/runtime3_support.rb +2 -2
  26. data/lib/puppet/pops/parser/egrammar.ra +3 -3
  27. data/lib/puppet/pops/parser/eparser.rb +3 -3
  28. data/lib/puppet/pops/parser/evaluating_parser.rb +4 -0
  29. data/lib/puppet/pops/types/type_calculator.rb +19 -8
  30. data/lib/puppet/pops/types/type_parser.rb +1 -4
  31. data/lib/puppet/provider/service/redhat.rb +6 -3
  32. data/lib/puppet/resource/catalog.rb +12 -1
  33. data/lib/puppet/settings/environment_conf.rb +7 -8
  34. data/lib/puppet/type/cron.rb +5 -1
  35. data/lib/puppet/type/file/content.rb +1 -1
  36. data/lib/puppet/util/tagging.rb +21 -2
  37. data/lib/puppet/version.rb +1 -1
  38. data/spec/integration/indirector/catalog/compiler_spec.rb +11 -0
  39. data/spec/integration/parser/collector_spec.rb +41 -0
  40. data/spec/integration/parser/compiler_spec.rb +16 -0
  41. data/spec/integration/parser/future_compiler_spec.rb +1 -1
  42. data/spec/unit/environments_spec.rb +238 -118
  43. data/spec/unit/functions/scanf_spec.rb +36 -0
  44. data/spec/unit/network/http/rack/rest_spec.rb +11 -8
  45. data/spec/unit/network/http/webrick/rest_spec.rb +19 -0
  46. data/spec/unit/parser/compiler_spec.rb +0 -27
  47. data/spec/unit/pops/evaluator/access_ops_spec.rb +9 -9
  48. data/spec/unit/pops/evaluator/comparison_ops_spec.rb +14 -8
  49. data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +20 -8
  50. data/spec/unit/pops/parser/parse_basic_expressions_spec.rb +10 -0
  51. data/spec/unit/pops/parser/parse_heredoc_spec.rb +30 -0
  52. data/spec/unit/pops/types/type_calculator_spec.rb +18 -0
  53. data/spec/unit/pops/types/type_parser_spec.rb +2 -2
  54. data/spec/unit/provider/service/redhat_spec.rb +2 -1
  55. data/spec/unit/type/cron_spec.rb +24 -24
  56. data/spec/unit/util/tagging_spec.rb +7 -0
  57. metadata +11 -2
@@ -68,6 +68,35 @@ describe Puppet::Parser::Collector do
68
68
  MANIFEST
69
69
  end
70
70
 
71
+ it "matches with bare word" do
72
+ expect_the_message_to_be(["wanted"], <<-MANIFEST)
73
+ @notify { "testing": tag => ["one"], message => "wanted" }
74
+ Notify <| tag == one |>
75
+ MANIFEST
76
+ end
77
+
78
+ it "matches with single quoted string" do
79
+ expect_the_message_to_be(["wanted"], <<-MANIFEST)
80
+ @notify { "testing": tag => ["one"], message => "wanted" }
81
+ Notify <| tag == 'one' |>
82
+ MANIFEST
83
+ end
84
+
85
+ it "matches with double quoted string" do
86
+ expect_the_message_to_be(["wanted"], <<-MANIFEST)
87
+ @notify { "testing": tag => ["one"], message => "wanted" }
88
+ Notify <| tag == "one" |>
89
+ MANIFEST
90
+ end
91
+
92
+ it "matches with double quoted string with interpolated expression" do
93
+ expect_the_message_to_be(["wanted"], <<-MANIFEST)
94
+ @notify { "testing": tag => ["one"], message => "wanted" }
95
+ $x = 'one'
96
+ Notify <| tag == "$x" |>
97
+ MANIFEST
98
+ end
99
+
71
100
  it "allows criteria to be combined with 'and'" do
72
101
  expect_the_message_to_be(["the message"], <<-MANIFEST)
73
102
  @notify { "testing": message => "the message" }
@@ -154,6 +183,18 @@ describe Puppet::Parser::Collector do
154
183
  end.to raise_error(/Classes cannot be collected/)
155
184
  end
156
185
 
186
+ it "does not collect resources that don't exist" do
187
+ node = Puppet::Node.new('the node')
188
+ expect do
189
+ catalog = compile_to_catalog(<<-MANIFEST, node)
190
+ class theclass {
191
+ @notify { "testing": message => "good message" }
192
+ }
193
+ SomeResource <| |>
194
+ MANIFEST
195
+ end.to raise_error(/Resource type someresource doesn't exist/)
196
+ end
197
+
157
198
  context "overrides" do
158
199
  it "modifies an existing array" do
159
200
  expect_the_message_to_be([["original message", "extra message"]], <<-MANIFEST)
@@ -522,4 +522,20 @@ describe "Puppet::Parser::Compiler" do
522
522
  expect(catalog).to have_resource("Notify[nbr2]").with_parameter(:message, 'overridden')
523
523
  end
524
524
  end
525
+
526
+
527
+ context "when converting catalog to resource" do
528
+ it "the same environment is used for compilation as for transformation to resource form" do
529
+ Puppet[:code] = <<-MANIFEST
530
+ notify { 'dummy':
531
+ }
532
+ MANIFEST
533
+
534
+ Puppet::Parser::Resource::Catalog.any_instance.expects(:to_resource).with do |catalog|
535
+ Puppet.lookup(:current_environment).name == :production
536
+ end
537
+
538
+ Puppet::Parser::Compiler.compile(Puppet::Node.new("mynode"))
539
+ end
540
+ end
525
541
  end
@@ -270,7 +270,7 @@ describe "Puppet::Parser::Compiler" do
270
270
  end
271
271
 
272
272
  it "between collection expressions" do
273
- assert_creates_relationships("File <| mode == 0644 |> -> File <| mode == 0755 |>",
273
+ assert_creates_relationships("File <| mode == '0644' |> -> File <| mode == '0755' |>",
274
274
  :relationships => [['a', 'd'],
275
275
  ['b', 'd'],
276
276
  ['c', 'd'],
@@ -2,6 +2,7 @@ require 'spec_helper'
2
2
  require 'puppet/environments'
3
3
  require 'puppet/file_system'
4
4
  require 'matchers/include'
5
+ require 'matchers/include_in_order'
5
6
 
6
7
  module PuppetEnvironments
7
8
  describe Puppet::Environments do
@@ -9,55 +10,50 @@ describe Puppet::Environments do
9
10
 
10
11
  FS = Puppet::FileSystem
11
12
 
12
- describe "directories loader" do
13
- before(:each) do
14
- Puppet.settings.initialize_global_settings
15
- end
13
+ before(:each) do
14
+ Puppet.settings.initialize_global_settings
15
+ Puppet[:environment_timeout] = "unlimited"
16
+ end
17
+
18
+ let(:directory_tree) do
19
+ FS::MemoryFile.a_directory(File.expand_path("envdir"), [
20
+ FS::MemoryFile.a_regular_file_containing("ignored_file", ''),
21
+ FS::MemoryFile.a_directory("an_environment", [
22
+ FS::MemoryFile.a_missing_file("environment.conf"),
23
+ FS::MemoryFile.a_directory("modules"),
24
+ FS::MemoryFile.a_directory("manifests"),
25
+ ]),
26
+ FS::MemoryFile.a_directory("another_environment", [
27
+ FS::MemoryFile.a_missing_file("environment.conf"),
28
+ ]),
29
+ FS::MemoryFile.a_missing_file("doesnotexist"),
30
+ ])
31
+ end
16
32
 
33
+ describe "directories loader" do
17
34
  it "lists environments" do
18
35
  global_path_1_location = File.expand_path("global_path_1")
19
36
  global_path_2_location = File.expand_path("global_path_2")
20
37
  global_path_1 = FS::MemoryFile.a_directory(global_path_1_location)
21
38
  global_path_2 = FS::MemoryFile.a_directory(global_path_2_location)
22
39
 
23
- envdir = FS::MemoryFile.a_directory(File.expand_path("envdir"), [
24
- FS::MemoryFile.a_directory("env1", [
25
- FS::MemoryFile.a_missing_file("environment.conf"),
26
- FS::MemoryFile.a_directory("modules"),
27
- FS::MemoryFile.a_directory("manifests"),
28
- ]),
29
- FS::MemoryFile.a_directory("env2", [
30
- FS::MemoryFile.a_missing_file("environment.conf"),
31
- ]),
32
- ])
33
-
34
- loader_from(:filesystem => [envdir, global_path_1, global_path_2],
35
- :directory => envdir,
40
+ loader_from(:filesystem => [directory_tree, global_path_1, global_path_2],
41
+ :directory => directory_tree,
36
42
  :modulepath => [global_path_1_location, global_path_2_location]) do |loader|
37
43
  expect(loader.list).to include_in_any_order(
38
- environment(:env1).
39
- with_manifest("#{FS.path_string(envdir)}/env1/manifests").
40
- with_modulepath(["#{FS.path_string(envdir)}/env1/modules",
44
+ environment(:an_environment).
45
+ with_manifest("#{FS.path_string(directory_tree)}/an_environment/manifests").
46
+ with_modulepath(["#{FS.path_string(directory_tree)}/an_environment/modules",
41
47
  global_path_1_location,
42
48
  global_path_2_location]),
43
- environment(:env2))
49
+ environment(:another_environment))
44
50
  end
45
51
  end
46
52
 
47
- it "does not list files" do
48
- envdir = FS::MemoryFile.a_directory(File.expand_path("envdir"), [
49
- FS::MemoryFile.a_regular_file_containing("foo", ''),
50
- FS::MemoryFile.a_directory("env1", [
51
- FS::MemoryFile.a_missing_file("environment.conf"),
52
- ]),
53
- FS::MemoryFile.a_directory("env2", [
54
- FS::MemoryFile.a_missing_file("environment.conf"),
55
- ]),
56
- ])
57
-
58
- loader_from(:filesystem => [envdir],
59
- :directory => envdir) do |loader|
60
- expect(loader.list).to include_in_any_order(environment(:env1), environment(:env2))
53
+ it "has search_paths" do
54
+ loader_from(:filesystem => [directory_tree],
55
+ :directory => directory_tree) do |loader|
56
+ expect(loader.search_paths).to eq(["file://#{directory_tree}"])
61
57
  end
62
58
  end
63
59
 
@@ -82,49 +78,25 @@ describe Puppet::Environments do
82
78
  end
83
79
 
84
80
  it "gets a particular environment" do
85
- directory_tree = FS::MemoryFile.a_directory(File.expand_path("envdir"), [
86
- FS::MemoryFile.a_directory("env1", [
87
- FS::MemoryFile.a_missing_file("environment.conf"),
88
- ]),
89
- FS::MemoryFile.a_directory("env2", [
90
- FS::MemoryFile.a_missing_file("environment.conf"),
91
- ]),
92
- ])
93
-
94
81
  loader_from(:filesystem => [directory_tree],
95
82
  :directory => directory_tree) do |loader|
96
- expect(loader.get("env1")).to environment(:env1)
83
+ expect(loader.get("an_environment")).to environment(:an_environment)
97
84
  end
98
85
  end
99
86
 
100
87
  it "raises error when environment not found" do
101
- directory_tree = FS::MemoryFile.a_directory(File.expand_path("envdir"), [])
102
-
103
88
  loader_from(:filesystem => [directory_tree],
104
89
  :directory => directory_tree) do |loader|
105
90
  expect do
106
- loader.get!("does_not_exist")
91
+ loader.get!("doesnotexist")
107
92
  end.to raise_error(Puppet::Environments::EnvironmentNotFound)
108
93
  end
109
94
  end
110
95
 
111
96
  it "returns nil if an environment can't be found" do
112
- directory_tree = FS::MemoryFile.a_directory("envdir", [])
113
-
114
97
  loader_from(:filesystem => [directory_tree],
115
98
  :directory => directory_tree) do |loader|
116
- expect(loader.get("env_not_in_this_list")).to be_nil
117
- end
118
- end
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)
99
+ expect(loader.get("doesnotexist")).to be_nil
128
100
  end
129
101
  end
130
102
 
@@ -362,53 +334,19 @@ config_version=$vardir/random/scripts
362
334
  end
363
335
 
364
336
  context "custom cache expiration service" do
365
- let(:envs_created) { Set.new }
366
- let(:envs_expired) { Set.new }
367
- let(:envs_evicted) { Set.new }
368
-
369
- it "should support registering a custom cache expiration service" do
370
-
371
- class CustomExpirationService
372
- def initialize(envs_created, envs_expired, envs_evicted)
373
- @envs_created = envs_created
374
- @envs_expired = envs_expired
375
- @envs_evicted = envs_evicted
376
- end
377
-
378
- def created(env)
379
- @envs_created << env.name
380
- end
381
- def expired?(env_name)
382
- @envs_expired << env_name
383
- true
384
- end
385
- def evicted(env_name)
386
- @envs_evicted << env_name
387
- end
388
- end
389
-
390
- Puppet[:environment_timeout] = "unlimited"
391
- directory_tree = FS::MemoryFile.a_directory(File.expand_path("envdir"), [
392
- FS::MemoryFile.a_directory("static1", [
393
- FS::MemoryFile.a_missing_file("environment.conf"),
394
- ]),
395
- ])
396
-
337
+ it "consults the custom service to expire the cache" do
397
338
  loader_from(:filesystem => [directory_tree],
398
339
  :directory => directory_tree) do |loader|
399
- begin
400
- orig_svc = Puppet::Environments::Cached.cache_expiration_service
401
- Puppet::Environments::Cached.cache_expiration_service =
402
- CustomExpirationService.new(envs_created, envs_expired, envs_evicted)
340
+ service = ReplayExpirationService.new([true])
341
+ using_expiration_service(service) do
342
+
403
343
  cached = Puppet::Environments::Cached.new(loader)
404
- cached.get(:static1)
405
- cached.get(:static1)
406
-
407
- expect(envs_created.include?(:static1)).to eq(true)
408
- expect(envs_expired.include?(:static1)).to eq(true)
409
- expect(envs_evicted.include?(:static1)).to eq(true)
410
- ensure
411
- Puppet::Environments::Cached.cache_expiration_service = orig_svc
344
+ cached.get(:an_environment)
345
+ cached.get(:an_environment)
346
+
347
+ expect(service.created_envs).to include(:an_environment)
348
+ expect(service.expired_envs).to include(:an_environment)
349
+ expect(service.evicted_envs).to include(:an_environment)
412
350
  end
413
351
  end
414
352
  end
@@ -425,6 +363,10 @@ config_version=$vardir/random/scripts
425
363
  expect(loader.list).to eq([static1, static2])
426
364
  end
427
365
 
366
+ it "has search_paths" do
367
+ expect(loader.search_paths).to eq(["data:text/plain,internal"])
368
+ end
369
+
428
370
  it "gets an environment" do
429
371
  expect(loader.get(:static2)).to eq(static2)
430
372
  end
@@ -460,25 +402,142 @@ config_version=$vardir/random/scripts
460
402
  end
461
403
  end
462
404
 
405
+ describe "combined loaders" do
406
+ let(:static1) { Puppet::Node::Environment.create(:static1, []) }
407
+ let(:static2) { Puppet::Node::Environment.create(:static2, []) }
408
+ let(:static_loader) { Puppet::Environments::Static.new(static1, static2) }
409
+ let(:directory_tree) do
410
+ FS::MemoryFile.a_directory(File.expand_path("envdir"), [
411
+ FS::MemoryFile.a_directory("an_environment", [
412
+ FS::MemoryFile.a_missing_file("environment.conf"),
413
+ FS::MemoryFile.a_directory("modules"),
414
+ FS::MemoryFile.a_directory("manifests"),
415
+ ]),
416
+ FS::MemoryFile.a_missing_file("env_does_not_exist"),
417
+ FS::MemoryFile.a_missing_file("static2"),
418
+ ])
419
+ end
463
420
 
464
- describe "cached loaders" do
465
- let(:cached1) { Puppet::Node::Environment.create(:cached1, []) }
466
- let(:cached2) { Puppet::Node::Environment.create(:cached2, []) }
467
- let(:static_loader) { Puppet::Environments::Static.new(cached1, cached2) }
468
- let(:loader) { Puppet::Environments::Cached.new(static_loader) }
421
+ it "lists environments" do
422
+ loader_from(:filesystem => [directory_tree], :directory => directory_tree) do |loader|
423
+ envs = Puppet::Environments::Combined.new(loader, static_loader).list
424
+ expect(envs[0]).to environment(:an_environment)
425
+ expect(envs[1]).to environment(:static1)
426
+ expect(envs[2]).to environment(:static2)
427
+ end
428
+ end
429
+
430
+ it "has search_paths" do
431
+ loader_from(:filesystem => [directory_tree], :directory => directory_tree) do |loader|
432
+ expect(Puppet::Environments::Combined.new(loader, static_loader).search_paths).to eq(["file://#{directory_tree}","data:text/plain,internal"])
433
+ end
434
+ end
469
435
 
470
436
  it "gets an environment" do
471
- expect(loader.get(:cached2)).to eq(cached2)
437
+ loader_from(:filesystem => [directory_tree], :directory => directory_tree) do |loader|
438
+ expect(Puppet::Environments::Combined.new(loader, static_loader).get(:an_environment)).to environment(:an_environment)
439
+ expect(Puppet::Environments::Combined.new(loader, static_loader).get(:static2)).to environment(:static2)
440
+ end
472
441
  end
473
442
 
474
443
  it "returns nil if env not found" do
475
- expect(loader.get(:doesnotexist)).to be_nil
444
+ loader_from(:filesystem => [directory_tree], :directory => directory_tree) do |loader|
445
+ expect(Puppet::Environments::Combined.new(loader, static_loader).get(:env_does_not_exist)).to be_nil
446
+ end
476
447
  end
477
448
 
478
- it "raises error if environment is not found" do
479
- expect do
480
- loader.get!(:doesnotexist)
481
- end.to raise_error(Puppet::Environments::EnvironmentNotFound)
449
+ it "raises an error if environment is not found" do
450
+ loader_from(:filesystem => [directory_tree], :directory => directory_tree) do |loader|
451
+ expect do
452
+ Puppet::Environments::Combined.new(loader, static_loader).get!(:env_does_not_exist)
453
+ end.to raise_error(Puppet::Environments::EnvironmentNotFound)
454
+ end
455
+ end
456
+
457
+ it "gets an environment.conf" do
458
+ loader_from(:filesystem => [directory_tree], :directory => directory_tree) do |loader|
459
+ expect(Puppet::Environments::Combined.new(loader, static_loader).get_conf(:an_environment)).to match_environment_conf(:an_environment).
460
+ with_env_path(directory_tree).
461
+ with_global_module_path([])
462
+ end
463
+ end
464
+ end
465
+
466
+ describe "cached loaders" do
467
+ it "lists environments" do
468
+ loader_from(:filesystem => [directory_tree], :directory => directory_tree) do |loader|
469
+ expect(Puppet::Environments::Cached.new(loader).list).to include_in_any_order(
470
+ environment(:an_environment),
471
+ environment(:another_environment))
472
+ end
473
+ end
474
+
475
+ it "has search_paths" do
476
+ loader_from(:filesystem => [directory_tree], :directory => directory_tree) do |loader|
477
+ expect(Puppet::Environments::Cached.new(loader).search_paths).to eq(["file://#{directory_tree}"])
478
+ end
479
+ end
480
+
481
+ context "#get" do
482
+ it "gets an environment" do
483
+ loader_from(:filesystem => [directory_tree], :directory => directory_tree) do |loader|
484
+ expect(Puppet::Environments::Cached.new(loader).get(:an_environment)).to environment(:an_environment)
485
+ end
486
+ end
487
+
488
+ it "does not reload the environment if it isn't expired" do
489
+ env = Puppet::Node::Environment.create(:cached, [])
490
+ mocked_loader = mock('loader')
491
+ mocked_loader.expects(:get).with(:cached).returns(env).once
492
+ mocked_loader.expects(:get_conf).with(:cached).returns(Puppet::Settings::EnvironmentConf.static_for(env, 20)).once
493
+
494
+ cached = Puppet::Environments::Cached.new(mocked_loader)
495
+
496
+ cached.get(:cached)
497
+ cached.get(:cached)
498
+ end
499
+
500
+ it "returns nil if env not found" do
501
+ loader_from(:filesystem => [directory_tree], :directory => directory_tree) do |loader|
502
+ expect(Puppet::Environments::Cached.new(loader).get(:doesnotexist)).to be_nil
503
+ end
504
+ end
505
+ end
506
+
507
+ context "#get!" do
508
+ it "gets an environment" do
509
+ loader_from(:filesystem => [directory_tree], :directory => directory_tree) do |loader|
510
+ expect(Puppet::Environments::Cached.new(loader).get!(:an_environment)).to environment(:an_environment)
511
+ end
512
+ end
513
+
514
+ it "does not reload the environment if it isn't expired" do
515
+ env = Puppet::Node::Environment.create(:cached, [])
516
+ mocked_loader = mock('loader')
517
+ mocked_loader.expects(:get).with(:cached).returns(env).once
518
+ mocked_loader.expects(:get_conf).with(:cached).returns(Puppet::Settings::EnvironmentConf.static_for(env, 20)).once
519
+
520
+ cached = Puppet::Environments::Cached.new(mocked_loader)
521
+
522
+ cached.get!(:cached)
523
+ cached.get!(:cached)
524
+ end
525
+
526
+ it "raises error if environment is not found" do
527
+ loader_from(:filesystem => [directory_tree], :directory => directory_tree) do |loader|
528
+ expect do
529
+ Puppet::Environments::Cached.new(loader).get!(:doesnotexist)
530
+ end.to raise_error(Puppet::Environments::EnvironmentNotFound)
531
+ end
532
+ end
533
+ end
534
+
535
+ it "gets an environment.conf" do
536
+ loader_from(:filesystem => [directory_tree], :directory => directory_tree) do |loader|
537
+ expect(Puppet::Environments::Cached.new(loader).get_conf(:an_environment)).to match_environment_conf(:an_environment).
538
+ with_env_path(directory_tree).
539
+ with_global_module_path([])
540
+ end
482
541
  end
483
542
  end
484
543
 
@@ -516,7 +575,33 @@ config_version=$vardir/random/scripts
516
575
  end
517
576
 
518
577
  failure_message_for_should do |env|
519
- "expected <#{env.name}: modulepath = [#{env.modulepath.join(', ')}], manifest = #{env.manifest}, config_version = #{env.config_version}> to be #{description}"
578
+ "expected <#{env.name}: modulepath = [#{env.full_modulepath.join(', ')}], manifest = #{env.manifest}, config_version = #{env.config_version}> to be #{description}"
579
+ end
580
+ end
581
+
582
+ RSpec::Matchers.define :match_environment_conf do |env_name|
583
+ match do |env_conf|
584
+ env_conf.path_to_env =~ /#{env_name}$/ &&
585
+ (!@env_path || File.join(@env_path,env_name.to_s) == env_conf.path_to_env) &&
586
+ (!@global_modulepath || @global_module_path == env_conf.global_module_path)
587
+ end
588
+
589
+ chain :with_env_path do |env_path|
590
+ @env_path = env_path.to_s
591
+ end
592
+
593
+ chain :with_global_module_path do |global_module_path|
594
+ @global_module_path = global_module_path
595
+ end
596
+
597
+ description do
598
+ "EnvironmentConf #{expected}" +
599
+ " with path_to_env: #{@env_path ? @env_path : "*"}/#{env_name}" +
600
+ (@global_module_path ? " with global_module_path [#{@global_module_path.join(', ')}]" : "")
601
+ end
602
+
603
+ failure_message_for_should do |env_conf|
604
+ "expected #{env_conf.inspect} to be #{description}"
520
605
  end
521
606
  end
522
607
 
@@ -531,5 +616,40 @@ config_version=$vardir/random/scripts
531
616
  end
532
617
  end
533
618
  end
619
+
620
+ def using_expiration_service(service)
621
+ begin
622
+ orig_svc = Puppet::Environments::Cached.cache_expiration_service
623
+ Puppet::Environments::Cached.cache_expiration_service = service
624
+ yield
625
+ ensure
626
+ Puppet::Environments::Cached.cache_expiration_service = orig_svc
627
+ end
628
+ end
629
+
630
+ class ReplayExpirationService
631
+ attr_reader :created_envs, :expired_envs, :evicted_envs
632
+
633
+ def initialize(expiration_sequence)
634
+ @created_envs = []
635
+ @expired_envs = []
636
+ @evicted_envs = []
637
+ @expiration_sequence = expiration_sequence
638
+ end
639
+
640
+ def created(env)
641
+ @created_envs << env.name
642
+ end
643
+
644
+ def expired?(env_name)
645
+ @expired_envs << env_name
646
+ @expiration_sequence.pop
647
+ end
648
+
649
+ def evicted(env_name)
650
+ @evicted_envs << env_name
651
+ end
652
+ end
653
+
534
654
  end
535
655
  end