From 92dffb29b50160e429b93f941054e5b74df8c598 Mon Sep 17 00:00:00 2001 From: Jacob Helwig Date: Sat, 5 Mar 2011 12:35:25 -0600 Subject: (#6513) Adjust P::U::Settings test name to reflect what it tests The 'should interpolate found values using the current environment' wasn't actually testing what it was describing, since the environment variable is special cased. Reviewed-by: Jesse Wolfe --- spec/unit/util/settings_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/unit/util/settings_spec.rb b/spec/unit/util/settings_spec.rb index 7bca44b76..3ed843b0b 100755 --- a/spec/unit/util/settings_spec.rb +++ b/spec/unit/util/settings_spec.rb @@ -331,7 +331,7 @@ describe Puppet::Util::Settings do @settings.value(:one, "env").should == "envval" end - it "should interpolate found values using the current environment" do + it 'should use the current environment for $environment' do @settings.setdefaults :main, :myval => ["$environment/foo", "mydocs"] @settings.value(:myval, "myenv").should == "myenv/foo" -- cgit From 64440e58967667426e7294ed38ad16e19812d8c4 Mon Sep 17 00:00:00 2001 From: Jacob Helwig Date: Sat, 5 Mar 2011 12:39:14 -0600 Subject: (#6513) Propagate the environment when doing variable lookup in settings For example with the following: test.conf: [master] rrddir = /var/lib/puppet/rrd templatedir = /var/lib/puppet/templates [env_a] templatedir = $rrddir/templates rrddir = /tmp/env_a/ The command: RUBYLIB=lib bin/puppet master --config ./test.conf --environment env_a --configprint templatedir originally produced '/var/lib/puppet/rrd/templates' instead of the expected '/tmp/env_a/templates' Reviewed-by: Jesse Wolfe --- lib/puppet/util/settings.rb | 2 +- spec/unit/util/settings_spec.rb | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb index 626ed20eb..f243b8691 100644 --- a/lib/puppet/util/settings.rb +++ b/lib/puppet/util/settings.rb @@ -91,7 +91,7 @@ class Puppet::Util::Settings varname = $2 || $1 if varname == "environment" and environment environment - elsif pval = self.value(varname) + elsif pval = self.value(varname, environment) pval else raise Puppet::DevError, "Could not find value for #{value}" diff --git a/spec/unit/util/settings_spec.rb b/spec/unit/util/settings_spec.rb index 3ed843b0b..07b712c08 100755 --- a/spec/unit/util/settings_spec.rb +++ b/spec/unit/util/settings_spec.rb @@ -284,7 +284,8 @@ describe Puppet::Util::Settings do @settings = Puppet::Util::Settings.new @settings.setdefaults :section, :config => ["/my/file", "a"], - :one => ["ONE", "a"] + :one => ["ONE", "a"], + :two => ["TWO", "b"] FileTest.stubs(:exist?).returns true Puppet.stubs(:run_mode).returns stub('run_mode', :name => :mymode) end @@ -337,6 +338,14 @@ describe Puppet::Util::Settings do @settings.value(:myval, "myenv").should == "myenv/foo" end + it "should interpolate found values using the current environment" do + text = "[main]\none = mainval\n[myname]\none = nameval\ntwo = $one/two\n" + @settings.stubs(:read_file).returns(text) + @settings.parse + + @settings.value(:two, "myname").should == "nameval/two" + end + it "should return values in a specified environment before values in the main or name sections" do text = "[env]\none = envval\n[main]\none = mainval\n[myname]\none = nameval\n" @settings.stubs(:read_file).returns(text) -- cgit