2012-12-26 22:02:16 +00:00
|
|
|
# encoding: utf-8
|
2015-04-27 19:24:14 +00:00
|
|
|
# rubocop:disable Next, UselessAssignment
|
2012-12-26 22:02:16 +00:00
|
|
|
require 'test_helper'
|
2015-04-27 19:24:14 +00:00
|
|
|
|
2012-12-26 22:02:16 +00:00
|
|
|
class PackageTest < ActiveSupport::TestCase
|
|
|
|
test 'packages' do
|
|
|
|
tests = [
|
|
|
|
|
2013-03-22 12:48:47 +00:00
|
|
|
# test 1 - normal install
|
2012-12-26 22:02:16 +00:00
|
|
|
{
|
2015-04-27 13:42:53 +00:00
|
|
|
zpm: '<?xml version="1.0"?>
|
2012-12-26 22:02:16 +00:00
|
|
|
<zpm version="1.0">
|
|
|
|
<name>UnitTestSample</name>
|
|
|
|
<version>1.0.1</version>
|
|
|
|
<vendor>Znuny GmbH</vendor>
|
|
|
|
<url>http://znuny.org/</url>
|
|
|
|
<license>ABC</license>
|
|
|
|
<description lang="en">some description</description>
|
|
|
|
<filelist>
|
|
|
|
<file permission="644" location="test.txt">YWJjw6TDtsO8w58=</file>
|
|
|
|
<file permission="644" location="some/dir/test.txt">YWJjw6TDtsO8w58=</file>
|
|
|
|
<file permission="644" location="db/addon/unit_test_sample/20121212000001_create_base.rb">Y2xhc3MgQ3JlYXRlQmFzZSA8IEFjdGl2ZVJlY29yZDo6TWlncmF0aW9uDQogIGRlZiBzZWxmLnVw
|
|
|
|
DQogICBjcmVhdGVfdGFibGUgOnNhbXBsZV90YWJsZXMgZG8gfHR8DQogICAgICB0LmNvbHVtbiA6
|
|
|
|
bmFtZSwgICAgICAgICAgIDpzdHJpbmcsIDpsaW1pdCA9PiAxNTAsICA6bnVsbCA9PiB0cnVlDQog
|
|
|
|
ICAgICB0LmNvbHVtbiA6ZGF0YSwgICAgICAgICAgIDpzdHJpbmcsIDpsaW1pdCA9PiA1MDAwLCA6
|
|
|
|
bnVsbCA9PiB0cnVlDQogICAgZW5kDQogIGVuZA0KDQogIGRlZiBzZWxmLmRvd24NCiAgICBkcm9w
|
|
|
|
X3RhYmxlIDpzYW1wbGVfdGFibGVzDQogIGVuZA0KZW5k</file>
|
|
|
|
</filelist>
|
|
|
|
</zpm>',
|
2015-04-27 13:42:53 +00:00
|
|
|
action: 'install',
|
|
|
|
result: true,
|
|
|
|
verify: {
|
|
|
|
package: {
|
|
|
|
name: 'UnitTestSample',
|
|
|
|
version: '1.0.1',
|
2012-12-26 22:02:16 +00:00
|
|
|
},
|
2015-04-27 13:42:53 +00:00
|
|
|
check_files: [
|
2012-12-26 22:02:16 +00:00
|
|
|
{
|
2015-04-27 13:42:53 +00:00
|
|
|
location: 'test.txt',
|
|
|
|
result: true,
|
2012-12-26 22:02:16 +00:00
|
|
|
},
|
|
|
|
{
|
2015-04-27 13:42:53 +00:00
|
|
|
location: 'test2.txt',
|
|
|
|
result: false,
|
2012-12-26 22:02:16 +00:00
|
|
|
},
|
|
|
|
{
|
2015-04-27 13:42:53 +00:00
|
|
|
location: 'some/dir/test.txt',
|
|
|
|
result: true,
|
2012-12-26 22:02:16 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2013-03-22 12:48:47 +00:00
|
|
|
# test 2 - try to install same package again / should not work
|
2012-12-26 22:02:16 +00:00
|
|
|
{
|
2015-04-27 13:42:53 +00:00
|
|
|
zpm: '<?xml version="1.0"?>
|
2012-12-26 22:02:16 +00:00
|
|
|
<zpm version="1.0">
|
|
|
|
<name>UnitTestSample</name>
|
|
|
|
<version>1.0.1</version>
|
|
|
|
<vendor>Znuny GmbH</vendor>
|
|
|
|
<url>http://znuny.org/</url>
|
|
|
|
<license>ABC</license>
|
|
|
|
<description lang="en">some description</description>
|
|
|
|
<filelist>
|
|
|
|
<file permission="644" location="test.txt">YWJjw6TDtsO8w58=</file>
|
|
|
|
</filelist>
|
|
|
|
</zpm>',
|
2015-04-27 13:42:53 +00:00
|
|
|
action: 'install',
|
|
|
|
result: false,
|
2012-12-26 22:02:16 +00:00
|
|
|
},
|
|
|
|
|
2013-03-22 12:48:47 +00:00
|
|
|
# test 3 - try to install lower version / should not work
|
2012-12-26 22:02:16 +00:00
|
|
|
{
|
2015-04-27 13:42:53 +00:00
|
|
|
zpm: '<?xml version="1.0"?>
|
2012-12-26 22:02:16 +00:00
|
|
|
<zpm version="1.0">
|
|
|
|
<name>UnitTestSample</name>
|
|
|
|
<version>1.0.0</version>
|
|
|
|
<vendor>Znuny GmbH</vendor>
|
|
|
|
<url>http://znuny.org/</url>
|
|
|
|
<license>ABC</license>
|
|
|
|
<description lang="en">some description</description>
|
|
|
|
<filelist>
|
|
|
|
<file permission="644" location="test.txt">YWJjw6TDtsO8w58=</file>
|
|
|
|
</filelist>
|
|
|
|
</zpm>',
|
2015-04-27 13:42:53 +00:00
|
|
|
action: 'install',
|
|
|
|
result: false,
|
2012-12-26 22:02:16 +00:00
|
|
|
},
|
|
|
|
|
2013-03-22 12:48:47 +00:00
|
|
|
# test 4 - upgrade 7 should work
|
2012-12-26 22:02:16 +00:00
|
|
|
{
|
2015-04-27 13:42:53 +00:00
|
|
|
zpm: '<?xml version="1.0"?>
|
2012-12-26 22:02:16 +00:00
|
|
|
<zpm version="1.0">
|
|
|
|
<name>UnitTestSample</name>
|
|
|
|
<version>1.0.2</version>
|
|
|
|
<vendor>Znuny GmbH</vendor>
|
|
|
|
<url>http://znuny.org/</url>
|
|
|
|
<license>ABC</license>
|
|
|
|
<description lang="en">some description</description>
|
|
|
|
<filelist>
|
|
|
|
<file permission="644" location="test.txt2">YWJjw6TDtsO8w58=</file>
|
|
|
|
<file permission="644" location="some/dir/test.txt2">YWJjw6TDtsO8w58=</file>
|
|
|
|
<file permission="644" location="db/addon/unit_test_sample/20121212000001_create_base.rb">Y2xhc3MgQ3JlYXRlQmFzZSA8IEFjdGl2ZVJlY29yZDo6TWlncmF0aW9uDQogIGRlZiBzZWxmLnVw
|
|
|
|
DQogICBjcmVhdGVfdGFibGUgOnNhbXBsZV90YWJsZXMgZG8gfHR8DQogICAgICB0LmNvbHVtbiA6
|
|
|
|
bmFtZSwgICAgICAgICAgIDpzdHJpbmcsIDpsaW1pdCA9PiAxNTAsICA6bnVsbCA9PiB0cnVlDQog
|
|
|
|
ICAgICB0LmNvbHVtbiA6ZGF0YSwgICAgICAgICAgIDpzdHJpbmcsIDpsaW1pdCA9PiA1MDAwLCA6
|
|
|
|
bnVsbCA9PiB0cnVlDQogICAgZW5kDQogIGVuZA0KDQogIGRlZiBzZWxmLmRvd24NCiAgICBkcm9w
|
|
|
|
X3RhYmxlIDpzYW1wbGVfdGFibGVzDQogIGVuZA0KZW5k</file>
|
|
|
|
</filelist>
|
|
|
|
</zpm>',
|
2015-04-27 13:42:53 +00:00
|
|
|
action: 'install',
|
|
|
|
result: true,
|
|
|
|
verify: {
|
|
|
|
package: {
|
|
|
|
name: 'UnitTestSample',
|
|
|
|
version: '1.0.2',
|
2012-12-26 22:02:16 +00:00
|
|
|
},
|
2015-04-27 13:42:53 +00:00
|
|
|
check_files: [
|
2012-12-26 22:02:16 +00:00
|
|
|
{
|
2015-04-27 13:42:53 +00:00
|
|
|
location: 'test.txt2',
|
|
|
|
result: true,
|
2012-12-26 22:02:16 +00:00
|
|
|
},
|
|
|
|
{
|
2015-04-27 13:42:53 +00:00
|
|
|
location: 'test.txt',
|
|
|
|
result: false,
|
2012-12-26 22:02:16 +00:00
|
|
|
},
|
|
|
|
{
|
2015-04-27 13:42:53 +00:00
|
|
|
location: 'test2.txt',
|
|
|
|
result: false,
|
2012-12-26 22:02:16 +00:00
|
|
|
},
|
|
|
|
{
|
2015-04-27 13:42:53 +00:00
|
|
|
location: 'some/dir/test.txt2',
|
|
|
|
result: true,
|
2012-12-26 22:02:16 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2013-03-22 12:48:47 +00:00
|
|
|
# test 4 - uninstall package / should work
|
2012-12-26 22:02:16 +00:00
|
|
|
{
|
2015-04-27 13:42:53 +00:00
|
|
|
name: 'UnitTestSample',
|
|
|
|
version: '1.0.2',
|
|
|
|
action: 'uninstall',
|
|
|
|
result: true,
|
|
|
|
verify: {
|
|
|
|
check_files: [
|
2012-12-26 22:02:16 +00:00
|
|
|
{
|
2015-04-27 13:42:53 +00:00
|
|
|
location: 'test.txt',
|
|
|
|
result: false,
|
2012-12-26 22:02:16 +00:00
|
|
|
},
|
|
|
|
{
|
2015-04-27 13:42:53 +00:00
|
|
|
location: 'test2.txt',
|
|
|
|
result: false,
|
2012-12-26 22:02:16 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2013-03-22 12:48:47 +00:00
|
|
|
# test 5 - check auto_install mechanism
|
2013-01-07 08:32:48 +00:00
|
|
|
{
|
2015-04-27 13:42:53 +00:00
|
|
|
zpm: '<?xml version="1.0"?>
|
2013-01-07 08:32:48 +00:00
|
|
|
<zpm version="1.0">
|
|
|
|
<name>UnitTestSample</name>
|
|
|
|
<version>1.0.2</version>
|
|
|
|
<vendor>Znuny GmbH</vendor>
|
|
|
|
<url>http://znuny.org/</url>
|
|
|
|
<license>ABC</license>
|
|
|
|
<description lang="en">some description</description>
|
|
|
|
<filelist>
|
|
|
|
<file permission="644" location="test.txt2">YWJjw6TDtsO8w58=</file>
|
|
|
|
<file permission="644" location="some/dir/test.txt2">YWJjw6TDtsO8w58=</file>
|
|
|
|
<file permission="644" location="db/addon/unit_test_sample/20121212000001_create_base.rb">Y2xhc3MgQ3JlYXRlQmFzZSA8IEFjdGl2ZVJlY29yZDo6TWlncmF0aW9uDQogIGRlZiBzZWxmLnVw
|
|
|
|
DQogICBjcmVhdGVfdGFibGUgOnNhbXBsZV90YWJsZXMgZG8gfHR8DQogICAgICB0LmNvbHVtbiA6
|
|
|
|
bmFtZSwgICAgICAgICAgIDpzdHJpbmcsIDpsaW1pdCA9PiAxNTAsICA6bnVsbCA9PiB0cnVlDQog
|
|
|
|
ICAgICB0LmNvbHVtbiA6ZGF0YSwgICAgICAgICAgIDpzdHJpbmcsIDpsaW1pdCA9PiA1MDAwLCA6
|
|
|
|
bnVsbCA9PiB0cnVlDQogICAgZW5kDQogIGVuZA0KDQogIGRlZiBzZWxmLmRvd24NCiAgICBkcm9w
|
|
|
|
X3RhYmxlIDpzYW1wbGVfdGFibGVzDQogIGVuZA0KZW5k</file>
|
|
|
|
</filelist>
|
|
|
|
</zpm>',
|
2015-04-27 13:42:53 +00:00
|
|
|
action: 'auto_install',
|
|
|
|
result: true,
|
|
|
|
verify: {
|
|
|
|
package: {
|
|
|
|
name: 'UnitTestSample',
|
|
|
|
version: '1.0.2',
|
2013-01-07 08:32:48 +00:00
|
|
|
},
|
2015-04-27 13:42:53 +00:00
|
|
|
check_files: [
|
2013-01-07 08:32:48 +00:00
|
|
|
{
|
2015-04-27 13:42:53 +00:00
|
|
|
location: 'test.txt2',
|
|
|
|
result: true,
|
2013-01-07 08:32:48 +00:00
|
|
|
},
|
|
|
|
{
|
2015-04-27 13:42:53 +00:00
|
|
|
location: 'test.txt',
|
|
|
|
result: false,
|
2013-01-07 08:32:48 +00:00
|
|
|
},
|
|
|
|
{
|
2015-04-27 13:42:53 +00:00
|
|
|
location: 'test2.txt',
|
|
|
|
result: false,
|
2013-01-07 08:32:48 +00:00
|
|
|
},
|
|
|
|
{
|
2015-04-27 13:42:53 +00:00
|
|
|
location: 'some/dir/test.txt2',
|
|
|
|
result: true,
|
2013-01-07 08:32:48 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2013-03-22 12:48:47 +00:00
|
|
|
# test 6 - check uninstall / should work
|
2013-01-07 08:32:48 +00:00
|
|
|
{
|
2015-04-27 13:42:53 +00:00
|
|
|
name: 'UnitTestSample',
|
|
|
|
version: '1.0.2',
|
|
|
|
action: 'uninstall',
|
|
|
|
result: true,
|
|
|
|
verify: {
|
|
|
|
check_files: [
|
2013-01-07 08:32:48 +00:00
|
|
|
{
|
2015-04-27 13:42:53 +00:00
|
|
|
location: 'test.txt',
|
|
|
|
result: false,
|
2013-01-07 08:32:48 +00:00
|
|
|
},
|
|
|
|
{
|
2015-04-27 13:42:53 +00:00
|
|
|
location: 'test2.txt',
|
|
|
|
result: false,
|
2013-01-07 08:32:48 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2012-12-26 22:02:16 +00:00
|
|
|
]
|
|
|
|
tests.each { |test|
|
|
|
|
if test[:action] == 'install'
|
|
|
|
begin
|
2015-04-27 13:42:53 +00:00
|
|
|
success = Package.install( string: test[:zpm] )
|
2012-12-26 22:02:16 +00:00
|
|
|
rescue => e
|
|
|
|
puts 'ERROR: ' + e.inspect
|
|
|
|
success = false
|
|
|
|
end
|
|
|
|
if test[:result]
|
2015-04-27 12:51:43 +00:00
|
|
|
assert( success, 'install package not successful' )
|
2012-12-26 22:02:16 +00:00
|
|
|
else
|
2015-04-27 12:51:43 +00:00
|
|
|
assert( !success, 'install package successful but should not' )
|
2012-12-26 22:02:16 +00:00
|
|
|
end
|
|
|
|
elsif test[:action] == 'uninstall'
|
|
|
|
if test[:zpm]
|
|
|
|
begin
|
2015-04-27 13:42:53 +00:00
|
|
|
success = Package.uninstall( string: test[:zpm] )
|
2012-12-26 22:02:16 +00:00
|
|
|
rescue
|
|
|
|
success = false
|
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
2015-04-27 13:42:53 +00:00
|
|
|
success = Package.uninstall( name: test[:name], version: test[:version] )
|
2012-12-26 22:02:16 +00:00
|
|
|
rescue
|
|
|
|
success = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if test[:result]
|
2015-04-27 12:51:43 +00:00
|
|
|
assert( success, 'uninstall package not successful' )
|
2012-12-26 22:02:16 +00:00
|
|
|
else
|
2015-04-27 12:51:43 +00:00
|
|
|
assert( !success, 'uninstall package successful but should not' )
|
2012-12-26 22:02:16 +00:00
|
|
|
end
|
2013-01-07 08:32:48 +00:00
|
|
|
elsif test[:action] == 'auto_install'
|
|
|
|
if test[:zpm]
|
|
|
|
if !File.exist?( Rails.root.to_s + '/auto_install/' )
|
|
|
|
Dir.mkdir( Rails.root.to_s + '/auto_install/', 0755)
|
|
|
|
end
|
|
|
|
location = Rails.root.to_s + '/auto_install/unittest.zpm'
|
|
|
|
file = File.new( location, 'wb' )
|
2015-04-27 19:24:14 +00:00
|
|
|
file.write( test[:zpm] )
|
2013-01-07 08:32:48 +00:00
|
|
|
file.close
|
|
|
|
end
|
|
|
|
begin
|
|
|
|
success = Package.auto_install()
|
|
|
|
rescue
|
|
|
|
success = false
|
|
|
|
end
|
|
|
|
if test[:zpm]
|
|
|
|
File.delete( location )
|
|
|
|
end
|
2012-12-26 22:02:16 +00:00
|
|
|
end
|
|
|
|
if test[:verify] && test[:verify][:package]
|
2015-04-27 13:42:53 +00:00
|
|
|
exists = Package.where( name: test[:verify][:package][:name], version: test[:verify][:package][:version] ).first
|
2012-12-26 22:02:16 +00:00
|
|
|
assert( exists, "package '#{test[:verify][:package][:name]}' is not installed" )
|
|
|
|
end
|
|
|
|
if test[:verify] && test[:verify][:check_files]
|
|
|
|
test[:verify][:check_files].each {|item|
|
|
|
|
exists = File.exist?( item[:location] )
|
|
|
|
if item[:result]
|
|
|
|
assert( exists, "'#{item[:location]}' exists" )
|
|
|
|
else
|
|
|
|
assert( !exists, "'#{item[:location]}' doesn't exists" )
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
end
|
2015-04-27 14:15:29 +00:00
|
|
|
end
|