Update mcollective.init according to OSCI-855
[packages/precise/mcollective.git] / spec / unit / pluginpackager / standard_definition_spec.rb
1 #!/usr/bin/env rspec
2
3 require 'spec_helper'
4
5 module MCollective
6   module PluginPackager
7     describe StandardDefinition do
8       before :each do
9         PluginPackager.expects(:get_metadata).once.returns({:name => "foo", :version => 1})
10       end
11
12       describe "#initialize" do
13         it "should replace spaces in the package name with dashes" do
14           plugin = StandardDefinition.new(".", "test plugin", nil, nil, nil, nil, [], {}, "testplugin")
15           plugin.metadata[:name].should == "test-plugin"
16         end
17
18         it "should set dependencies if present" do
19           plugin = StandardDefinition.new(".", "test plugin", nil, nil, nil, nil, [{:name => "foo", :version => nil}], {}, "testplugin")
20           plugin.dependencies.should == [{:name => "foo", :version => nil},
21                                          {:name => "mcollective-common", :version => nil}]
22         end
23
24         it "should set mc name and version dependencies" do
25           plugin = StandardDefinition.new(".", "test plugin", nil, nil, nil, nil, [], {:mcname => "pe-mcollective", :mcversion => "1"}, "testplugin")
26           plugin.mcname.should == "pe-mcollective"
27           plugin.mcversion.should == "1"
28         end
29
30         it "should replace underscores with dashes in the name" do
31           plugin = StandardDefinition.new(".", "test_plugin", nil, nil, nil, nil, [], {:mcname => "pe-mcollective", :mcversion => "1"}, "testplugin")
32           plugin.metadata[:name].should == "test-plugin"
33         end
34
35         it "should replace whitespaces with a single dash in the name" do
36           plugin = StandardDefinition.new(".", "test  plugin", nil, nil, nil, nil, [], {:mcname => "pe-mcollective", :mcversion => "1"}, "testplugin")
37           plugin.metadata[:name].should == "test-plugin"
38         end
39       end
40
41       describe "#identify_packages" do
42         it "should attempt to identify all packages" do
43           StandardDefinition.any_instance.expects(:common).once.returns(:check)
44           StandardDefinition.any_instance.expects(:plugin).once.returns(:check)
45
46           plugin = StandardDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "testplugin")
47           plugin.packagedata[:common].should == :check
48           plugin.packagedata["testplugin"].should == :check
49         end
50       end
51
52       describe "#plugin" do
53
54         it "should return nil if the plugin doesn't contain any files" do
55           StandardDefinition.any_instance.expects(:common).returns(nil)
56           PluginPackager.expects(:check_dir_present).returns(false)
57           plugin = StandardDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "testplugin")
58           plugin.packagedata["testplugin"].should == nil
59         end
60
61         it "should add plugin files to the file list" do
62           StandardDefinition.any_instance.expects(:common).returns(nil)
63           PluginPackager.expects(:check_dir_present).returns(true)
64           Dir.expects(:glob).with("./testplugin/*").returns(["file.rb"])
65           plugin = StandardDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "testplugin")
66           plugin.packagedata["testplugin"][:files].should == ["file.rb"]
67         end
68
69         it "should add common package as dependency if present" do
70           StandardDefinition.any_instance.expects(:common).returns(true)
71           PluginPackager.expects(:check_dir_present).returns(true)
72           Dir.expects(:glob).with("./testplugin/*").returns(["file.rb"])
73           plugin = StandardDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "testplugin")
74           plugin.packagedata["testplugin"][:files].should == ["file.rb"]
75           plugin.packagedata["testplugin"][:dependencies].should == [{:name => "mcollective-common", :version => nil}]
76           plugin.packagedata["testplugin"][:plugindependency].should == {:name => "mcollective-foo-common", :version => 1, :iteration => 1}
77         end
78       end
79
80       describe "#common" do
81         before do
82           StandardDefinition.any_instance.expects(:plugin).returns(false)
83         end
84
85         it "should return nil if common doesn't contain any files" do
86           PluginPackager.expects(:check_dir_present).returns(false)
87           plugin = StandardDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "testplugin")
88           plugin.packagedata[:common].should == nil
89         end
90
91         it "should add common files to the file list" do
92           PluginPackager.expects(:check_dir_present).returns(true)
93           Dir.expects(:glob).with("./util/*").returns(["common.rb"])
94           plugin = StandardDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "testplugin")
95           plugin.packagedata[:common][:files].should == ["common.rb"]
96         end
97       end
98     end
99   end
100 end