spec/unit/plugins/mcollective/packagers/debpackage_packager_spec.rb in mcollective-client-2.0.0 vs spec/unit/plugins/mcollective/packagers/debpackage_packager_spec.rb in mcollective-client-2.2.0
- old
+ new
@@ -17,10 +17,11 @@
end
before :each do
PluginPackager.stubs(:build_tool?).with("debuild").returns(true)
@plugin = mock()
+ @plugin.stubs(:mcname).returns("mcollective")
end
after :all do
@tmpdirs.each{|tmpdir| FileUtils.rm_rf tmpdir if File.directory? tmpdir}
end
@@ -28,11 +29,11 @@
describe "#initialize" do
it "should raise an exception if debuild isn't present" do
PluginPackager.expects(:build_tool?).with("debuild").returns(false)
expect{
DebpackagePackager.new("plugin")
- }.to raise_error RuntimeError, "package 'debuild' is not installed"
+ }.to raise_error(RuntimeError, "package 'debuild' is not installed")
end
it "should set the correct libdir and verbose value" do
PluginPackager.expects(:build_tool?).with("debuild").returns(true)
packager = DebpackagePackager.new("plugin", nil, nil, true)
@@ -47,10 +48,11 @@
@plugin.stubs(:packagedata).returns({:test => {:files => ["test.rb"]}})
@plugin.stubs(:metadata).returns({:name => "test_plugin", :version => "1"})
@plugin.stubs(:iteration).returns("1")
@packager.stubs(:prepare_tmpdirs)
@packager.stubs(:create_package)
+ @packager.stubs(:move_packages)
@packager.stubs(:cleanup_tmpdirs)
Dir.stubs(:mktmpdir).with("mcollective_packager").returns("/tmp")
Dir.stubs(:mkdir)
end
@@ -61,11 +63,11 @@
@packager.current_package_shortname.should == "mcollective-test_plugin-test"
@packager.current_package_fullname.should == "mcollective-test_plugin-test_1-1"
end
it "Should create the build dir" do
- Dir.expects(:mkdir).with("/tmp/mcollective-test_plugin-test_1-1")
+ Dir.expects(:mkdir).with("/tmp/mcollective-test_plugin-test_1")
@packager.create_packages
end
it "should create packages" do
@packager.expects(:create_package)
@@ -77,11 +79,11 @@
it "should raise an exception if the package cannot be created" do
packager = DebpackagePackager.new(@plugin)
packager.stubs(:create_file).raises("test exception")
expect{
packager.create_package
- }.to raise_error RuntimeError, "Could not build package - test exception"
+ }.to raise_error(RuntimeError, "Could not build package - test exception")
end
it "should correctly create a package" do
packager = DebpackagePackager.new(@plugin, nil, nil, true)
@@ -97,11 +99,10 @@
packager.build_dir = "/tmp"
packager.tmpdir = "/tmp"
packager.current_package_fullname = "test"
PluginPackager.expects(:safe_system).with("debuild -i -us -uc")
- FileUtils.expects(:cp).with(File.join("/tmp", "test_all.deb"), ".")
packager.expects(:puts).with("Created package test")
packager.create_package
end
@@ -120,11 +121,10 @@
packager.build_dir = "/tmp"
packager.tmpdir = "/tmp"
packager.current_package_fullname = "test"
PluginPackager.expects(:safe_system).with("debuild -i -ktest")
- FileUtils.expects(:cp).with(File.join("/tmp", "test_all.deb"), ".")
packager.expects(:puts).with("Created package test")
packager.create_package
end
end
@@ -137,20 +137,20 @@
it "should raise an exception if preinstall is not null and preinstall script isn't present" do
@plugin.stubs(:preinstall).returns("myscript")
File.expects(:exists?).with("myscript").returns(false)
expect{
@packager.create_preandpost_install
- }.to raise_error RuntimeError, "pre-install script 'myscript' not found"
+ }.to raise_error(RuntimeError, "pre-install script 'myscript' not found")
end
it "should raise an exception if postinstall is not null and postinstall script isn't present" do
@plugin.stubs(:preinstall).returns(nil)
@plugin.stubs(:postinstall).returns("myscript")
File.expects(:exists?).with("myscript").returns(false)
expect{
@packager.create_preandpost_install
- }.to raise_error RuntimeError, "post-install script 'myscript' not found"
+ }.to raise_error(RuntimeError, "post-install script 'myscript' not found")
end
it "should copy the preinstall and postinstall scripts to the correct directory with the correct name" do
@plugin.stubs(:postinstall).returns("myscript")
@plugin.stubs(:preinstall).returns("myscript")
@@ -164,51 +164,74 @@
end
describe "#create_install" do
before :each do
@packager = DebpackagePackager.new(@plugin)
+ @plugin.stubs(:path).returns("")
end
it "should raise an exception if the install file can't be created" do
File.expects(:join).raises("test error")
expect{
@packager.create_install
- }.to raise_error RuntimeError, "Could not create install file - test error"
+ }.to raise_error(RuntimeError, "Could not create install file - test error")
end
it "should copy the package install file to the correct location" do
tmpdir = maketmpdir
Dir.mkdir(File.join(tmpdir, "debian"))
@packager.build_dir = tmpdir
@packager.current_package_shortname = "test"
@packager.current_package_data = {:files => ["foo.rb"]}
@packager.create_install
install_file = File.read("#{tmpdir}/debian/test.install")
- install_file.should == "/usr/share/mcollective/plugins/mcollective/foo.rb /usr/share/mcollective/plugins/mcollective/.\n"
+ install_file.should == "/usr/share/mcollective/plugins/mcollective/foo.rb /usr/share/mcollective/plugins/mcollective\n"
end
end
+ describe "#move_packages" do
+ before :each do
+ @plugin = mock()
+ end
+
+ it "should move the packages to the working directory" do
+ Dir.expects(:glob)
+ File.expects(:join)
+ FileUtils.expects(:cp)
+ @packager = DebpackagePackager.new(@plugin)
+ @packager.move_packages
+ end
+
+ it "should raise an error if the packages could not be moved" do
+ @packager = DebpackagePackager.new(@plugin)
+ File.expects(:join).raises("error")
+ expect{
+ @packager.move_packages
+ }.to raise_error(RuntimeError, "Could not copy packages to working directory: 'error'")
+ end
+ end
+
describe "#create_tar" do
before :each do
@packager = DebpackagePackager.new(@plugin, nil, true)
end
it "should raise an exception if the tarball can't be built" do
PluginPackager.expects(:do_quietly?).raises("test error")
expect{
@packager.create_tar
- }.to raise_error RuntimeError, "Could not create tarball - test error"
+ }.to raise_error(RuntimeError, "Could not create tarball - test error")
end
it "should create a tarball containing the package files" do
@packager.tmpdir = "/tmp"
@packager.build_dir = "/build_dir"
@packager.current_package_shortname = "test"
@plugin.stubs(:metadata).returns(@plugin)
@plugin.stubs(:[]).with(:version).returns("1")
@plugin.stubs(:iteration).returns("1")
- PluginPackager.expects(:safe_system).with("tar -Pcvzf /tmp/test_1.orig.tar.gz /build_dir")
+ PluginPackager.expects(:safe_system).with("tar -Pcvzf /tmp/test_1.orig.tar.gz test_1")
@packager.create_tar
end
end
describe "#create_file" do
@@ -218,11 +241,11 @@
it "should raise an exception if the file can't be created" do
File.expects(:dirname).raises("test error")
expect{
@packager.create_file("test")
- }.to raise_error RuntimeError, "could not create test file - test error"
+ }.to raise_error(RuntimeError, "could not create test file - test error")
end
it "should place a build file in the debian directory" do
tmpdir = maketmpdir
Dir.mkdir(File.join(tmpdir, "debian"))
@@ -235,15 +258,18 @@
result.should == "testfile\n"
end
end
describe "#prepare_tmpdirs" do
- before :all do
+ before :each do
@tmpfile = Tempfile.new("mc-file").path
end
- after :all do
- FileUtils.rm(@tmpfile)
+ after :each do
+ begin
+ FileUtils.rm(@tmpfile)
+ rescue Exception
+ end
end
it "should create the correct tmp dirs and copy package contents to correct dir" do
packager = DebpackagePackager.new(@plugin)
tmpdir = maketmpdir