/
local-plugin-spec.rb
109 lines (84 loc) · 4.18 KB
/
local-plugin-spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#
# Copyright 2010 Red Hat, Inc.
#
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 3 of
# the License, or (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this software; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
require 'boxgrinder-build/plugins/delivery/local/local-plugin'
require 'hashery/opencascade'
module BoxGrinder
describe LocalPlugin do
before(:each) do
@config = Config.new('plugins' => {'local' => {'path' => 'a/path'}})
@appliance_config = mock('ApplianceConfig')
@appliance_config.stub!(:path).and_return(OpenCascade.new({:build => 'build/path'}))
@appliance_config.stub!(:name).and_return('appliance')
@appliance_config.stub!(:version).and_return(1)
@appliance_config.stub!(:release).and_return(0)
@appliance_config.stub!(:os).and_return(OpenCascade.new({:name => :fedora, :version => '13'}))
@appliance_config.stub!(:hardware).and_return(OpenCascade.new({:arch => 'x86_64'}))
@plugin = RSpecPluginHelper.new(LocalPlugin).prepare(@config, @appliance_config,
:previous_plugin => OpenCascade.new(:type => :os, :deliverables => {:disk => "a_disk.raw", :metadata => 'metadata.xml'}),
:plugin_info => {:class => BoxGrinder::LocalPlugin, :type => :delivery, :name => :local, :full_name => "Local file system"}
)
@plugin_config = @config.plugins['local']
@appliance_config = @plugin.instance_variable_get(:@appliance_config)
@exec_helper = @plugin.instance_variable_get(:@exec_helper)
@log = @plugin.instance_variable_get(:@log)
@dir = @plugin.instance_variable_get(:@dir)
end
describe ".execute" do
it "should package and deliver the appliance" do
@plugin_config.merge!('package' => true)
FileUtils.should_receive(:mkdir_p).with('a/path')
package_helper = mock(PackageHelper)
PackageHelper.should_receive(:new).with(@config, @appliance_config, :log => @log, :exec_helper => @exec_helper).and_return(package_helper)
package_helper.should_receive(:package).with('.', "a/path/appliance-1.0-fedora-13-x86_64-raw.tgz").and_return("deliverable")
@plugin.execute
end
it "should not package, but deliver the appliance" do
@plugin_config.merge!('package' => false)
FileUtils.should_receive(:mkdir_p).with('a/path')
PackageHelper.should_not_receive(:new)
@exec_helper.should_receive(:execute).with("cp 'a_disk.raw' 'a/path'")
@exec_helper.should_receive(:execute).with("cp 'metadata.xml' 'a/path'")
@plugin.execute
end
it "should not deliver the package, because it is already delivered" do
@plugin.instance_variable_set(:@plugin_config, {
'overwrite' => false,
'path' => 'a/path',
'package' => false
})
PackageHelper.should_not_receive(:new)
@exec_helper.should_not_receive(:execute)
@plugin.should_receive(:deliverables_exists?).and_return(true)
@plugin.execute
end
end
describe ".deliverables_exists?" do
it "should return true for package" do
@plugin_config.merge!('package' => true)
File.should_receive(:exists?).with('a/path/appliance-1.0-fedora-13-x86_64-raw.tgz').and_return(true)
@plugin.deliverables_exists?.should == true
end
it "should return true for non-packaged appliance" do
@plugin_config.merge!('package' => false)
File.should_receive(:exists?).with('a/path/a_disk.raw').and_return(true)
File.should_receive(:exists?).with('a/path/metadata.xml').and_return(true)
@plugin.deliverables_exists?.should == true
end
end
end
end