|
| 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 |
0 commit comments