@@ -723,6 +723,30 @@ module PuppetEnvironments
723
723
724
724
context '#clear_all' do
725
725
let ( :service ) { ReplayExpirationService . new }
726
+ let ( :envdir ) { File . expand_path ( "envdir" ) }
727
+ let ( :default_dir ) { File . join ( envdir , "cached_env" , "modules" ) }
728
+ let ( :expected_dir ) { File . join ( envdir , "cached_env" , "site" ) }
729
+
730
+ let ( :base_dir ) do
731
+ FS ::MemoryFile . a_directory ( envdir , [
732
+ FS ::MemoryFile . a_directory ( "cached_env" , [
733
+ FS ::MemoryFile . a_missing_file ( "environment.conf" )
734
+ ] )
735
+ ] )
736
+ end
737
+
738
+ let ( :updated_dir ) do
739
+ FS ::MemoryFile . a_directory ( envdir , [
740
+ FS ::MemoryFile . a_directory ( "cached_env" , [
741
+ FS ::MemoryFile . a_directory ( "site" ) ,
742
+ FS ::MemoryFile . a_missing_directory ( "modules" ) ,
743
+ FS ::MemoryFile . a_regular_file_containing ( "environment.conf" , <<-EOF )
744
+ modulepath=site
745
+ environment_timeout=unlimited
746
+ EOF
747
+ ] )
748
+ ] )
749
+ end
726
750
727
751
it 'evicts all environments' do
728
752
with_environment_loaded ( service ) do |cached |
@@ -734,48 +758,44 @@ module PuppetEnvironments
734
758
end
735
759
end
736
760
737
- it 'clears cached environment settings' do
738
- base_dir = File . expand_path ( "envdir" )
739
- original_envdir = FS ::MemoryFile . a_directory ( base_dir , [
740
- FS ::MemoryFile . a_directory ( "env3" , [
741
- FS ::MemoryFile . a_regular_file_containing ( "environment.conf" , <<-EOF )
742
- manifest=/manifest_orig
743
- modulepath=/modules_orig
744
- environment_timeout=60
745
- EOF
746
- ] ) ,
747
- ] )
761
+ it "recomputes modulepath if 'get' is called before 'clear_all'" do
762
+ cached_loader_from ( :filesystem => [ base_dir ] , :directory => base_dir ) do |loader |
763
+ loader . get ( :cached_env )
748
764
749
- FS . overlay ( original_envdir ) do
750
- dir_loader = Puppet ::Environments ::Directories . new ( original_envdir , [ ] )
751
- loader = Puppet ::Environments ::Cached . new ( dir_loader )
752
- Puppet . override ( :environments => loader ) do
753
- original_env = loader . get ( "env3" ) # force the environment.conf to be read
765
+ expect ( Puppet . settings . value ( :modulepath , :cached_env ) ) . to eq ( default_dir )
754
766
755
- changed_envdir = FS ::MemoryFile . a_directory ( base_dir , [
756
- FS ::MemoryFile . a_directory ( "env3" , [
757
- FS ::MemoryFile . a_regular_file_containing ( "environment.conf" , <<-EOF )
758
- manifest=/manifest_changed
759
- modulepath=/modules_changed
760
- environment_timeout=60
761
- EOF
762
- ] ) ,
763
- ] )
767
+ FS . overlay ( updated_dir ) do
768
+ loader . clear_all
764
769
765
- #Clear all cached environments
770
+ expect ( loader . get ( :cached_env ) . modulepath ) . to contain_exactly ( expected_dir )
771
+ end
772
+ end
773
+ end
774
+
775
+ it "recomputes modulepath if 'list' is called before 'clear_all'" do
776
+ cached_loader_from ( :filesystem => [ base_dir ] , :directory => base_dir ) do |loader |
777
+ loader . list
778
+
779
+ expect ( Puppet . settings . value ( :modulepath , :cached_env ) ) . to eq ( default_dir )
780
+
781
+ FS . overlay ( updated_dir ) do
766
782
loader . clear_all
767
783
768
- FS . overlay ( changed_envdir ) do
769
- changed_env = loader . get ( "env3" )
784
+ expect ( loader . get ( :cached_env ) . modulepath ) . to contain_exactly ( expected_dir )
785
+ end
786
+ end
787
+ end
770
788
771
- expect ( original_env ) . to environment ( :env3 ) .
772
- with_manifest ( File . expand_path ( "/manifest_orig" ) ) .
773
- with_full_modulepath ( [ File . expand_path ( "/modules_orig" ) ] )
789
+ it "recomputes modulepath if 'get_conf' is called before 'clear_all'" do
790
+ cached_loader_from ( :filesystem => [ base_dir ] , :directory => base_dir ) do | loader |
791
+ loader . get_conf ( :cached_env )
774
792
775
- expect ( changed_env ) . to environment ( :env3 ) .
776
- with_manifest ( File . expand_path ( "/manifest_changed" ) ) .
777
- with_full_modulepath ( [ File . expand_path ( "/modules_changed" ) ] )
778
- end
793
+ expect ( Puppet . settings . value ( :modulepath , :cached_env ) ) . to eq ( default_dir )
794
+
795
+ FS . overlay ( updated_dir ) do
796
+ loader . clear_all
797
+
798
+ expect ( loader . get ( :cached_env ) . modulepath ) . to contain_exactly ( expected_dir )
779
799
end
780
800
end
781
801
end
@@ -861,6 +881,20 @@ module PuppetEnvironments
861
881
end
862
882
end
863
883
884
+ def cached_loader_from ( options , &block )
885
+ FS . overlay ( *options [ :filesystem ] ) do
886
+ environments = Puppet ::Environments ::Cached . new (
887
+ Puppet ::Environments ::Directories . new (
888
+ options [ :directory ] ,
889
+ options [ :modulepath ] || [ ]
890
+ )
891
+ )
892
+ Puppet . override ( :environments => environments ) do
893
+ yield environments
894
+ end
895
+ end
896
+ end
897
+
864
898
def loader_from ( options , &block )
865
899
FS . overlay ( *options [ :filesystem ] ) do
866
900
environments = Puppet ::Environments ::Directories . new (
0 commit comments