summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@chef.io>2017-10-03 15:22:34 -0700
committerThom May <thom@chef.io>2017-10-03 15:46:16 -0700
commit8d560b01fd5a3771aff67f3a5463e3e7e7e85b12 (patch)
treebc5a972bd2b606ae15dd80ffd1b124c7983b8f12
parent00e10b3fa2be1f572be207fcb3b1d3bdf135690e (diff)
downloadchef-tm/route_tests.tar.gz
[Route unit tests]: Ensure we go down the new file pathtm/route_tests
This should make us more robust in the face of the enemy Signed-off-by: Thom May <thom@chef.io>
-rw-r--r--lib/chef/provider/route.rb2
-rw-r--r--spec/unit/provider/route_spec.rb2
2 files changed, 3 insertions, 1 deletions
diff --git a/lib/chef/provider/route.rb b/lib/chef/provider/route.rb
index 2439f45eda..be695dd83a 100644
--- a/lib/chef/provider/route.rb
+++ b/lib/chef/provider/route.rb
@@ -186,7 +186,7 @@ class Chef
network_file_name = "/etc/sysconfig/network"
converge_by("write route default route to #{network_file_name}") do
Chef::Log.debug("#{new_resource} writing default route #{new_resource.gateway} to #{network_file_name}")
- if ::File.exists?(network_file_name)
+ if ::File.exist?(network_file_name)
network_file = ::Chef::Util::FileEdit.new(network_file_name)
network_file.search_file_replace_line /^GATEWAY=/, "GATEWAY=#{new_resource.gateway}"
network_file.insert_line_if_no_match /^GATEWAY=/, "GATEWAY=#{new_resource.gateway}"
diff --git a/spec/unit/provider/route_spec.rb b/spec/unit/provider/route_spec.rb
index 5e655bda0c..ea6ddffb81 100644
--- a/spec/unit/provider/route_spec.rb
+++ b/spec/unit/provider/route_spec.rb
@@ -236,9 +236,11 @@ describe Chef::Provider::Route do
@node.automatic_attrs[:platform] = platform
route_file = StringIO.new
+ allow(File).to receive(:exist?).with("/etc/sysconfig/network").and_return(false)
expect(File).to receive(:new).with("/etc/sysconfig/network", "w").and_return(route_file)
@run_context.resource_collection << @default_resource
@default_provider.generate_config
+ expect(route_file.string).to match(/GATEWAY=10\.0\.0\.9/)
end
end