summaryrefslogtreecommitdiff
path: root/spec/unit/resource/ifconfig_spec.rb
diff options
context:
space:
mode:
authorXabier de Zuazo <xabier@onddo.com>2013-02-10 20:50:12 +0100
committerBryan McLellan <btm@opscode.com>2013-06-19 14:09:57 -0700
commit87362261bfb47fc1628a531f83e1dd77484dd1bb (patch)
tree26a90cf3ba35924bfa7a499b68c524fa7e8f4579 /spec/unit/resource/ifconfig_spec.rb
parent1504a1d133f5a8c71431027bc9012fdb8507fde5 (diff)
downloadchef-87362261bfb47fc1628a531f83e1dd77484dd1bb.tar.gz
[CHEF-3029] Tests added to Provider::Ifconfig for testing redhat, ubuntu and debian providers selection
Diffstat (limited to 'spec/unit/resource/ifconfig_spec.rb')
-rw-r--r--spec/unit/resource/ifconfig_spec.rb61
1 files changed, 60 insertions, 1 deletions
diff --git a/spec/unit/resource/ifconfig_spec.rb b/spec/unit/resource/ifconfig_spec.rb
index 2aac130978..58869d5107 100644
--- a/spec/unit/resource/ifconfig_spec.rb
+++ b/spec/unit/resource/ifconfig_spec.rb
@@ -21,7 +21,10 @@ require 'spec_helper'
describe Chef::Resource::Ifconfig do
before(:each) do
- @resource = Chef::Resource::Ifconfig.new("fakey_fakerton")
+ @node = Chef::Node.new
+ @events = Chef::EventDispatch::Dispatcher.new
+ @run_context = Chef::RunContext.new(@node, {}, @events)
+ @resource = Chef::Resource::Ifconfig.new("fakey_fakerton", @run_context)
end
describe "when it has target, hardware address, inet address, and a mask" do
@@ -43,4 +46,60 @@ describe Chef::Resource::Ifconfig do
@resource.identity.should == "charmander"
end
end
+
+ shared_examples "being a platform using the default ifconfig provider" do |platform, version|
+ before do
+ @node.automatic_attrs[:platform] = platform
+ @node.automatic_attrs[:platform_version] = version
+ end
+
+ it "should use an ordinary Provider::Ifconfig as a provider for #{platform} #{version}" do
+ @resource.provider_for_action(:add).should be_a_kind_of(Chef::Provider::Ifconfig)
+ @resource.provider_for_action(:add).should_not be_a_kind_of(Chef::Provider::Ifconfig::Debian)
+ @resource.provider_for_action(:add).should_not be_a_kind_of(Chef::Provider::Ifconfig::Redhat)
+ end
+ end
+
+ shared_examples "being a platform based on RedHat" do |platform, version|
+ before do
+ @node.automatic_attrs[:platform] = platform
+ @node.automatic_attrs[:platform_version] = version
+ end
+
+ it "should use an Provider::Ifconfig::Redhat as a provider for #{platform} #{version}" do
+ @resource.provider_for_action(:add).should be_a_kind_of(Chef::Provider::Ifconfig::Redhat)
+ end
+ end
+
+ shared_examples "being a platform based on a recent Debian" do |platform, version|
+ before do
+ @node.automatic_attrs[:platform] = platform
+ @node.automatic_attrs[:platform_version] = version
+ end
+
+ it "should use an Ifconfig::Debian as a provider for #{platform} #{version}" do
+ @resource.provider_for_action(:add).should be_a_kind_of(Chef::Provider::Ifconfig::Debian)
+ end
+ end
+
+ describe "when it is a RedHat platform" do
+ it_should_behave_like "being a platform based on RedHat", "redhat", "4.0"
+ end
+
+ describe "when it is an old Debian platform" do
+ it_should_behave_like "being a platform using the default ifconfig provider", "debian", "6.0"
+ end
+
+ describe "when it is a new Debian platform" do
+ it_should_behave_like "being a platform based on a recent Debian", "debian", "7.0"
+ end
+
+ describe "when it is an old Ubuntu platform" do
+ it_should_behave_like "being a platform using the default ifconfig provider", "ubuntu", "11.04"
+ end
+
+ describe "when it is a new Ubuntu platform" do
+ it_should_behave_like "being a platform based on a recent Debian", "ubuntu", "11.10"
+ end
+
end