spec/unit/provider/route_spec.rb in chef-11.4.4 vs spec/unit/provider/route_spec.rb in chef-11.6.0.hotfix.1

- old
+ new

@@ -106,10 +106,25 @@ @provider.should_not_receive(:generate_command).with(:add) @provider.should_receive(:generate_config) @provider.run_action(:add) @new_resource.should_not be_updated end + + it "should not delete config file for :add action (CHEF-3332)" do + @node.automatic_attrs[:platform] = 'centos' + + route_file = StringIO.new + File.should_receive(:new).and_return(route_file) + @resource_add = Chef::Resource::Route.new('192.168.1.0/24 via 192.168.0.1') + @run_context.resource_collection << @resource_add + @provider.stub!(:run_command).and_return(true) + + @resource_add.action(:add) + @provider.run_action(:add) + route_file.string.split("\n").should have(1).items + route_file.string.should match(/^192\.168\.1\.0\/24 via 192\.168\.0\.1$/) + end end describe Chef::Provider::Route, "action_delete" do it "should delete the route if it exists" do @provider.stub!(:run_command).and_return(true) @@ -138,16 +153,16 @@ @new_resource.stub!(:netmask).and_return(nil) @provider.generate_command(:add).should_not match(/\/\d{1,2}\s/) end it "should include ' via $gateway ' when a gateway is specified" do - @provider.generate_command(:add).should match(/\svia\s#{@new_resource.gateway}\s/) + @provider.generate_command(:add).should match(/\svia\s#{Regexp.escape(@new_resource.gateway.to_s)}\s/) end it "should not include ' via $gateway ' when a gateway is not specified" do @new_resource.stub!(:gateway).and_return(nil) - @provider.generate_command(:add).should_not match(/\svia\s#{@new_resource.gateway}\s/) + @provider.generate_command(:add).should_not match(/\svia\s#{Regexp.escape(@new_resource.gateway.to_s)}\s/) end end describe Chef::Provider::Route, "generate_command for action_delete" do it "should include a netmask when a one is specified" do @@ -159,16 +174,16 @@ @new_resource.stub!(:netmask).and_return(nil) @provider.generate_command(:delete).should_not match(/\/\d{1,2}\s/) end it "should include ' via $gateway ' when a gateway is specified" do - @provider.generate_command(:delete).should match(/\svia\s#{@new_resource.gateway}\s/) + @provider.generate_command(:delete).should match(/\svia\s#{Regexp.escape(@new_resource.gateway.to_s)}\s/) end it "should not include ' via $gateway ' when a gateway is not specified" do @new_resource.stub!(:gateway).and_return(nil) - @provider.generate_command(:delete).should_not match(/\svia\s#{@new_resource.gateway}\s/) + @provider.generate_command(:delete).should_not match(/\svia\s#{Regexp.escape(@new_resource.gateway.to_s)}\s/) end end describe Chef::Provider::Route, "config_file_contents for action_add" do it "should include a netmask when a one is specified" do @@ -179,15 +194,15 @@ it "should not include a netmask when a one is specified" do @provider.config_file_contents(:add, { :target => @new_resource.target}).should_not match(/\/\d{1,2}.*\n$/) end it "should include ' via $gateway ' when a gateway is specified" do - @provider.config_file_contents(:add, { :target => @new_resource.target, :gateway => @new_resource.gateway}).should match(/\svia\s#{@new_resource.gateway}\n/) + @provider.config_file_contents(:add, { :target => @new_resource.target, :gateway => @new_resource.gateway}).should match(/\svia\s#{Regexp.escape(@new_resource.gateway.to_s)}\n/) end it "should not include ' via $gateway ' when a gateway is not specified" do - @provider.generate_command(:add).should_not match(/\svia\s#{@new_resource.gateway}\n/) + @provider.generate_command(:add).should_not match(/\svia\s#{Regexp.escape(@new_resource.gateway.to_s)}\n/) end end describe Chef::Provider::Route, "config_file_contents for action_delete" do it "should return an empty string" do @@ -215,13 +230,14 @@ File.should_receive(:new).and_return(route_file) @run_context.resource_collection << Chef::Resource::Route.new('192.168.1.0/24 via 192.168.0.1') @run_context.resource_collection << Chef::Resource::Route.new('192.168.2.0/24 via 192.168.0.1') @run_context.resource_collection << Chef::Resource::Route.new('192.168.3.0/24 via 192.168.0.1') + @provider.action = :add @provider.generate_config route_file.string.split("\n").should have(3).items - route_file.string.should match(/^192.168.1.0\/24 via 192.168.0.1$/) - route_file.string.should match(/^192.168.2.0\/24 via 192.168.0.1$/) - route_file.string.should match(/^192.168.3.0\/24 via 192.168.0.1$/) + route_file.string.should match(/^192\.168\.1\.0\/24 via 192\.168\.0\.1$/) + route_file.string.should match(/^192\.168\.2\.0\/24 via 192\.168\.0\.1$/) + route_file.string.should match(/^192\.168\.3\.0\/24 via 192\.168\.0\.1$/) end end end