Skip to content

Commit 2491e45

Browse files
committed
add some route unit tests
1 parent ceec2c8 commit 2491e45

2 files changed

Lines changed: 187 additions & 0 deletions

File tree

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#
2+
# Author:: Bryan McLellan (btm@loftninjas.org)
3+
# Copyright:: Copyright (c) 2009 Bryan McLellan
4+
# License:: Apache License, Version 2.0
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper"))
20+
21+
describe Chef::Provider::Route, "initialize" do
22+
before(:each) do
23+
@node = mock("Chef::Node", :null_object => true)
24+
@new_resource = mock("Chef::Resource", :null_object => true)
25+
end
26+
27+
it "should return a Chef::Provider::Route object" do
28+
provider = Chef::Provider::Route.new(@node, @new_resource)
29+
provider.should be_a_kind_of(Chef::Provider::Route)
30+
end
31+
32+
end
33+
34+
describe Chef::Provider::Route, "action_add" do
35+
before(:each) do
36+
@node = mock("Chef::Node", :null_object => true)
37+
@new_resource = mock("Chef::Resource::Route",
38+
:null_object => true,
39+
:name => "10.0.0.10",
40+
:target => "10.0.0.10",
41+
:gateway => "10.0.0.9"
42+
)
43+
@current_resource = mock("Chef::Resource::Route",
44+
:null_object => true,
45+
:name => "10.0.0.10",
46+
:target => "10.0.0.10",
47+
:gateway => "10.0.0.9"
48+
)
49+
50+
@provider = Chef::Provider::Route.new(@node, @new_resource)
51+
@provider.current_resource = @current_resource
52+
end
53+
54+
it "should add the route if it does not exist" do
55+
@provider.stub!(:run_command).and_return(true)
56+
@current_resource.stub!(:gateway).and_return(nil)
57+
@new_resource.should_recieve(:updated=).with(true)
58+
@provider.action_add
59+
end
60+
61+
it "should not add the route if it exists" do
62+
@provider.stub!(:run_command).and_return(true)
63+
@new_resource.should_not_recieve(:updated=).with(true)
64+
@provider.action_add
65+
end
66+
end
67+
68+
describe Chef::Provider::Route, "action_delete" do
69+
before(:each) do
70+
@node = mock("Chef::Node", :null_object => true)
71+
@new_resource = mock("Chef::Resource::Route",
72+
:null_object => true,
73+
:name => "10.0.0.10",
74+
:target => "10.0.0.10",
75+
:gateway => "10.0.0.9"
76+
)
77+
@current_resource = mock("Chef::Resource::Route",
78+
:null_object => true,
79+
:name => "10.0.0.10",
80+
:target => "10.0.0.10",
81+
:gateway => "10.0.0.9"
82+
)
83+
84+
@provider = Chef::Provider::Route.new(@node, @new_resource)
85+
@provider.current_resource = @current_resource
86+
end
87+
88+
it "should delete the route if it exists" do
89+
@provider.stub!(:run_command).and_return(true)
90+
@new_resource.should_recieve(:updated=).with(true)
91+
@provider.action_delete
92+
end
93+
94+
it "should not delete the route if it does not exist" do
95+
@provider.stub!(:run_command).and_return(true)
96+
@new_resource.should_not_recieve(:updated=).with(true)
97+
@provider.action_delete
98+
end
99+
end
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#
2+
# Author:: Bryan McLellan (btm@loftninjas.org)
3+
# Copyright:: Copyright (c) 2008 Bryan McLellan
4+
# License:: Apache License, Version 2.0
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper"))
20+
21+
describe Chef::Resource::Route do
22+
23+
before(:each) do
24+
@resource = Chef::Resource::Route.new("10.0.0.10")
25+
end
26+
27+
it "should create a new Chef::Resource::Route" do
28+
@resource.should be_a_kind_of(Chef::Resource)
29+
@resource.should be_a_kind_of(Chef::Resource::Route)
30+
end
31+
32+
it "should have a name" do
33+
@resource.name.should eql("10.0.0.10")
34+
end
35+
36+
it "should have a default action of 'add'" do
37+
@resource.action.should eql(:add)
38+
end
39+
40+
it "should accept add or delete for action" do
41+
lambda { @resource.action :add }.should_not raise_error(ArgumentError)
42+
lambda { @resource.action :delete }.should_not raise_error(ArgumentError)
43+
lambda { @resource.action :lolcat }.should raise_error(ArgumentError)
44+
end
45+
46+
it "should use the object name as the target by default" do
47+
@resource.target.should eql("10.0.0.10")
48+
end
49+
50+
it "should allow you to specify the netmask" do
51+
@resource.netmask "255.255.255.0"
52+
@resource.netmask.should eql("255.255.255.0")
53+
end
54+
55+
it "should allow you to specify the gateway" do
56+
@resource.gateway "10.0.0.1"
57+
@resource.gateway.should eql("10.0.0.1")
58+
end
59+
60+
it "should allow you to specify the metric" do
61+
@resource.metric 10
62+
@resource.metric.should eql(10)
63+
end
64+
65+
it "should allow you to specify the device" do
66+
@resource.device "eth0"
67+
@resource.device.should eql("eth0")
68+
end
69+
70+
it "should allow you to specify the route type" do
71+
@resource.route_type "host"
72+
@resource.route_type.should eql(:host)
73+
end
74+
75+
it "should default to a host route type" do
76+
@resource.route_type.should eql(:host)
77+
end
78+
79+
it "should accept a net route type" do
80+
@resource.route_type :net
81+
@resource.route_type.should eql(:net)
82+
end
83+
84+
it "should reject any other route_type but :host and :net" do
85+
lambda { @resource.route_type "lolcat" }.should raise_error(ArgumentError)
86+
end
87+
88+
end

0 commit comments

Comments
 (0)