trabajo-afectivo/test/integration/package_test.rb

391 lines
10 KiB
Ruby
Raw Normal View History

2022-01-01 13:38:12 +00:00
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
require 'integration_test_helper'
2015-04-27 19:24:14 +00:00
class PackageTest < ActiveSupport::TestCase
2017-11-06 01:32:47 +00:00
test 'packages' do
tests = [
2013-03-22 12:48:47 +00:00
# test 1 - normal install
{
zpm: '{
"name": "UnitTestSample",
"version": "1.0.1",
"vendor": "Znuny GmbH",
"license": "ABC",
"url": "http://znuny.org/",
"description": [
{
"language": "en",
"text": "some description"
}
],
"files": [
{
"permission": "644",
"location": "test.txt",
"content": "YWJjw6TDtsO8w58="
},
{
"permission": "644",
"location": "some/dir/test.txt",
"content": "YWJjw6TDtsO8w58="
},
{
"permission": "644",
"location": "db/addon/unit_test_sample/20121212000001_create_base.rb",
2017-09-23 06:25:55 +00:00
"content": "Y2xhc3MgQ3JlYXRlQmFzZSA8IEFjdGl2ZVJlY29yZDo6TWlncmF0aW9uWzQuMl0NCiAgZGVmIHNlbGYudXANCiAgIGNyZWF0ZV90YWJsZSA6c2FtcGxlX3RhYmxlcyBkbyB8dHwNCiAgICAgIHQuY29sdW1uIDpuYW1lLCAgICAgICAgICAgOnN0cmluZywgOmxpbWl0ID0+IDE1MCwgIDpudWxsID0+IHRydWUNCiAgICAgIHQuY29sdW1uIDpkYXRhLCAgICAgICAgICAgOnN0cmluZywgOmxpbWl0ID0+IDUwMDAsIDpudWxsID0+IHRydWUNCiAgICBlbmQNCiAgZW5kDQoNCiAgZGVmIHNlbGYuZG93bg0KICAgIGRyb3BfdGFibGUgOnNhbXBsZV90YWJsZXMNCiAgZW5kDQplbmQ="
}
]
}',
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,
},
],
},
},
2016-02-01 00:42:30 +00:00
# test 2 - renstall
{
action: 'reinstall',
name: 'UnitTestSample',
2016-02-01 00:42:30 +00:00
result: true,
verify: {
package: {
name: 'UnitTestSample',
2016-02-01 00:42:30 +00:00
version: '1.0.1',
},
check_files: [
{
location: 'test.txt',
result: true,
2016-02-01 00:42:30 +00:00
},
{
location: 'test2.txt',
result: false,
2016-02-01 00:42:30 +00:00
},
{
location: 'some/dir/test.txt',
result: true,
2016-02-01 00:42:30 +00:00
},
],
},
},
# test 3 - try to install same package again / should not work
{
zpm: '{
"name": "UnitTestSample",
"version": "1.0.1",
"vendor": "Znuny GmbH",
"license": "ABC",
"url": "http://znuny.org/",
"description": [
{
"language": "en",
"text": "some description"
}
],
"files": [
{
"permission": "644",
"location": "test.txt",
"content": "YWJjw6TDtsO8w58="
}
]
}',
action: 'install',
result: false,
},
2016-02-01 00:42:30 +00:00
# test 4 - try to install lower version / should not work
{
zpm: '{
"name": "UnitTestSample",
"version": "1.0.0",
"vendor": "Znuny GmbH",
"license": "ABC",
"url": "http://znuny.org/",
"description": [
{
"language": "en",
"text": "some description"
}
],
"files": [
{
"permission": "644",
"location": "test.txt",
"content": "YWJjw6TDtsO8w58="
}
]
}',
action: 'install',
result: false,
},
2016-02-01 00:42:30 +00:00
# test 5 - upgrade 7 should work
{
zpm: '{
"name": "UnitTestSample",
"version": "1.0.2",
"vendor": "Znuny GmbH",
"license": "ABC",
"url": "http://znuny.org/",
"description": [
{
"language": "en",
"text": "some description"
}
],
"files": [
{
"permission": "644",
"location": "test.txt2",
"content": "YWJjw6TDtsO8w58="
},
{
"permission": "644",
"location": "some/dir/test.txt2",
"content": "YWJjw6TDtsO8w58="
},
{
"permission": "644",
"location": "db/addon/unit_test_sample/20121212000001_create_base.rb",
2017-09-23 06:25:55 +00:00
"content": "Y2xhc3MgQ3JlYXRlQmFzZSA8IEFjdGl2ZVJlY29yZDo6TWlncmF0aW9uWzQuMl0NCiAgZGVmIHNlbGYudXANCiAgIGNyZWF0ZV90YWJsZSA6c2FtcGxlX3RhYmxlcyBkbyB8dHwNCiAgICAgIHQuY29sdW1uIDpuYW1lLCAgICAgICAgICAgOnN0cmluZywgOmxpbWl0ID0+IDE1MCwgIDpudWxsID0+IHRydWUNCiAgICAgIHQuY29sdW1uIDpkYXRhLCAgICAgICAgICAgOnN0cmluZywgOmxpbWl0ID0+IDUwMDAsIDpudWxsID0+IHRydWUNCiAgICBlbmQNCiAgZW5kDQoNCiAgZGVmIHNlbGYuZG93bg0KICAgIGRyb3BfdGFibGUgOnNhbXBsZV90YWJsZXMNCiAgZW5kDQplbmQ="
}
]
}',
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,
},
],
},
},
2016-02-01 00:42:30 +00:00
# test 6 - uninstall package / should work
{
name: 'UnitTestSample',
version: '1.0.2',
action: 'uninstall',
result: true,
verify: {
check_files: [
{
location: 'test.txt',
result: false,
},
{
location: 'test2.txt',
result: false,
},
],
},
},
2016-02-01 00:42:30 +00:00
# test 7 - check auto_install mechanism
{
zpm: '{
"name": "UnitTestSample",
"version": "1.0.2",
"vendor": "Znuny GmbH",
"license": "ABC",
"url": "http://znuny.org/",
"description": [
{
"language": "en",
"text": "some description"
}
],
"files": [
{
"permission": "644",
"location": "test.txt2",
"content": "YWJjw6TDtsO8w58="
},
{
"permission": "644",
"location": "some/dir/test.txt2",
"content": "YWJjw6TDtsO8w58="
},
{
"permission": "644",
"location": "db/addon/unit_test_sample/20121212000001_create_base.rb",
2017-09-23 06:25:55 +00:00
"content": "Y2xhc3MgQ3JlYXRlQmFzZSA8IEFjdGl2ZVJlY29yZDo6TWlncmF0aW9uWzQuMl0NCiAgZGVmIHNlbGYudXANCiAgIGNyZWF0ZV90YWJsZSA6c2FtcGxlX3RhYmxlcyBkbyB8dHwNCiAgICAgIHQuY29sdW1uIDpuYW1lLCAgICAgICAgICAgOnN0cmluZywgOmxpbWl0ID0+IDE1MCwgIDpudWxsID0+IHRydWUNCiAgICAgIHQuY29sdW1uIDpkYXRhLCAgICAgICAgICAgOnN0cmluZywgOmxpbWl0ID0+IDUwMDAsIDpudWxsID0+IHRydWUNCiAgICBlbmQNCiAgZW5kDQoNCiAgZGVmIHNlbGYuZG93bg0KICAgIGRyb3BfdGFibGUgOnNhbXBsZV90YWJsZXMNCiAgZW5kDQplbmQ="
}
]
}',
action: 'auto_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,
},
],
},
},
2016-02-01 00:42:30 +00:00
# test 8 - check uninstall / should work
{
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 do |test|
case test[:action]
when 'install'
begin
2017-09-23 06:25:55 +00:00
package = Package.install(string: test[:zpm])
rescue => e
puts "ERROR: #{e.inspect}"
end
if test[:result]
2017-09-23 06:25:55 +00:00
assert(package, 'install package not successful')
issues = package.verify
assert_not(issues, 'package verify not successful')
else
assert_not(package, 'install package successful but should not')
end
when 'reinstall'
2016-02-01 00:42:30 +00:00
begin
2017-09-23 06:25:55 +00:00
package = Package.reinstall(test[:name])
2016-02-01 00:42:30 +00:00
rescue
package = false
end
if test[:result]
2017-09-23 06:25:55 +00:00
assert(package, 'reinstall package not successful')
2016-02-01 00:42:30 +00:00
issues = package.verify
assert_not(issues, 'package verify not successful')
2016-02-01 00:42:30 +00:00
else
assert_not(package, 'reinstall package successful but should not')
2016-02-01 00:42:30 +00:00
end
when 'uninstall'
if test[:zpm]
begin
2017-09-23 06:25:55 +00:00
package = Package.uninstall(string: test[:zpm])
rescue
package = false
end
else
begin
2017-09-23 06:25:55 +00:00
package = Package.uninstall(name: test[:name], version: test[:version])
rescue
package = false
end
end
if test[:result]
2017-09-23 06:25:55 +00:00
assert(package, 'uninstall package not successful')
else
assert_not(package, 'uninstall package successful but should not')
end
when 'auto_install'
if test[:zpm]
if !File.exist?(Rails.root.join('auto_install'))
Dir.mkdir(Rails.root.join('auto_install'), 0o755)
end
location = Rails.root.join('auto_install/unittest.zpm')
2017-09-23 06:25:55 +00:00
file = File.new(location, 'wb')
file.write(test[:zpm])
file.close
end
begin
Package.auto_install
rescue
2019-06-28 11:38:49 +00:00
false
end
if test[:zpm]
File.delete(location)
end
end
if test[:verify] && test[:verify][:package]
2017-09-23 06:25:55 +00:00
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
next if !test[:verify]
next if !test[:verify][:check_files]
test[:verify][:check_files].each do |item|
2017-09-23 06:25:55 +00:00
exists = File.exist?(item[:location])
if item[:result]
assert(exists, "'#{item[:location]}' exists")
else
assert_not(exists, "'#{item[:location]}' doesn't exists")
end
end
end
end
end