summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorSerdar Sutay <serdar@opscode.com>2014-03-19 15:10:23 -0700
committerSerdar Sutay <serdar@opscode.com>2014-03-19 15:10:23 -0700
commit0ca71108f72bd5ebfae88cffdfe8b38d69f1b841 (patch)
tree74478a7b46ef9af67f0d29486577874bb4e6df1c /spec
parent861f2c7784b666313fafdb1d6b9d1ff1e426de33 (diff)
parent0ad8d6c0c53563dce41799cca6bc69f936bee656 (diff)
downloadchef-0ca71108f72bd5ebfae88cffdfe8b38d69f1b841.tar.gz
Merge pull request #1268 from ccope/solaris11-ips-fix
[CHEF-5037] default to IPS packages on Solaris 5.11+
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/platform_spec.rb365
1 files changed, 191 insertions, 174 deletions
diff --git a/spec/unit/platform_spec.rb b/spec/unit/platform_spec.rb
index 72d0a9184a..3d7aef98a0 100644
--- a/spec/unit/platform_spec.rb
+++ b/spec/unit/platform_spec.rb
@@ -48,209 +48,226 @@ end
describe Chef::Platform do
- before :all do
- @original_platform_map = Chef::Platform.platforms
- end
+ context "while testing with fake data" do
- after :all do ||
- Chef::Platform.platforms = @original_platform_map
- end
+ before :all do
+ @original_platform_map = Chef::Platform.platforms
+ end
- before(:each) do
- Chef::Platform.platforms = {
- :darwin => {
- ">= 10.11" => {
- :file => "new_darwinian"
+ after :all do ||
+ Chef::Platform.platforms = @original_platform_map
+ end
+
+ before(:each) do
+ Chef::Platform.platforms = {
+ :darwin => {
+ ">= 10.11" => {
+ :file => "new_darwinian"
+ },
+ "9.2.2" => {
+ :file => "darwinian",
+ :else => "thing"
+ },
+ :default => {
+ :file => "old school",
+ :snicker => "snack"
+ }
},
- "9.2.2" => {
- :file => "darwinian",
- :else => "thing"
+ :mars_volta => {
},
:default => {
- :file => "old school",
- :snicker => "snack"
+ :file => Chef::Provider::File,
+ :pax => "brittania",
+ :cat => "nice"
}
- },
- :mars_volta => {
- },
- :default => {
- :file => Chef::Provider::File,
- :pax => "brittania",
- :cat => "nice"
}
- }
- @events = Chef::EventDispatch::Dispatcher.new
- end
+ @events = Chef::EventDispatch::Dispatcher.new
+ end
- it "should allow you to look up a platform by name and version, returning the provider map for it" do
- pmap = Chef::Platform.find("Darwin", "9.2.2")
- pmap.should be_a_kind_of(Hash)
- pmap[:file].should eql("darwinian")
- end
+ it "should allow you to look up a platform by name and version, returning the provider map for it" do
+ pmap = Chef::Platform.find("Darwin", "9.2.2")
+ pmap.should be_a_kind_of(Hash)
+ pmap[:file].should eql("darwinian")
+ end
- it "should allow you to look up a platform by name and version using \"greater than\" style operators" do
- pmap = Chef::Platform.find("Darwin", "11.1.0")
- pmap.should be_a_kind_of(Hash)
- pmap[:file].should eql("new_darwinian")
- end
+ it "should allow you to look up a platform by name and version using \"greater than\" style operators" do
+ pmap = Chef::Platform.find("Darwin", "11.1.0")
+ pmap.should be_a_kind_of(Hash)
+ pmap[:file].should eql("new_darwinian")
+ end
- it "should use the default providers for an os if the specific version does not exist" do
- pmap = Chef::Platform.find("Darwin", "1")
- pmap.should be_a_kind_of(Hash)
- pmap[:file].should eql("old school")
- end
+ it "should use the default providers for an os if the specific version does not exist" do
+ pmap = Chef::Platform.find("Darwin", "1")
+ pmap.should be_a_kind_of(Hash)
+ pmap[:file].should eql("old school")
+ end
- it "should use the default providers if the os doesn't give me a default, but does exist" do
- pmap = Chef::Platform.find("mars_volta", "1")
- pmap.should be_a_kind_of(Hash)
- pmap[:file].should eql(Chef::Provider::File)
- end
+ it "should use the default providers if the os doesn't give me a default, but does exist" do
+ pmap = Chef::Platform.find("mars_volta", "1")
+ pmap.should be_a_kind_of(Hash)
+ pmap[:file].should eql(Chef::Provider::File)
+ end
- it "should use the default provider if the os does not exist" do
- pmap = Chef::Platform.find("AIX", "1")
- pmap.should be_a_kind_of(Hash)
- pmap[:file].should eql(Chef::Provider::File)
- end
+ it "should use the default provider if the os does not exist" do
+ pmap = Chef::Platform.find("AIX", "1")
+ pmap.should be_a_kind_of(Hash)
+ pmap[:file].should eql(Chef::Provider::File)
+ end
- it "should merge the defaults for an os with the specific version" do
- pmap = Chef::Platform.find("Darwin", "9.2.2")
- pmap[:file].should eql("darwinian")
- pmap[:snicker].should eql("snack")
- end
+ it "should merge the defaults for an os with the specific version" do
+ pmap = Chef::Platform.find("Darwin", "9.2.2")
+ pmap[:file].should eql("darwinian")
+ pmap[:snicker].should eql("snack")
+ end
- it "should merge the defaults for an os with the universal defaults" do
- pmap = Chef::Platform.find("Darwin", "9.2.2")
- pmap[:file].should eql("darwinian")
- pmap[:pax].should eql("brittania")
- end
+ it "should merge the defaults for an os with the universal defaults" do
+ pmap = Chef::Platform.find("Darwin", "9.2.2")
+ pmap[:file].should eql("darwinian")
+ pmap[:pax].should eql("brittania")
+ end
- it "should allow you to look up a provider for a platform directly by symbol" do
- Chef::Platform.find_provider("Darwin", "9.2.2", :file).should eql("darwinian")
- end
+ it "should allow you to look up a provider for a platform directly by symbol" do
+ Chef::Platform.find_provider("Darwin", "9.2.2", :file).should eql("darwinian")
+ end
- it "should raise an exception if a provider cannot be found for a resource type" do
- lambda { Chef::Platform.find_provider("Darwin", "9.2.2", :coffee) }.should raise_error(ArgumentError)
- end
+ it "should raise an exception if a provider cannot be found for a resource type" do
+ lambda { Chef::Platform.find_provider("Darwin", "9.2.2", :coffee) }.should raise_error(ArgumentError)
+ end
- it "should look up a provider for a resource with a Chef::Resource object" do
- kitty = Chef::Resource::Cat.new("loulou")
- Chef::Platform.find_provider("Darwin", "9.2.2", kitty).should eql("nice")
- end
+ it "should look up a provider for a resource with a Chef::Resource object" do
+ kitty = Chef::Resource::Cat.new("loulou")
+ Chef::Platform.find_provider("Darwin", "9.2.2", kitty).should eql("nice")
+ end
- it "should look up a provider with a node and a Chef::Resource object" do
- kitty = Chef::Resource::Cat.new("loulou")
- node = Chef::Node.new
- node.name("Intel")
- node.automatic_attrs[:platform] = "mac_os_x"
- node.automatic_attrs[:platform_version] = "9.2.2"
- Chef::Platform.find_provider_for_node(node, kitty).should eql("nice")
- end
+ it "should look up a provider with a node and a Chef::Resource object" do
+ kitty = Chef::Resource::Cat.new("loulou")
+ node = Chef::Node.new
+ node.name("Intel")
+ node.automatic_attrs[:platform] = "mac_os_x"
+ node.automatic_attrs[:platform_version] = "9.2.2"
+ Chef::Platform.find_provider_for_node(node, kitty).should eql("nice")
+ end
- it "should not throw an exception when the platform version has an unknown format" do
- Chef::Platform.find_provider(:darwin, "bad-version", :file).should eql("old school")
- end
+ it "should not throw an exception when the platform version has an unknown format" do
+ Chef::Platform.find_provider(:darwin, "bad-version", :file).should eql("old school")
+ end
- it "should prefer an explicit provider" do
- kitty = Chef::Resource::Cat.new("loulou")
- kitty.stub(:provider).and_return(Chef::Provider::File)
- node = Chef::Node.new
- node.name("Intel")
- node.automatic_attrs[:platform] = "mac_os_x"
- node.automatic_attrs[:platform_version] = "9.2.2"
- Chef::Platform.find_provider_for_node(node, kitty).should eql(Chef::Provider::File)
- end
+ it "should prefer an explicit provider" do
+ kitty = Chef::Resource::Cat.new("loulou")
+ kitty.stub(:provider).and_return(Chef::Provider::File)
+ node = Chef::Node.new
+ node.name("Intel")
+ node.automatic_attrs[:platform] = "mac_os_x"
+ node.automatic_attrs[:platform_version] = "9.2.2"
+ Chef::Platform.find_provider_for_node(node, kitty).should eql(Chef::Provider::File)
+ end
- it "should look up a provider based on the resource name if nothing else matches" do
- kitty = Chef::Resource::Cat.new("loulou")
- class Chef::Provider::Cat < Chef::Provider; end
- Chef::Platform.platforms[:default].delete(:cat)
- node = Chef::Node.new
- node.name("Intel")
- node.automatic_attrs[:platform] = "mac_os_x"
- node.automatic_attrs[:platform_version] = "8.5"
- Chef::Platform.find_provider_for_node(node, kitty).should eql(Chef::Provider::Cat)
- end
+ it "should look up a provider based on the resource name if nothing else matches" do
+ kitty = Chef::Resource::Cat.new("loulou")
+ class Chef::Provider::Cat < Chef::Provider; end
+ Chef::Platform.platforms[:default].delete(:cat)
+ node = Chef::Node.new
+ node.name("Intel")
+ node.automatic_attrs[:platform] = "mac_os_x"
+ node.automatic_attrs[:platform_version] = "8.5"
+ Chef::Platform.find_provider_for_node(node, kitty).should eql(Chef::Provider::Cat)
+ end
- def setup_file_resource
- node = Chef::Node.new
- node.automatic_attrs[:platform] = "mac_os_x"
- node.automatic_attrs[:platform_version] = "9.2.2"
- run_context = Chef::RunContext.new(node, {}, @events)
- [ Chef::Resource::File.new("whateva", run_context), run_context ]
- end
+ def setup_file_resource
+ node = Chef::Node.new
+ node.automatic_attrs[:platform] = "mac_os_x"
+ node.automatic_attrs[:platform_version] = "9.2.2"
+ run_context = Chef::RunContext.new(node, {}, @events)
+ [ Chef::Resource::File.new("whateva", run_context), run_context ]
+ end
- it "returns a provider object given a Chef::Resource object which has a valid run context and an action" do
- file, run_context = setup_file_resource
- provider = Chef::Platform.provider_for_resource(file, :foo)
- provider.should be_an_instance_of(Chef::Provider::File)
- provider.new_resource.should equal(file)
- provider.run_context.should equal(run_context)
- end
+ it "returns a provider object given a Chef::Resource object which has a valid run context and an action" do
+ file, run_context = setup_file_resource
+ provider = Chef::Platform.provider_for_resource(file, :foo)
+ provider.should be_an_instance_of(Chef::Provider::File)
+ provider.new_resource.should equal(file)
+ provider.run_context.should equal(run_context)
+ end
- it "returns a provider object given a Chef::Resource object which has a valid run context without an action" do
- file, run_context = setup_file_resource
- provider = Chef::Platform.provider_for_resource(file)
- provider.should be_an_instance_of(Chef::Provider::File)
- provider.new_resource.should equal(file)
- provider.run_context.should equal(run_context)
- end
+ it "returns a provider object given a Chef::Resource object which has a valid run context without an action" do
+ file, run_context = setup_file_resource
+ provider = Chef::Platform.provider_for_resource(file)
+ provider.should be_an_instance_of(Chef::Provider::File)
+ provider.new_resource.should equal(file)
+ provider.run_context.should equal(run_context)
+ end
- it "raises an error when trying to find the provider for a resource with no run context" do
- file = Chef::Resource::File.new("whateva")
- lambda {Chef::Platform.provider_for_resource(file)}.should raise_error(ArgumentError)
- end
+ it "raises an error when trying to find the provider for a resource with no run context" do
+ file = Chef::Resource::File.new("whateva")
+ lambda {Chef::Platform.provider_for_resource(file)}.should raise_error(ArgumentError)
+ end
- it "does not support finding a provider by resource and node -- a run context is required" do
- lambda {Chef::Platform.provider_for_node('node', 'resource')}.should raise_error(NotImplementedError)
- end
+ it "does not support finding a provider by resource and node -- a run context is required" do
+ lambda {Chef::Platform.provider_for_node('node', 'resource')}.should raise_error(NotImplementedError)
+ end
+
+ it "should update the provider map with map" do
+ Chef::Platform.set(
+ :platform => :darwin,
+ :version => "9.2.2",
+ :resource => :file,
+ :provider => "masterful"
+ )
+ Chef::Platform.platforms[:darwin]["9.2.2"][:file].should eql("masterful")
+ Chef::Platform.set(
+ :platform => :darwin,
+ :resource => :file,
+ :provider => "masterful"
+ )
+ Chef::Platform.platforms[:darwin][:default][:file].should eql("masterful")
+ Chef::Platform.set(
+ :resource => :file,
+ :provider => "masterful"
+ )
+ Chef::Platform.platforms[:default][:file].should eql("masterful")
+
+ Chef::Platform.set(
+ :platform => :hero,
+ :version => "9.2.2",
+ :resource => :file,
+ :provider => "masterful"
+ )
+ Chef::Platform.platforms[:hero]["9.2.2"][:file].should eql("masterful")
+
+ Chef::Platform.set(
+ :resource => :file,
+ :provider => "masterful"
+ )
+ Chef::Platform.platforms[:default][:file].should eql("masterful")
+
+ Chef::Platform.platforms = {}
+
+ Chef::Platform.set(
+ :resource => :file,
+ :provider => "masterful"
+ )
+ Chef::Platform.platforms[:default][:file].should eql("masterful")
+
+ Chef::Platform.platforms = { :neurosis => {} }
+ Chef::Platform.set(:platform => :neurosis, :resource => :package, :provider => "masterful")
+ Chef::Platform.platforms[:neurosis][:default][:package].should eql("masterful")
- it "should update the provider map with map" do
- Chef::Platform.set(
- :platform => :darwin,
- :version => "9.2.2",
- :resource => :file,
- :provider => "masterful"
- )
- Chef::Platform.platforms[:darwin]["9.2.2"][:file].should eql("masterful")
- Chef::Platform.set(
- :platform => :darwin,
- :resource => :file,
- :provider => "masterful"
- )
- Chef::Platform.platforms[:darwin][:default][:file].should eql("masterful")
- Chef::Platform.set(
- :resource => :file,
- :provider => "masterful"
- )
- Chef::Platform.platforms[:default][:file].should eql("masterful")
-
- Chef::Platform.set(
- :platform => :hero,
- :version => "9.2.2",
- :resource => :file,
- :provider => "masterful"
- )
- Chef::Platform.platforms[:hero]["9.2.2"][:file].should eql("masterful")
-
- Chef::Platform.set(
- :resource => :file,
- :provider => "masterful"
- )
- Chef::Platform.platforms[:default][:file].should eql("masterful")
-
- Chef::Platform.platforms = {}
-
- Chef::Platform.set(
- :resource => :file,
- :provider => "masterful"
- )
- Chef::Platform.platforms[:default][:file].should eql("masterful")
-
- Chef::Platform.platforms = { :neurosis => {} }
- Chef::Platform.set(:platform => :neurosis, :resource => :package, :provider => "masterful")
- Chef::Platform.platforms[:neurosis][:default][:package].should eql("masterful")
+ end
end
+ context "while testing the configured platform data" do
+
+ it "should use the solaris package provider on Solaris <11" do
+ pmap = Chef::Platform.find("Solaris2", "5.9")
+ pmap[:package].should eql(Chef::Provider::Package::Solaris)
+ end
+
+ it "should use the IPS package provider on Solaris 11" do
+ pmap = Chef::Platform.find("Solaris2", "5.11")
+ pmap[:package].should eql(Chef::Provider::Package::Ips)
+ end
+
+ end
end