Skip to content

Commit 0ad78cb

Browse files
committed
(PUP-10942) Use cached_loader_from
1 parent be5a65f commit 0ad78cb

File tree

1 file changed

+32
-40
lines changed

1 file changed

+32
-40
lines changed

spec/unit/environments_spec.rb

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
require 'puppet/environments'
33
require 'puppet/file_system'
44

5-
module PuppetEnvironments
65
describe Puppet::Environments do
76
FS = Puppet::FileSystem
87

@@ -402,33 +401,29 @@ module PuppetEnvironments
402401
]),
403402
])
404403

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
420406

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+
])
423416

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")
427419

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")])
432427
end
433428
end
434429
end
@@ -554,24 +549,24 @@ module PuppetEnvironments
554549

555550
describe "cached loaders" do
556551
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(
559554
environment(:an_environment),
560555
environment(:another_environment),
561556
environment(:symlinked_environment))
562557
end
563558
end
564559

565560
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}"])
568563
end
569564
end
570565

571566
context "#get" do
572567
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)
575570
end
576571
end
577572

@@ -588,16 +583,16 @@ module PuppetEnvironments
588583
end
589584

590585
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
593588
end
594589
end
595590
end
596591

597592
context "#get!" do
598593
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)
601596
end
602597
end
603598

@@ -614,9 +609,9 @@ module PuppetEnvironments
614609
end
615610

616611
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|
618613
expect do
619-
Puppet::Environments::Cached.new(loader).get!(:doesnotexist)
614+
loader.get!(:doesnotexist)
620615
end.to raise_error(Puppet::Environments::EnvironmentNotFound)
621616
end
622617
end
@@ -643,8 +638,6 @@ module PuppetEnvironments
643638
end
644639

645640
it "evicts an expired environment" do
646-
service = ReplayExpirationService.new
647-
648641
expect(service).to receive(:expired?).and_return(true)
649642

650643
with_environment_loaded(service) do |cached|
@@ -947,4 +940,3 @@ def evicted(env_name)
947940
end
948941
end
949942
end
950-
end

0 commit comments

Comments
 (0)