X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;ds=sidebyside;f=spec%2Funit%2Fpluginpackager%2Fstandard_definition_spec.rb;fp=spec%2Funit%2Fpluginpackager%2Fstandard_definition_spec.rb;h=381c993b83baad4d8bcbdfd9e96d7632699c4551;hb=b87d2f4e68281062df1913440ca5753ae63314a9;hp=0000000000000000000000000000000000000000;hpb=ab0ea530b8ac956091f17b104ab2311336cfc250;p=packages%2Fprecise%2Fmcollective.git diff --git a/spec/unit/pluginpackager/standard_definition_spec.rb b/spec/unit/pluginpackager/standard_definition_spec.rb new file mode 100644 index 0000000..381c993 --- /dev/null +++ b/spec/unit/pluginpackager/standard_definition_spec.rb @@ -0,0 +1,100 @@ +#!/usr/bin/env rspec + +require 'spec_helper' + +module MCollective + module PluginPackager + describe StandardDefinition do + before :each do + PluginPackager.expects(:get_metadata).once.returns({:name => "foo", :version => 1}) + end + + describe "#initialize" do + it "should replace spaces in the package name with dashes" do + plugin = StandardDefinition.new(".", "test plugin", nil, nil, nil, nil, [], {}, "testplugin") + plugin.metadata[:name].should == "test-plugin" + end + + it "should set dependencies if present" do + plugin = StandardDefinition.new(".", "test plugin", nil, nil, nil, nil, [{:name => "foo", :version => nil}], {}, "testplugin") + plugin.dependencies.should == [{:name => "foo", :version => nil}, + {:name => "mcollective-common", :version => nil}] + end + + it "should set mc name and version dependencies" do + plugin = StandardDefinition.new(".", "test plugin", nil, nil, nil, nil, [], {:mcname => "pe-mcollective", :mcversion => "1"}, "testplugin") + plugin.mcname.should == "pe-mcollective" + plugin.mcversion.should == "1" + end + + it "should replace underscores with dashes in the name" do + plugin = StandardDefinition.new(".", "test_plugin", nil, nil, nil, nil, [], {:mcname => "pe-mcollective", :mcversion => "1"}, "testplugin") + plugin.metadata[:name].should == "test-plugin" + end + + it "should replace whitespaces with a single dash in the name" do + plugin = StandardDefinition.new(".", "test plugin", nil, nil, nil, nil, [], {:mcname => "pe-mcollective", :mcversion => "1"}, "testplugin") + plugin.metadata[:name].should == "test-plugin" + end + end + + describe "#identify_packages" do + it "should attempt to identify all packages" do + StandardDefinition.any_instance.expects(:common).once.returns(:check) + StandardDefinition.any_instance.expects(:plugin).once.returns(:check) + + plugin = StandardDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "testplugin") + plugin.packagedata[:common].should == :check + plugin.packagedata["testplugin"].should == :check + end + end + + describe "#plugin" do + + it "should return nil if the plugin doesn't contain any files" do + StandardDefinition.any_instance.expects(:common).returns(nil) + PluginPackager.expects(:check_dir_present).returns(false) + plugin = StandardDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "testplugin") + plugin.packagedata["testplugin"].should == nil + end + + it "should add plugin files to the file list" do + StandardDefinition.any_instance.expects(:common).returns(nil) + PluginPackager.expects(:check_dir_present).returns(true) + Dir.expects(:glob).with("./testplugin/*").returns(["file.rb"]) + plugin = StandardDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "testplugin") + plugin.packagedata["testplugin"][:files].should == ["file.rb"] + end + + it "should add common package as dependency if present" do + StandardDefinition.any_instance.expects(:common).returns(true) + PluginPackager.expects(:check_dir_present).returns(true) + Dir.expects(:glob).with("./testplugin/*").returns(["file.rb"]) + plugin = StandardDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "testplugin") + plugin.packagedata["testplugin"][:files].should == ["file.rb"] + plugin.packagedata["testplugin"][:dependencies].should == [{:name => "mcollective-common", :version => nil}] + plugin.packagedata["testplugin"][:plugindependency].should == {:name => "mcollective-foo-common", :version => 1, :iteration => 1} + end + end + + describe "#common" do + before do + StandardDefinition.any_instance.expects(:plugin).returns(false) + end + + it "should return nil if common doesn't contain any files" do + PluginPackager.expects(:check_dir_present).returns(false) + plugin = StandardDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "testplugin") + plugin.packagedata[:common].should == nil + end + + it "should add common files to the file list" do + PluginPackager.expects(:check_dir_present).returns(true) + Dir.expects(:glob).with("./util/*").returns(["common.rb"]) + plugin = StandardDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "testplugin") + plugin.packagedata[:common][:files].should == ["common.rb"] + end + end + end + end +end