diff options
Diffstat (limited to 'spec/functional/resource/env_spec.rb')
-rwxr-xr-x | spec/functional/resource/env_spec.rb | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/spec/functional/resource/env_spec.rb b/spec/functional/resource/env_spec.rb index 9002d4b727..24fe5e1dff 100755 --- a/spec/functional/resource/env_spec.rb +++ b/spec/functional/resource/env_spec.rb @@ -24,6 +24,8 @@ describe Chef::Resource::Env, :windows_only do let(:chef_env_test_mixed_case) { 'chefENVtest' } let(:env_value1) { 'value1' } let(:env_value2) { 'value2' } + + let(:env_value_expandable) { '%SystemRoot%' } let(:test_run_context) { node = Chef::Node.new node.default['platform'] = 'windows' @@ -71,6 +73,14 @@ describe Chef::Resource::Env, :windows_only do test_resource.run_action(:create) expect(ENV[chef_env_test_lower_case]).to eq(env_value2) end + + it 'should not expand environment variables if the variable is not PATH' do + expect(ENV[chef_env_test_lower_case]).to eq(nil) + test_resource.key_name(chef_env_test_lower_case) + test_resource.value(env_value_expandable) + test_resource.run_action(:create) + expect(ENV[chef_env_test_lower_case]).to eq(env_value_expandable) + end end context "when the modify action is invoked" do @@ -102,6 +112,42 @@ describe Chef::Resource::Env, :windows_only do test_resource.run_action(:modify) expect(ENV[chef_env_test_lower_case]).to eq(env_value2) end + + it 'should not expand environment variables if the variable is not PATH' do + test_resource.key_name(chef_env_test_lower_case) + test_resource.value(env_value1) + test_resource.run_action(:create) + expect(ENV[chef_env_test_lower_case]).to eq(env_value1) + test_resource.value(env_value_expandable) + test_resource.run_action(:modify) + expect(ENV[chef_env_test_lower_case]).to eq(env_value_expandable) + end + + context 'when using PATH' do + let(:random_name) { Time.now.to_i } + let(:env_val) { "#{env_value_expandable}_#{random_name}"} + let(:path_before) { test_resource.provider_for_action(test_resource.action).env_value('PATH') } + + it 'should expand PATH' do + path_before.should_not include(env_val) + test_resource.key_name('PATH') + test_resource.value("#{path_before};#{env_val}") + test_resource.run_action(:create) + ENV['PATH'].should_not include(env_val) + ENV['PATH'].should include("#{random_name}") + end + + after(:each) do + # cleanup so we don't flood the path + test_resource.key_name('PATH') + test_resource.value(path_before) + test_resource.run_action(:create) + if test_resource.provider_for_action(test_resource.action).env_value('PATH') != path_before + raise 'Failed to cleanup after ourselves' + end + end + end + end context "when the delete action is invoked" do |