# encoding: utf-8
require 'test_helper'
class PackageTest < ActiveSupport::TestCase
test 'packages' do
tests = [
# test 1
{
:zpm => '
UnitTestSample
1.0.1
Znuny GmbH
http://znuny.org/
ABC
some description
YWJjw6TDtsO8w58=
YWJjw6TDtsO8w58=
Y2xhc3MgQ3JlYXRlQmFzZSA8IEFjdGl2ZVJlY29yZDo6TWlncmF0aW9uDQogIGRlZiBzZWxmLnVw
DQogICBjcmVhdGVfdGFibGUgOnNhbXBsZV90YWJsZXMgZG8gfHR8DQogICAgICB0LmNvbHVtbiA6
bmFtZSwgICAgICAgICAgIDpzdHJpbmcsIDpsaW1pdCA9PiAxNTAsICA6bnVsbCA9PiB0cnVlDQog
ICAgICB0LmNvbHVtbiA6ZGF0YSwgICAgICAgICAgIDpzdHJpbmcsIDpsaW1pdCA9PiA1MDAwLCA6
bnVsbCA9PiB0cnVlDQogICAgZW5kDQogIGVuZA0KDQogIGRlZiBzZWxmLmRvd24NCiAgICBkcm9w
X3RhYmxlIDpzYW1wbGVfdGFibGVzDQogIGVuZA0KZW5k
',
:action => 'install',
:result => true,
:verify => {
:package => {
:name => 'UnitTestSample',
:version => '1.0.1',
},
:check_files => [
{
:location => 'test.txt',
:result => true,
},
{
:location => 'test2.txt',
:result => false,
},
{
:location => 'some/dir/test.txt',
:result => true,
},
],
},
},
# test 2
{
:zpm => '
UnitTestSample
1.0.1
Znuny GmbH
http://znuny.org/
ABC
some description
YWJjw6TDtsO8w58=
',
:action => 'install',
:result => false,
},
# test 3
{
:zpm => '
UnitTestSample
1.0.0
Znuny GmbH
http://znuny.org/
ABC
some description
YWJjw6TDtsO8w58=
',
:action => 'install',
:result => false,
},
# test 4
{
:zpm => '
UnitTestSample
1.0.2
Znuny GmbH
http://znuny.org/
ABC
some description
YWJjw6TDtsO8w58=
YWJjw6TDtsO8w58=
Y2xhc3MgQ3JlYXRlQmFzZSA8IEFjdGl2ZVJlY29yZDo6TWlncmF0aW9uDQogIGRlZiBzZWxmLnVw
DQogICBjcmVhdGVfdGFibGUgOnNhbXBsZV90YWJsZXMgZG8gfHR8DQogICAgICB0LmNvbHVtbiA6
bmFtZSwgICAgICAgICAgIDpzdHJpbmcsIDpsaW1pdCA9PiAxNTAsICA6bnVsbCA9PiB0cnVlDQog
ICAgICB0LmNvbHVtbiA6ZGF0YSwgICAgICAgICAgIDpzdHJpbmcsIDpsaW1pdCA9PiA1MDAwLCA6
bnVsbCA9PiB0cnVlDQogICAgZW5kDQogIGVuZA0KDQogIGRlZiBzZWxmLmRvd24NCiAgICBkcm9w
X3RhYmxlIDpzYW1wbGVfdGFibGVzDQogIGVuZA0KZW5k
',
:action => 'install',
:result => true,
:verify => {
:package => {
:name => 'UnitTestSample',
:version => '1.0.2',
},
:check_files => [
{
:location => 'test.txt2',
:result => true,
},
{
:location => 'test.txt',
:result => false,
},
{
:location => 'test2.txt',
:result => false,
},
{
:location => 'some/dir/test.txt2',
:result => true,
},
],
},
},
# test 4
{
:name => 'UnitTestSample',
:version => '1.0.2',
:action => 'uninstall',
:result => true,
:verify => {
:check_files => [
{
:location => 'test.txt',
:result => false,
},
{
:location => 'test2.txt',
:result => false,
},
],
},
},
]
tests.each { |test|
if test[:action] == 'install'
begin
success = Package.install( :string => test[:zpm] )
rescue => e
puts 'ERROR: ' + e.inspect
success = false
end
if test[:result]
assert( success, "install package not successful" )
else
assert( !success, "install package successful but should not" )
end
elsif test[:action] == 'uninstall'
if test[:zpm]
begin
success = Package.uninstall( :string => test[:zpm] )
rescue
success = false
end
else
begin
success = Package.uninstall( :name => test[:name], :version => test[:version] )
rescue
success = false
end
end
if test[:result]
assert( success, "uninstall package not successful" )
else
assert( !success, "uninstall package successful but should not" )
end
end
if test[:verify] && test[:verify][:package]
exists = Package.where( :name => test[:verify][:package][:name], :version => test[:verify][:package][:version] ).first
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
end