summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2014-02-11 16:57:20 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2014-02-11 16:57:20 -0800
commit83f8079d54bfcdda3b2f1c0b0249ddd9983b693f (patch)
tree857d9e14d8fcc052087c995aefea218bff2c19e4
parent452453f2844ea5ed5217f0c8d90b92cf61e400d0 (diff)
downloadchef-83f8079d54bfcdda3b2f1c0b0249ddd9983b693f.tar.gz
CHEF-3838: fix unit test in debian_spec for FileEdit change
- also rearrangement to use let instead of instance vars
-rw-r--r--spec/unit/provider/ifconfig/debian_spec.rb118
1 files changed, 65 insertions, 53 deletions
diff --git a/spec/unit/provider/ifconfig/debian_spec.rb b/spec/unit/provider/ifconfig/debian_spec.rb
index 3f46d9df23..a6b125c785 100644
--- a/spec/unit/provider/ifconfig/debian_spec.rb
+++ b/spec/unit/provider/ifconfig/debian_spec.rb
@@ -20,70 +20,82 @@ require 'spec_helper'
require 'chef/exceptions'
describe Chef::Provider::Ifconfig::Debian do
- before do
- @node = Chef::Node.new
- @cookbook_collection = Chef::CookbookCollection.new([])
- @events = Chef::EventDispatch::Dispatcher.new
- @run_context = Chef::RunContext.new(@node, @cookbook_collection, @events)
- #This new_resource can be called anything --> it is not the same as in ifconfig.rb
- @new_resource = Chef::Resource::Ifconfig.new("10.0.0.1", @run_context)
- @new_resource.mask "255.255.254.0"
- @new_resource.metric "1"
- @new_resource.mtu "1500"
- @new_resource.device "eth0"
- @provider = Chef::Provider::Ifconfig::Debian.new(@new_resource, @run_context)
- @current_resource = Chef::Resource::Ifconfig.new("10.0.0.1", @run_context)
- status = double("Status", :exitstatus => 0)
- @provider.instance_variable_set("@status", status)
- @provider.current_resource = @current_resource
- @provider.stub(:load_current_resource)
- @provider.stub(:run_command)
+ let(:run_context) do
+ node = Chef::Node.new
+ cookbook_collection = Chef::CookbookCollection.new([])
+ events = Chef::EventDispatch::Dispatcher.new
+ Chef::RunContext.new(node, cookbook_collection, events)
+ end
- @config_filename_ifaces = "/etc/network/interfaces"
- @config_filename_ifcfg = "/etc/network/interfaces.d/ifcfg-#{@new_resource.device}"
+ let(:new_resource) do
+ new_resource = Chef::Resource::Ifconfig.new("10.0.0.1", run_context)
+ new_resource.mask "255.255.254.0"
+ new_resource.metric "1"
+ new_resource.mtu "1500"
+ new_resource.device "eth0"
+ new_resource
end
+ let(:current_resource) { Chef::Resource::Ifconfig.new("10.0.0.1", run_context) }
+
+ let(:provider) do
+ status = double("Status", :exitstatus => 0)
+ provider = Chef::Provider::Ifconfig::Debian.new(new_resource, run_context)
+ provider.instance_variable_set("@status", status)
+ provider.current_resource = current_resource
+ provider.stub(:load_current_resource)
+ provider.stub(:run_command)
+ provider
+ end
+
+ let(:config_filename_ifaces) { "/etc/network/interfaces" }
+
+ let(:config_filename_ifcfg) { "/etc/network/interfaces.d/ifcfg-#{new_resource.device}" }
+
describe "generate_config for action_add" do
- before do
- @config_file_ifaces = StringIO.new
- @config_file_ifcfg = StringIO.new
- FileUtils.should_receive(:cp)
- File.should_receive(:new).with(@config_filename_ifaces).and_return(StringIO.new)
- File.should_receive(:open).with(@config_filename_ifaces, "w").and_yield(@config_file_ifaces)
- File.should_receive(:new).with(@config_filename_ifcfg, "w").and_return(@config_file_ifcfg)
- File.should_receive(:exist?).with(@config_filename_ifaces).and_return(true)
- end
-
- it "should create network-scripts directory" do
- File.should_receive(:directory?).with(File.dirname(@config_filename_ifcfg)).and_return(false)
- Dir.should_receive(:mkdir).with(File.dirname(@config_filename_ifcfg))
- @provider.run_action(:add)
- end
-
- it "should write configure network-scripts directory" do
- File.should_receive(:directory?).with(File.dirname(@config_filename_ifcfg)).and_return(true)
- @provider.run_action(:add)
- @config_file_ifaces.string.should match(/^\s*source\s+\/etc\/network\/interfaces[.]d\/[*]\s*$/)
- end
-
- it "should write a network-script" do
- File.should_receive(:directory?).with(File.dirname(@config_filename_ifcfg)).and_return(true)
- @provider.run_action(:add)
- @config_file_ifcfg.string.should match(/^iface eth0 inet static\s*$/)
- @config_file_ifcfg.string.should match(/^\s+address 10\.0\.0\.1\s*$/)
- @config_file_ifcfg.string.should match(/^\s+netmask 255\.255\.254\.0\s*$/)
- end
+
+ let(:config_file_ifaces) { StringIO.new }
+
+ let(:config_file_ifcfg) { StringIO.new }
+
+ before do
+ FileUtils.should_receive(:cp)
+ File.should_receive(:open).with(config_filename_ifaces).and_return(StringIO.new)
+ File.should_receive(:open).with(config_filename_ifaces, "w").and_yield(config_file_ifaces)
+ File.should_receive(:new).with(config_filename_ifcfg, "w").and_return(config_file_ifcfg)
+ File.should_receive(:exist?).with(config_filename_ifaces).and_return(true)
+ end
+
+ it "should create network-scripts directory" do
+ File.should_receive(:directory?).with(File.dirname(config_filename_ifcfg)).and_return(false)
+ Dir.should_receive(:mkdir).with(File.dirname(config_filename_ifcfg))
+ provider.run_action(:add)
+ end
+
+ it "should write configure network-scripts directory" do
+ File.should_receive(:directory?).with(File.dirname(config_filename_ifcfg)).and_return(true)
+ provider.run_action(:add)
+ config_file_ifaces.string.should match(/^\s*source\s+\/etc\/network\/interfaces[.]d\/[*]\s*$/)
+ end
+
+ it "should write a network-script" do
+ File.should_receive(:directory?).with(File.dirname(config_filename_ifcfg)).and_return(true)
+ provider.run_action(:add)
+ config_file_ifcfg.string.should match(/^iface eth0 inet static\s*$/)
+ config_file_ifcfg.string.should match(/^\s+address 10\.0\.0\.1\s*$/)
+ config_file_ifcfg.string.should match(/^\s+netmask 255\.255\.254\.0\s*$/)
+ end
end
describe "delete_config for action_delete" do
it "should delete network-script if it exists" do
- @current_resource.device @new_resource.device
- File.should_receive(:exist?).with(@config_filename_ifcfg).and_return(true)
- FileUtils.should_receive(:rm_f).with(@config_filename_ifcfg, :verbose => false)
+ current_resource.device new_resource.device
+ File.should_receive(:exist?).with(config_filename_ifcfg).and_return(true)
+ FileUtils.should_receive(:rm_f).with(config_filename_ifcfg, :verbose => false)
- @provider.run_action(:delete)
+ provider.run_action(:delete)
end
end
end