spec/appliance-spec.rb in boxgrinder-build-0.6.5 vs spec/appliance-spec.rb in boxgrinder-build-0.7.0

- old
+ new

@@ -21,22 +21,22 @@ require 'ostruct' require 'logger' module BoxGrinder describe Appliance do - def prepare_appliance(options = OpenStruct.new) - options.name = 'boxgrinder' + def prepare_appliance(options = OpenStruct.new, definition_file = "#{File.dirname(__FILE__)}/rspec/src/appliances/jeos-f13.appl") + options.name = 'boxgrinder' options.version = '1.0' - @options = options - @log = Logger.new('/dev/null') + @options = options + @log = Logger.new('/dev/null') @plugin_manager = mock(PluginManager) PluginManager.stub!(:instance).and_return(@plugin_manager) - @appliance = Appliance.new("#{File.dirname(__FILE__)}/rspec/src/appliances/jeos-f13.appl", :log => @log, :options => @options) + @appliance = Appliance.new(definition_file, :log => @log, :options => @options) end def prepare_appliance_config @appliance_config = mock('ApplianceConfig') @@ -49,17 +49,17 @@ @appliance_config.stub!(:hardware).and_return( OpenCascade.new({ :partitions => { - '/' => {'size' => 2}, + '/' => {'size' => 2}, '/home' => {'size' => 3}, }, - :arch => 'i686', - :base_arch => 'i386', - :cpus => 1, - :memory => 256, + :arch => 'i686', + :base_arch => 'i386', + :cpus => 1, + :memory => 256, }) ) @appliance_config end @@ -98,31 +98,88 @@ @appliance.should_receive(:execute_plugin_chain) @appliance.create end - it "should read definition" do - prepare_appliance + describe ".validate_definition" do + it "should read definition with standard appliance definition file" do + prepare_appliance - appliance_config = ApplianceConfig.new + appliance_config = ApplianceConfig.new - appliance_helper = mock(ApplianceHelper) - appliance_helper.should_receive(:read_definitions).with("#{File.dirname(__FILE__)}/rspec/src/appliances/jeos-f13.appl").and_return([{}, appliance_config]) + appliance_helper = mock(ApplianceHelper) + appliance_helper.should_receive(:read_definitions).with("#{File.dirname(__FILE__)}/rspec/src/appliances/jeos-f13.appl").and_return([{}, appliance_config]) - ApplianceHelper.should_receive(:new).with(:log => @log).and_return(appliance_helper) + ApplianceHelper.should_receive(:new).with(:log => @log).and_return(appliance_helper) - appliance_config_helper = mock(ApplianceConfigHelper) + appliance_config_helper = mock(ApplianceConfigHelper) - appliance_config.should_receive(:clone).and_return(appliance_config) - appliance_config.should_receive(:init_arch).and_return(appliance_config) - appliance_config.should_receive(:initialize_paths).and_return(appliance_config) + appliance_config.should_receive(:clone).and_return(appliance_config) + appliance_config.should_receive(:init_arch).and_return(appliance_config) + appliance_config.should_receive(:initialize_paths).and_return(appliance_config) - appliance_config_helper.should_receive(:merge).with(appliance_config).and_return(appliance_config) + appliance_config_helper.should_receive(:merge).with(appliance_config).and_return(appliance_config) - ApplianceConfigHelper.should_receive(:new).with({}).and_return(appliance_config_helper) + ApplianceConfigHelper.should_receive(:new).with({}).and_return(appliance_config_helper) - @appliance.read_definition + @appliance.read_definition + end + + it "should read definition with kickstart appliance definition file" do + prepare_appliance(OpenStruct.new, "#{File.dirname(__FILE__)}/rspec/src/appliances/jeos-f13.ks") + + appliance_config = ApplianceConfig.new + + appliance_helper = mock(ApplianceHelper) + appliance_helper.should_receive(:read_definitions).with("#{File.dirname(__FILE__)}/rspec/src/appliances/jeos-f13.ks").and_raise("Unknown format") + + clazz = mock('PluginClass') + + plugin_manager = mock(PluginManager) + plugin_manager.should_receive(:plugins).and_return({:os => {:fedora => {:class => clazz, :type => :os, :name => :fedora, :full_name => "Fedora", :versions => ["11", "12", "13", "14", "rawhide"]}}}) + + plugin = mock('Plugin') + plugin.should_receive(:respond_to?).with(:read_file).and_return(true) + plugin.should_receive(:read_file).and_return(appliance_config) + + clazz.should_receive(:new).and_return(plugin) + + PluginManager.should_receive(:instance).and_return(plugin_manager) + + ApplianceHelper.should_receive(:new).with(:log => @log).and_return(appliance_helper) + + appliance_config_helper = mock(ApplianceConfigHelper) + + appliance_config.should_receive(:clone).and_return(appliance_config) + appliance_config.should_receive(:init_arch).and_return(appliance_config) + appliance_config.should_receive(:initialize_paths).and_return(appliance_config) + + appliance_config_helper.should_receive(:merge).with(appliance_config).and_return(appliance_config) + + ApplianceConfigHelper.should_receive(:new).with([appliance_config]).and_return(appliance_config_helper) + + @appliance.read_definition + end + + it "should read definition with kickstart appliance definition file and fail because there was no plugin able to read .ks" do + prepare_appliance(OpenStruct.new, "#{File.dirname(__FILE__)}/rspec/src/appliances/jeos-f13.ks") + + appliance_helper = mock(ApplianceHelper) + appliance_helper.should_receive(:read_definitions).with("#{File.dirname(__FILE__)}/rspec/src/appliances/jeos-f13.ks").and_raise("Unknown format") + + plugin_manager = mock(PluginManager) + plugin_manager.should_receive(:plugins).and_return({:os => {}}) + + + PluginManager.should_receive(:instance).and_return(plugin_manager) + + ApplianceHelper.should_receive(:new).with(:log => @log).and_return(appliance_helper) + + lambda { + @appliance.read_definition + }.should raise_error("Couldn't read appliance definition file: jeos-f13.ks") + end end describe ".validate_definition" do it "should validate definition and pass" do prepare_appliance @@ -131,12 +188,10 @@ appliance_config_validator = mock(ApplianceConfigValidator) appliance_config_validator.should_receive(:validate) ApplianceConfigValidator.should_receive(:new).with(@appliance_config).and_return(appliance_config_validator) - puts @appliance_config - plugin_manager = mock(PluginManager) plugin_manager.stub!(:plugins).and_return({:os => {:fedora => {:type => :os, :name => :fedora, :full_name => "Fedora", :versions => ["11", "12", "13", "14", "rawhide"]}}}) PluginManager.stub!(:instance).and_return(plugin_manager) @@ -155,16 +210,13 @@ plugin_manager = mock(PluginManager) plugin_manager.stub!(:plugins).and_return({:os => {}}) PluginManager.stub!(:instance).and_return(plugin_manager) - begin + lambda { @appliance.validate_definition - raise "Shouldn't raise" - rescue => e - e.message.should == "No operating system plugins installed. Install one or more operating system plugin. See http://community.jboss.org/docs/DOC-15081 and http://community.jboss.org/docs/DOC-15214 for more info" - end + }.should raise_error(SystemExit, "No operating system plugins installed. Install one or more operating system plugin. See http://community.jboss.org/docs/DOC-15081 and http://community.jboss.org/docs/DOC-15214 for more info") end it "should validate definition and fail because no supported operating system plugins is installed" do prepare_appliance @appliance.instance_variable_set(:@appliance_config, prepare_appliance_config) @@ -172,23 +224,18 @@ appliance_config_validator = mock(ApplianceConfigValidator) appliance_config_validator.should_receive(:validate) ApplianceConfigValidator.should_receive(:new).with(@appliance_config).and_return(appliance_config_validator) - puts @appliance_config - plugin_manager = mock(PluginManager) plugin_manager.stub!(:plugins).and_return({:os => {:rhel => {}}}) PluginManager.stub!(:instance).and_return(plugin_manager) - begin + lambda { @appliance.validate_definition - raise "Shouldn't raise" - rescue => e - e.message.should == "Not supported operating system selected: fedora. Make sure you have installed right operating system plugin, see http://community.jboss.org/docs/DOC-15214. Supported OSes are: rhel" - end + }.should raise_error(SystemExit, "Not supported operating system selected: fedora. Make sure you have installed right operating system plugin, see http://community.jboss.org/docs/DOC-15214. Supported OSes are: rhel") end it "should validate definition and fail because no supported operating system version plugins is installed" do prepare_appliance @appliance.instance_variable_set(:@appliance_config, prepare_appliance_config) @@ -196,22 +243,17 @@ appliance_config_validator = mock(ApplianceConfigValidator) appliance_config_validator.should_receive(:validate) ApplianceConfigValidator.should_receive(:new).with(@appliance_config).and_return(appliance_config_validator) - puts @appliance_config - plugin_manager = mock(PluginManager) plugin_manager.stub!(:plugins).and_return({:os => {:fedora => {:type => :os, :name => :fedora, :full_name => "Fedora", :versions => ["xyz"]}}}) PluginManager.stub!(:instance).and_return(plugin_manager) - begin + lambda { @appliance.validate_definition - raise "Shouldn't raise" - rescue => e - e.message.should == "Not supported operating system version selected: 11. Supported versions are: xyz" - end + }.should raise_error(SystemExit, "Not supported operating system version selected: 11. Supported versions are: xyz") end end it "should remove old builds" do prepare_appliance