summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan McLellan <btm@getchef.com>2014-06-05 12:52:33 -0700
committerBryan McLellan <btm@getchef.com>2014-06-05 12:52:33 -0700
commitff690278cd0e6bf5d552a59611be0a6a258128f2 (patch)
treef9eec5e516a033c253412002798c4155f4367a32
parent697d84f20a04f55e0d1ed2d7ebb0bc10956f8cad (diff)
parent20e543ab1ccb1ea628ad76d4588545cbc520db85 (diff)
downloadchef-ff690278cd0e6bf5d552a59611be0a6a258128f2.tar.gz
Merge branch 'CHEF-5174'
-rw-r--r--lib/chef/provider/env/windows.rb2
-rw-r--r--spec/unit/provider/env/windows_spec.rb67
2 files changed, 69 insertions, 0 deletions
diff --git a/lib/chef/provider/env/windows.rb b/lib/chef/provider/env/windows.rb
index 297de94083..d0c136451f 100644
--- a/lib/chef/provider/env/windows.rb
+++ b/lib/chef/provider/env/windows.rb
@@ -34,6 +34,7 @@ class Chef
end
obj.variablevalue = @new_resource.value
obj.put_
+ ENV[@new_resource.key_name] = @new_resource.value
broadcast_env_change
end
@@ -41,6 +42,7 @@ class Chef
obj = env_obj(@new_resource.key_name)
if obj
obj.delete_
+ ENV.delete(@new_resource.key_name)
broadcast_env_change
end
end
diff --git a/spec/unit/provider/env/windows_spec.rb b/spec/unit/provider/env/windows_spec.rb
new file mode 100644
index 0000000000..329448ac05
--- /dev/null
+++ b/spec/unit/provider/env/windows_spec.rb
@@ -0,0 +1,67 @@
+#
+# Author:: Sander van Harmelen <svanharmelen@schubergphilis.com>
+# Copyright:: Copyright (c) 2014 Chef Software, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require 'spec_helper'
+
+describe Chef::Provider::Env::Windows, :windows_only do
+ before do
+ @node = Chef::Node.new
+ @events = Chef::EventDispatch::Dispatcher.new
+ @run_context = Chef::RunContext.new(@node, {}, @events)
+ @new_resource = Chef::Resource::Env.new("CHEF_WINDOWS_ENV_TEST")
+ @new_resource.value("foo")
+ @provider = Chef::Provider::Env::Windows.new(@new_resource, @run_context)
+ @provider.stub(:env_obj).and_return(double('null object').as_null_object)
+ end
+
+ describe "action_create" do
+ before do
+ ENV.delete('CHEF_WINDOWS_ENV_TEST')
+ @provider.key_exists = false
+ end
+
+ it "should update the ruby ENV object when it creates the key" do
+ @provider.action_create
+ expect(ENV['CHEF_WINDOWS_ENV_TEST']).to eql('foo')
+ end
+ end
+
+ describe "action_modify" do
+ before do
+ ENV['CHEF_WINDOWS_ENV_TEST'] = 'foo'
+ end
+
+ it "should update the ruby ENV object when it updates the value" do
+ @provider.should_receive(:compare_value).and_return(true)
+ @new_resource.value("foobar")
+ @provider.action_modify
+ expect(ENV['CHEF_WINDOWS_ENV_TEST']).to eql('foobar')
+ end
+ end
+
+ describe "action_delete" do
+ before do
+ ENV['CHEF_WINDOWS_ENV_TEST'] = 'foo'
+ end
+
+ it "should update the ruby ENV object when it deletes the key" do
+ @provider.action_delete
+ expect(ENV['CHEF_WINDOWS_ENV_TEST']).to eql(nil)
+ end
+ end
+end