2
2
require 'puppet/environments'
3
3
require 'puppet/file_system'
4
4
5
- module PuppetEnvironments
6
5
describe Puppet ::Environments do
7
6
FS = Puppet ::FileSystem
8
7
@@ -402,33 +401,29 @@ module PuppetEnvironments
402
401
] ) ,
403
402
] )
404
403
405
- FS . overlay ( original_envdir ) do
406
- dir_loader = Puppet ::Environments ::Directories . new ( original_envdir , [ ] )
407
- loader = Puppet ::Environments ::Cached . new ( dir_loader )
408
- Puppet . override ( :environments => loader ) do
409
- original_env = loader . get ( "env3" ) # force the environment.conf to be read
410
-
411
- changed_envdir = FS ::MemoryFile . a_directory ( base_dir , [
412
- FS ::MemoryFile . a_directory ( "env3" , [
413
- FS ::MemoryFile . a_regular_file_containing ( "environment.conf" , <<-EOF )
414
- manifest=/manifest_changed
415
- modulepath=/modules_changed
416
- environment_timeout=0
417
- EOF
418
- ] ) ,
419
- ] )
404
+ cached_loader_from ( :filesystem => [ original_envdir ] , :directory => original_envdir ) do |loader |
405
+ original_env = loader . get ( "env3" ) # force the environment.conf to be read
420
406
421
- FS . overlay ( changed_envdir ) do
422
- changed_env = loader . get ( "env3" )
407
+ changed_envdir = FS ::MemoryFile . a_directory ( base_dir , [
408
+ FS ::MemoryFile . a_directory ( "env3" , [
409
+ FS ::MemoryFile . a_regular_file_containing ( "environment.conf" , <<-EOF )
410
+ manifest=/manifest_changed
411
+ modulepath=/modules_changed
412
+ environment_timeout=0
413
+ EOF
414
+ ] ) ,
415
+ ] )
423
416
424
- expect ( original_env ) . to environment ( :env3 ) .
425
- with_manifest ( File . expand_path ( "/manifest_orig" ) ) .
426
- with_full_modulepath ( [ File . expand_path ( "/modules_orig" ) ] )
417
+ FS . overlay ( changed_envdir ) do
418
+ changed_env = loader . get ( "env3" )
427
419
428
- expect ( changed_env ) . to environment ( :env3 ) .
429
- with_manifest ( File . expand_path ( "/manifest_changed" ) ) .
430
- with_full_modulepath ( [ File . expand_path ( "/modules_changed" ) ] )
431
- end
420
+ expect ( original_env ) . to environment ( :env3 ) .
421
+ with_manifest ( File . expand_path ( "/manifest_orig" ) ) .
422
+ with_full_modulepath ( [ File . expand_path ( "/modules_orig" ) ] )
423
+
424
+ expect ( changed_env ) . to environment ( :env3 ) .
425
+ with_manifest ( File . expand_path ( "/manifest_changed" ) ) .
426
+ with_full_modulepath ( [ File . expand_path ( "/modules_changed" ) ] )
432
427
end
433
428
end
434
429
end
@@ -554,24 +549,24 @@ module PuppetEnvironments
554
549
555
550
describe "cached loaders" do
556
551
it "lists environments" do
557
- loader_from ( :filesystem => [ directory_tree ] , :directory => directory_tree . children . first ) do |loader |
558
- expect ( Puppet :: Environments :: Cached . new ( loader ) . list ) . to contain_exactly (
552
+ cached_loader_from ( :filesystem => [ directory_tree ] , :directory => directory_tree . children . first ) do |loader |
553
+ expect ( loader . list ) . to contain_exactly (
559
554
environment ( :an_environment ) ,
560
555
environment ( :another_environment ) ,
561
556
environment ( :symlinked_environment ) )
562
557
end
563
558
end
564
559
565
560
it "has search_paths" do
566
- loader_from ( :filesystem => [ directory_tree ] , :directory => directory_tree . children . first ) do |loader |
567
- expect ( Puppet :: Environments :: Cached . new ( loader ) . search_paths ) . to eq ( [ "file://#{ directory_tree . children . first } " ] )
561
+ cached_loader_from ( :filesystem => [ directory_tree ] , :directory => directory_tree . children . first ) do |loader |
562
+ expect ( loader . search_paths ) . to eq ( [ "file://#{ directory_tree . children . first } " ] )
568
563
end
569
564
end
570
565
571
566
context "#get" do
572
567
it "gets an environment" do
573
- loader_from ( :filesystem => [ directory_tree ] , :directory => directory_tree . children . first ) do |loader |
574
- expect ( Puppet :: Environments :: Cached . new ( loader ) . get ( :an_environment ) ) . to environment ( :an_environment )
568
+ cached_loader_from ( :filesystem => [ directory_tree ] , :directory => directory_tree . children . first ) do |loader |
569
+ expect ( loader . get ( :an_environment ) ) . to environment ( :an_environment )
575
570
end
576
571
end
577
572
@@ -588,16 +583,16 @@ module PuppetEnvironments
588
583
end
589
584
590
585
it "returns nil if env not found" do
591
- loader_from ( :filesystem => [ directory_tree ] , :directory => directory_tree . children . first ) do |loader |
592
- expect ( Puppet :: Environments :: Cached . new ( loader ) . get ( :doesnotexist ) ) . to be_nil
586
+ cached_loader_from ( :filesystem => [ directory_tree ] , :directory => directory_tree . children . first ) do |loader |
587
+ expect ( loader . get ( :doesnotexist ) ) . to be_nil
593
588
end
594
589
end
595
590
end
596
591
597
592
context "#get!" do
598
593
it "gets an environment" do
599
- loader_from ( :filesystem => [ directory_tree ] , :directory => directory_tree . children . first ) do |loader |
600
- expect ( Puppet :: Environments :: Cached . new ( loader ) . get! ( :an_environment ) ) . to environment ( :an_environment )
594
+ cached_loader_from ( :filesystem => [ directory_tree ] , :directory => directory_tree . children . first ) do |loader |
595
+ expect ( loader . get! ( :an_environment ) ) . to environment ( :an_environment )
601
596
end
602
597
end
603
598
@@ -614,9 +609,9 @@ module PuppetEnvironments
614
609
end
615
610
616
611
it "raises error if environment is not found" do
617
- loader_from ( :filesystem => [ directory_tree ] , :directory => directory_tree . children . first ) do |loader |
612
+ cached_loader_from ( :filesystem => [ directory_tree ] , :directory => directory_tree . children . first ) do |loader |
618
613
expect do
619
- Puppet :: Environments :: Cached . new ( loader ) . get! ( :doesnotexist )
614
+ loader . get! ( :doesnotexist )
620
615
end . to raise_error ( Puppet ::Environments ::EnvironmentNotFound )
621
616
end
622
617
end
@@ -643,8 +638,6 @@ module PuppetEnvironments
643
638
end
644
639
645
640
it "evicts an expired environment" do
646
- service = ReplayExpirationService . new
647
-
648
641
expect ( service ) . to receive ( :expired? ) . and_return ( true )
649
642
650
643
with_environment_loaded ( service ) do |cached |
@@ -947,4 +940,3 @@ def evicted(env_name)
947
940
end
948
941
end
949
942
end
950
- end
0 commit comments