Skip to content

Instantly share code, notes, and snippets.

@btm
Created January 22, 2009 03:30
Show Gist options
  • Save btm/50400 to your computer and use it in GitHub Desktop.
Save btm/50400 to your computer and use it in GitHub Desktop.
1)
NoMethodError in 'Chef::Provider::Route action_add should add the route if it does not exist'
undefined method `gateway' for nil:NilClass
/home/bryanm/chef/chef/spec/../lib/chef/provider/route.rb:58:in `action_add'
./spec/unit/provider/route_spec.rb:57:
def action_add
# check to see if load_current_resource found the route
unless @current_resource.gateway
if @new_resource.route_type == :net
command = "route add -net #{@new_resource.target}"
else
command = "route add #{@new_resource.target}"
end
command << " netmask #{@new_resource.netmask}" if @new_resource.netmask
command << " gw #{@new_resource.gateway}" if @new_resource.gateway
command << " metric #{@new_resource.metric}" if @new_resource.metric
command << " dev #{@new_resource.device}" if @new_resource.device
run_command(
:command => command
)
@new_resource.updated = true
else
Chef::Log.debug("Route #{@current_resource.target} already exists")
end
end
describe Chef::Provider::Route, "action_add" do
before(:each) do
@node = mock("Chef::Node", :null_object => true)
@new_resource = mock("Chef::Resource::Route",
:null_object => true,
:name => "10.0.0.10",
:target => "10.0.0.10",
:gateway => "10.0.0.9"
)
@current_resource = mock("Chef::Resource::Route",
:null_object => true,
:name => "10.0.0.10",
:target => "10.0.0.10",
:gateway => "10.0.0.9"
)
@provider = Chef::Provider::Route.new(@node, @new_resource)
end
it "should add the route if it does not exist" do
@current_resource.stub!(:gateway).and_return("10.0.0.1")
@new_resource.stub!(:gateway).and_return("10.0.0.1")
@new_resource.should_recieve(:updated=).with(true)
@provider.action_add
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment