tpkg 2.3.3 → 2.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/Portfile +39 -0
- data/Portfile.template +39 -0
- data/README.md +43 -0
- data/Rakefile +468 -18
- data/bin/gem2tpkg +2 -2
- data/bin/tpkg +18 -13
- data/bin/tpkg_uploader +132 -0
- data/ca.pem +1 -0
- data/control +7 -0
- data/depend +3 -0
- data/externals-etch/authorized_keys +40 -0
- data/externals-etch/group +9 -0
- data/externals-etch/iptables +38 -0
- data/externals-etch/limits +30 -0
- data/externals-etch/nfs +30 -0
- data/externals-etch/sudo +30 -0
- data/externals-etch/supplemental_groups +8 -0
- data/externals-etch/sysctl +30 -0
- data/externals-etch/user +41 -0
- data/externals/group +39 -0
- data/externals/supplemental_groups +48 -0
- data/externals/user +39 -0
- data/lib/tpkg.rb +260 -991
- data/lib/tpkg/os.rb +164 -0
- data/lib/tpkg/os/debian.rb +159 -0
- data/lib/tpkg/os/freebsd.rb +113 -0
- data/lib/tpkg/os/macosx.rb +113 -0
- data/lib/tpkg/os/redhat.rb +173 -0
- data/lib/tpkg/os/solaris.rb +101 -0
- data/lib/tpkg/os/windows.rb +26 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify.rb +67 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/errors.rb +127 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/kwalify.schema.yaml +58 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/main.rb +442 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/messages.rb +173 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/meta-validator.rb +275 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/parser/base.rb +127 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/parser/yaml.rb +841 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/rule.rb +559 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/templates/genclass-java.eruby +222 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/templates/genclass-php.eruby +104 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/templates/genclass-ruby.eruby +113 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/types.rb +156 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util.rb +158 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/assert-text-equal.rb +46 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/hash-interface.rb +18 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/hashlike.rb +51 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/option-parser.rb +220 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/ordered-hash.rb +57 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/testcase-helper.rb +112 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/validator.rb +282 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/yaml-parser.rb +870 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh.rb +219 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/agent.rb +179 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/constants.rb +18 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/key_manager.rb +219 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/abstract.rb +60 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/hostbased.rb +71 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/keyboard_interactive.rb +66 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/password.rb +39 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/publickey.rb +92 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/pageant.rb +183 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/session.rb +134 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/buffer.rb +340 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/buffered_io.rb +198 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/config.rb +205 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/channel.rb +630 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/constants.rb +33 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/session.rb +597 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/term.rb +178 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/errors.rb +85 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/key_factory.rb +102 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/known_hosts.rb +129 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/loggable.rb +61 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/packet.rb +102 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/prompt.rb +93 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/command.rb +75 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/errors.rb +14 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/http.rb +94 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/socks4.rb +70 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/socks5.rb +142 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/ruby_compat.rb +43 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/service/forward.rb +288 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test.rb +89 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/channel.rb +129 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/extensions.rb +152 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/kex.rb +44 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/local_packet.rb +51 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/packet.rb +81 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/remote_packet.rb +38 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/script.rb +157 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/socket.rb +64 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/algorithms.rb +384 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/cipher_factory.rb +97 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/constants.rb +30 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac.rb +31 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/abstract.rb +79 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/md5.rb +12 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/md5_96.rb +11 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/none.rb +15 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/sha1.rb +13 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/sha1_96.rb +11 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/identity_cipher.rb +55 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/kex.rb +13 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +208 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +77 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/openssl.rb +127 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/packet_stream.rb +235 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/server_version.rb +71 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/session.rb +276 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/state.rb +206 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/verifiers/lenient.rb +30 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/verifiers/null.rb +12 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/verifiers/strict.rb +53 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/version.rb +62 -0
- data/lib/tpkg/version.rb +3 -0
- data/man/man1/cpan2tpkg.1 +82 -0
- data/man/man1/gem2tpkg.1 +120 -0
- data/man/man1/tpkg.1 +411 -0
- data/pkginfo +8 -0
- data/postinstall.solaris +11 -0
- data/postremove.solaris +16 -0
- data/schema/schema-1.0.5.yml +0 -0
- data/schema/schema-1.0.6.yml +0 -0
- data/schema/schema-1.0.7.yml +0 -0
- data/schema/schema-1.0.8.yml +0 -0
- data/schema/schema-1.0.9.yml +0 -0
- data/schema/schema.yml +0 -0
- data/schema/tpkg-1.0.0.dtd +0 -0
- data/schema/tpkg-1.0.1.dtd +0 -0
- data/schema/tpkg-1.0.2.dtd +0 -0
- data/schema/tpkg-1.0.3.dtd +0 -0
- data/schema/tpkg-1.0.4.dtd +0 -0
- data/schema/tpkg-1.0.5.dtd +0 -0
- data/schema/tpkg-1.0.6.dtd +0 -0
- data/schema/tpkg-1.0.7.dtd +0 -0
- data/schema/tpkg-1.0.8.dtd +0 -0
- data/schema/tpkg-1.0.9.dtd +0 -0
- data/schema/tpkg.dtd +0 -0
- data/test/TODO +30 -0
- data/test/premadetestpkg/pkg_without_file_metadata-1.0-1.tpkg +0 -0
- data/test/test_checksum.rb +53 -0
- data/test/test_compress.rb +55 -0
- data/test/test_conflict.rb +41 -0
- data/test/test_crontabs.rb +398 -0
- data/test/test_dependency.rb +1113 -0
- data/test/test_downgrade.rb +80 -0
- data/test/test_download.rb +95 -0
- data/test/test_encrypt.rb +136 -0
- data/test/test_filemetadata.rb +131 -0
- data/test/test_initscript.rb +93 -0
- data/test/test_install.rb +186 -0
- data/test/test_lock.rb +82 -0
- data/test/test_make.rb +410 -0
- data/test/test_metadata.rb +805 -0
- data/test/test_misc.rb +379 -0
- data/test/test_options.rb +1711 -0
- data/test/test_os.rb +193 -0
- data/test/test_os_debian.rb +99 -0
- data/test/test_os_freebsd.rb +89 -0
- data/test/test_os_macosx.rb +79 -0
- data/test/test_os_redhat.rb +124 -0
- data/test/test_os_solaris.rb +85 -0
- data/test/test_os_windows.rb +26 -0
- data/test/test_query.rb +134 -0
- data/test/test_remove.rb +539 -0
- data/test/test_tar.rb +99 -0
- data/test/test_unpack.rb +977 -0
- data/test/test_upgrade.rb +398 -0
- data/test/test_version.rb +54 -0
- data/test/testcmds/crontab +14 -0
- data/test/testcmds/debian/apt-cache +145 -0
- data/test/testcmds/debian/dpkg-query +16 -0
- data/test/testcmds/freebsd/pkg_info +13 -0
- data/test/testcmds/macosx/port +35 -0
- data/test/testcmds/redhat/rpmbuild +6 -0
- data/test/testcmds/redhat/yum +90 -0
- data/test/testcmds/solaris/pkginfo +25 -0
- data/test/testcmds/solaris/pkgutil +36 -0
- data/test/testpkg/reloc/encfile +2 -0
- data/test/testpkg/reloc/file +2 -0
- data/test/testpkg/reloc/precryptfile +1 -0
- data/test/testpkg/reloc/precryptfile.plaintext +3 -0
- data/test/testpkg/tpkg-bad-ownergroup.xml +25 -0
- data/test/testpkg/tpkg-bad-ownergroup.yml +18 -0
- data/test/testpkg/tpkg-default-perms.xml +28 -0
- data/test/testpkg/tpkg-default-perms.yml +20 -0
- data/test/testpkg/tpkg-good-ownergroup.xml +25 -0
- data/test/testpkg/tpkg-good-ownergroup.yml +18 -0
- data/test/testpkg/tpkg-nativedeps.yml +13 -0
- data/test/testpkg/tpkg-nofiles.xml +14 -0
- data/test/testpkg/tpkg-nofiles.yml +9 -0
- data/test/testpkg/tpkg.xml +35 -0
- data/test/testpkg/tpkg.yml +25 -0
- data/test/tpkgtest.rb +300 -0
- data/tpkg.conf +16 -0
- data/tpkg.gemspec +24 -0
- data/tpkg.spec +28 -0
- data/tpkg.xml +17 -0
- data/tpkg_profile.sh +32 -0
- metadata +306 -31
@@ -0,0 +1,1113 @@
|
|
1
|
+
#
|
2
|
+
# Test tpkg's ability to resolve dependencies
|
3
|
+
#
|
4
|
+
|
5
|
+
require File.expand_path('tpkgtest', File.dirname(__FILE__))
|
6
|
+
|
7
|
+
class TpkgDependencyTests < Test::Unit::TestCase
|
8
|
+
include TpkgTests
|
9
|
+
|
10
|
+
def setup
|
11
|
+
Tpkg::set_prompt(false)
|
12
|
+
@tpkg = Tpkg.new
|
13
|
+
|
14
|
+
# temp dir that will automatically get deleted at end of test run, can be
|
15
|
+
# used for storing packages
|
16
|
+
@tempoutdir = Dir.mktmpdir('tempoutdir')
|
17
|
+
@pkgfiles = []
|
18
|
+
# a depends on b, and c >= 1.1, <= 1.2
|
19
|
+
@pkgfiles << make_package(:output_directory => @tempoutdir, :change => { 'name' => 'a' }, :remove => ['operatingsystem', 'architecture'], :dependencies => {'b' => {}, 'c' => {'minimum_version' => '1.1', 'maximum_version' => '1.2'}})
|
20
|
+
# generic b for all OSs
|
21
|
+
# These two b packages will end up with the same filename, so we
|
22
|
+
# manually rename this one
|
23
|
+
bpkg = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'b' }, :remove => ['operatingsystem', 'architecture'])
|
24
|
+
bpkgnew = bpkg + '.generic'
|
25
|
+
File.rename(bpkg, bpkgnew)
|
26
|
+
@pkgfiles << bpkgnew
|
27
|
+
# b specific to this OS (should prefer this one)
|
28
|
+
@pkgfiles << make_package(:output_directory => @tempoutdir, :change => { 'name' => 'b', 'operatingsystem' => @tpkg.os.os }, :remove => ['architecture'])
|
29
|
+
# c 1.0 to 1.3, a's dep should result in c-1.2 getting picked
|
30
|
+
@pkgfiles << make_package(:output_directory => @tempoutdir, :change => { 'name' => 'c', 'version' => '1.0' }, :remove => ['operatingsystem', 'architecture'], :dependencies => {'d' => {'minimum_version' => '1.0', 'maximum_version' => '1.0'}})
|
31
|
+
@pkgfiles << make_package(:output_directory => @tempoutdir, :change => { 'name' => 'c', 'version' => '1.1' }, :remove => ['operatingsystem', 'architecture'], :dependencies => {'d' => {'minimum_version' => '1.1', 'maximum_version' => '1.1'}})
|
32
|
+
@pkgfiles << make_package(:output_directory => @tempoutdir, :change => { 'name' => 'c', 'version' => '1.2' }, :remove => ['operatingsystem', 'architecture'], :dependencies => {'d' => {'minimum_version' => '1.2', 'maximum_version' => '1.2'}})
|
33
|
+
@pkgfiles << make_package(:output_directory => @tempoutdir, :change => { 'name' => 'c', 'version' => '1.3' }, :remove => ['operatingsystem', 'architecture'], :dependencies => {'d' => {'minimum_version' => '1.3', 'maximum_version' => '1.3'}})
|
34
|
+
# d 1.0 to 1.3, c's dep should result in d-1.2 getting picked
|
35
|
+
@pkgfiles << make_package(:output_directory => @tempoutdir, :change => { 'name' => 'd', 'version' => '1.0' }, :remove => ['operatingsystem', 'architecture'])
|
36
|
+
@pkgfiles << make_package(:output_directory => @tempoutdir, :change => { 'name' => 'd', 'version' => '1.1' }, :remove => ['operatingsystem', 'architecture'])
|
37
|
+
@pkgfiles << make_package(:output_directory => @tempoutdir, :change => { 'name' => 'd', 'version' => '1.2' }, :remove => ['operatingsystem', 'architecture'])
|
38
|
+
@pkgfiles << make_package(:output_directory => @tempoutdir, :change => { 'name' => 'd', 'version' => '1.3' }, :remove => ['operatingsystem', 'architecture'])
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_packages_meet_requirement
|
42
|
+
# FIXME
|
43
|
+
end
|
44
|
+
def test_package_meets_requirement
|
45
|
+
#
|
46
|
+
# Test version handling
|
47
|
+
#
|
48
|
+
|
49
|
+
pkgfile = make_package(:change => {'package_version' => '5.0.0'}, :output_directory => @tempoutdir, :remove => ['operatingsystem', 'architecture'])
|
50
|
+
metadata = Tpkg::metadata_from_package(pkgfile)
|
51
|
+
pkg = { :metadata => metadata, :source => pkgfile }
|
52
|
+
req = { :name => 'testpkg' }
|
53
|
+
|
54
|
+
#
|
55
|
+
# First up a bunch of iterations testing combinations of min/max versions
|
56
|
+
# alone, and with both min/max and greater/less than package versions.
|
57
|
+
#
|
58
|
+
# Apologies that this code is long and perhaps somewhat cryptic. I tried
|
59
|
+
# to reduce duplication and at the same time retain some cut-n-paste
|
60
|
+
# consistency, but a fresh set of eyes might come up with something
|
61
|
+
# cleaner.
|
62
|
+
#
|
63
|
+
# Just a reminder, pkgfile has version 1.0 and package version 5.0.0
|
64
|
+
#
|
65
|
+
|
66
|
+
# >= <= >=? <=?
|
67
|
+
[['2.0', '3.0', false, true], # version below range
|
68
|
+
['1.0', '2.0', true, true], # version at bottom of range
|
69
|
+
['0.5', '2.0', true, true], # version in middle of range
|
70
|
+
['0.5', '1.0', true, true], # version at top of range
|
71
|
+
['0.1', '0.5', true, false]].each do |testver| # version above range
|
72
|
+
minver, maxver, minresult, maxresult = testver
|
73
|
+
|
74
|
+
# Minimum version only
|
75
|
+
req = { :name => 'testpkg' }
|
76
|
+
req[:minimum_version] = minver
|
77
|
+
assert_equal(
|
78
|
+
minresult,
|
79
|
+
@tpkg.package_meets_requirement?(pkg, req),
|
80
|
+
"ver >= #{minver}")
|
81
|
+
# >= <= >=? <=?
|
82
|
+
[['6.0', '7.0', false, true], # version below range
|
83
|
+
['5.0', '6.0', true, true], # version at bottom of range
|
84
|
+
['4.5', '6.0', true, true], # version in middle of range
|
85
|
+
['4.5', '5.0', true, true], # version at top of range
|
86
|
+
['4.0', '4.5', true, false]].each do |testpackver| # version above range
|
87
|
+
minpackver, maxpackver, minpackresult, maxpackresult = testpackver
|
88
|
+
|
89
|
+
# Minimum package version only
|
90
|
+
req = { :name => 'testpkg' }
|
91
|
+
req[:minimum_version] = minver
|
92
|
+
req[:minimum_package_version] = minpackver
|
93
|
+
assert_equal(
|
94
|
+
# We can cheat and use .to_f rather than Version with our test
|
95
|
+
# versions since we know they're valid floating point numbers. It
|
96
|
+
# doesn't work in the general case. I.e. tpkg itself can't take the
|
97
|
+
# same shortcut.
|
98
|
+
(metadata[:version].to_f != minver.to_f && minresult) ||
|
99
|
+
(metadata[:version].to_f == minver.to_f && minresult && minpackresult),
|
100
|
+
@tpkg.package_meets_requirement?(pkg, req),
|
101
|
+
"ver >= #{minver}, packver >= #{minpackver}")
|
102
|
+
end
|
103
|
+
# > < >? <?
|
104
|
+
[['6.0', '7.0', false, true], # version below range
|
105
|
+
['5.0', '6.0', false, true], # version just below range
|
106
|
+
['4.5', '6.0', true, true], # version in middle of range
|
107
|
+
['4.5', '5.0', true, false], # version just above range
|
108
|
+
['3.0', '4.0', true, false]].each do |testpackver| # version above range
|
109
|
+
gtpackver, ltpackver, gtpackverresult, ltpackverresult = testpackver
|
110
|
+
|
111
|
+
# Just :package_version_greater_than
|
112
|
+
req = { :name => 'testpkg' }
|
113
|
+
req[:minimum_version] = minver
|
114
|
+
req[:package_version_greater_than] = gtpackver
|
115
|
+
assert_equal(
|
116
|
+
(metadata[:version].to_f != minver.to_f && minresult) ||
|
117
|
+
(metadata[:version].to_f == minver.to_f && minresult && gtpackverresult),
|
118
|
+
@tpkg.package_meets_requirement?(pkg, req),
|
119
|
+
"ver >= #{minver}, packver > #{gtpackver}")
|
120
|
+
end
|
121
|
+
|
122
|
+
# Maximum version only
|
123
|
+
req = { :name => 'testpkg' }
|
124
|
+
req[:maximum_version] = maxver
|
125
|
+
assert_equal(
|
126
|
+
maxresult,
|
127
|
+
@tpkg.package_meets_requirement?(pkg, req),
|
128
|
+
"ver <= #{maxver}")
|
129
|
+
[['6.0', '7.0', false, true], # version below range
|
130
|
+
['5.0', '6.0', true, true], # version at bottom of range
|
131
|
+
['4.5', '6.0', true, true], # version in middle of range
|
132
|
+
['4.5', '5.0', true, true], # version at top of range
|
133
|
+
['4.0', '4.5', true, false]].each do |testpackver| # version above range
|
134
|
+
minpackver, maxpackver, minpackresult, maxpackresult = testpackver
|
135
|
+
|
136
|
+
# Maximum package version only
|
137
|
+
req = { :name => 'testpkg' }
|
138
|
+
req[:maximum_version] = maxver
|
139
|
+
req[:maximum_package_version] = maxpackver
|
140
|
+
assert_equal(
|
141
|
+
(metadata[:version].to_f != maxver.to_f && maxresult) ||
|
142
|
+
(metadata[:version].to_f == maxver.to_f && maxresult && maxpackresult),
|
143
|
+
@tpkg.package_meets_requirement?(pkg, req),
|
144
|
+
"ver <= #{maxver}, packver <= #{maxpackver}")
|
145
|
+
end
|
146
|
+
[['6.0', '7.0', false, true], # version below range
|
147
|
+
['5.0', '6.0', false, true], # version just below range
|
148
|
+
['4.5', '6.0', true, true], # version in middle of range
|
149
|
+
['4.5', '5.0', true, false], # version just above range
|
150
|
+
['3.0', '4.0', true, false]].each do |testpackver| # version above range
|
151
|
+
gtpackver, ltpackver, gtpackverresult, ltpackverresult = testpackver
|
152
|
+
|
153
|
+
# Just :package_version_less_than
|
154
|
+
req = { :name => 'testpkg' }
|
155
|
+
req[:maximum_version] = maxver
|
156
|
+
req[:package_version_less_than] = ltpackver
|
157
|
+
assert_equal(
|
158
|
+
(metadata[:version].to_f != maxver.to_f && maxresult) ||
|
159
|
+
(metadata[:version].to_f == maxver.to_f && maxresult && ltpackverresult),
|
160
|
+
@tpkg.package_meets_requirement?(pkg, req),
|
161
|
+
"ver <= #{maxver}, packver < #{ltpackver}")
|
162
|
+
end
|
163
|
+
|
164
|
+
# Minimum and maximum version
|
165
|
+
req = { :name => 'testpkg' }
|
166
|
+
req[:minimum_version] = minver
|
167
|
+
req[:maximum_version] = maxver
|
168
|
+
assert_equal(
|
169
|
+
minresult && maxresult,
|
170
|
+
@tpkg.package_meets_requirement?(pkg, req),
|
171
|
+
"ver >= #{minver}, <= #{maxver}")
|
172
|
+
[['6.0', '7.0', false, true], # version below range
|
173
|
+
['5.0', '6.0', true, true], # version at bottom of range
|
174
|
+
['4.5', '6.0', true, true], # version in middle of range
|
175
|
+
['4.5', '5.0', true, true], # version at top of range
|
176
|
+
['4.0', '4.5', true, false]].each do |testpackver| # version above range
|
177
|
+
minpackver, maxpackver, minpackresult, maxpackresult = testpackver
|
178
|
+
|
179
|
+
# Minimum package version only
|
180
|
+
req = { :name => 'testpkg' }
|
181
|
+
req[:minimum_version] = minver
|
182
|
+
req[:maximum_version] = maxver
|
183
|
+
req[:minimum_package_version] = minpackver
|
184
|
+
assert_equal(
|
185
|
+
(metadata[:version].to_f != minver.to_f && minresult && maxresult) ||
|
186
|
+
(metadata[:version].to_f == minver.to_f && minresult && maxresult && minpackresult),
|
187
|
+
@tpkg.package_meets_requirement?(pkg, req),
|
188
|
+
"ver >= #{minver}, <= #{maxver}, packver >= #{minpackver}")
|
189
|
+
# Maximum package version only
|
190
|
+
req = { :name => 'testpkg' }
|
191
|
+
req[:minimum_version] = minver
|
192
|
+
req[:maximum_version] = maxver
|
193
|
+
req[:maximum_package_version] = maxpackver
|
194
|
+
assert_equal(
|
195
|
+
(metadata[:version].to_f != maxver.to_f && minresult && maxresult) ||
|
196
|
+
(metadata[:version].to_f == maxver.to_f && minresult && maxresult && maxpackresult),
|
197
|
+
@tpkg.package_meets_requirement?(pkg, req),
|
198
|
+
"ver >= #{minver}, <= #{maxver}, packver <= #{maxpackver}")
|
199
|
+
# Minimum and maximum package version
|
200
|
+
req = { :name => 'testpkg' }
|
201
|
+
req[:minimum_version] = minver
|
202
|
+
req[:maximum_version] = maxver
|
203
|
+
req[:minimum_package_version] = minpackver
|
204
|
+
req[:maximum_package_version] = maxpackver
|
205
|
+
assert_equal(
|
206
|
+
(metadata[:version].to_f != minver.to_f && metadata[:version].to_f != maxver.to_f && minresult && maxresult) ||
|
207
|
+
(metadata[:version].to_f == minver.to_f && metadata[:version].to_f != maxver.to_f && minresult && maxresult && minpackresult) ||
|
208
|
+
(metadata[:version].to_f != minver.to_f && metadata[:version].to_f == maxver.to_f && minresult && maxresult && maxpackresult) ||
|
209
|
+
(metadata[:version].to_f == minver.to_f && metadata[:version].to_f == maxver.to_f && minresult && maxresult && minpackresult && maxpackresult),
|
210
|
+
@tpkg.package_meets_requirement?(pkg, req),
|
211
|
+
"ver >= #{minver}, <= #{maxver}, packver >= #{minpackver}, <= #{maxpackver}")
|
212
|
+
end
|
213
|
+
[['6.0', '7.0', false, true], # version below range
|
214
|
+
['5.0', '6.0', false, true], # version just below range
|
215
|
+
['4.5', '6.0', true, true], # version in middle of range
|
216
|
+
['4.5', '5.0', true, false], # version just above range
|
217
|
+
['3.0', '4.0', true, false]].each do |testpackver| # version above range
|
218
|
+
gtpackver, ltpackver, gtpackverresult, ltpackverresult = testpackver
|
219
|
+
|
220
|
+
# Just :package_version_greater_than
|
221
|
+
req = { :name => 'testpkg' }
|
222
|
+
req[:minimum_version] = minver
|
223
|
+
req[:maximum_version] = maxver
|
224
|
+
req[:package_version_greater_than] = gtpackver
|
225
|
+
assert_equal(
|
226
|
+
(metadata[:version].to_f != minver.to_f && minresult && maxresult) ||
|
227
|
+
(metadata[:version].to_f == minver.to_f && minresult && maxresult && gtpackverresult),
|
228
|
+
@tpkg.package_meets_requirement?(pkg, req),
|
229
|
+
"ver >= #{minver}, <= #{maxver}, packver > #{gtpackver}")
|
230
|
+
# Just :package_version_less_than
|
231
|
+
req = { :name => 'testpkg' }
|
232
|
+
req[:minimum_version] = minver
|
233
|
+
req[:maximum_version] = maxver
|
234
|
+
req[:package_version_less_than] = ltpackver
|
235
|
+
assert_equal(
|
236
|
+
(metadata[:version].to_f != maxver.to_f && minresult && maxresult) ||
|
237
|
+
(metadata[:version].to_f == maxver.to_f && minresult && maxresult && ltpackverresult),
|
238
|
+
@tpkg.package_meets_requirement?(pkg, req),
|
239
|
+
"ver >= #{minver}, <= #{maxver}, packver < #{ltpackver}")
|
240
|
+
# :package_version_greater_than and :package_version_less_than
|
241
|
+
req = { :name => 'testpkg' }
|
242
|
+
req[:minimum_version] = minver
|
243
|
+
req[:maximum_version] = maxver
|
244
|
+
req[:package_version_greater_than] = gtpackver
|
245
|
+
req[:package_version_less_than] = ltpackver
|
246
|
+
assert_equal(
|
247
|
+
(metadata[:version].to_f != minver.to_f && metadata[:version].to_f != maxver.to_f && minresult && maxresult) ||
|
248
|
+
(metadata[:version].to_f == minver.to_f && metadata[:version].to_f != maxver.to_f && minresult && maxresult && gtpackverresult) ||
|
249
|
+
(metadata[:version].to_f != minver.to_f && metadata[:version].to_f == maxver.to_f && minresult && maxresult && ltpackverresult) ||
|
250
|
+
(metadata[:version].to_f == minver.to_f && metadata[:version].to_f == maxver.to_f && minresult && maxresult && gtpackverresult && ltpackverresult),
|
251
|
+
@tpkg.package_meets_requirement?(pkg, req),
|
252
|
+
"ver >= #{minver}, <= #{maxver}, packver > #{gtpackver}, < #{ltpackver}")
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
#
|
257
|
+
# Tests for allowed_versions
|
258
|
+
#
|
259
|
+
|
260
|
+
# 5.* included since it matches the package version but not the version,
|
261
|
+
# in case there's any mistake about applying the pattern to the wrong
|
262
|
+
# version.
|
263
|
+
[['0.*', false],
|
264
|
+
['1.*', true],
|
265
|
+
['1.1.*', false],
|
266
|
+
['2.*', false],
|
267
|
+
['5.*', false]].each do |allowedver|
|
268
|
+
ver, verresult = allowedver
|
269
|
+
req = { :name => 'testpkg' }
|
270
|
+
req[:allowed_versions] = ver
|
271
|
+
assert_equal(
|
272
|
+
verresult,
|
273
|
+
@tpkg.package_meets_requirement?(pkg, req),
|
274
|
+
"allowed ver #{ver}")
|
275
|
+
|
276
|
+
# 1.* included since it matches the version but not the package version,
|
277
|
+
# in case there's any mistake about applying the pattern to the wrong
|
278
|
+
# version.
|
279
|
+
[['1.*', false],
|
280
|
+
['4.*', false],
|
281
|
+
['5.*', true],
|
282
|
+
['5.1.*', false],
|
283
|
+
['6.*', false]].each do |allowedpackver|
|
284
|
+
packver, packverresult = allowedpackver
|
285
|
+
req = { :name => 'testpkg' }
|
286
|
+
req[:allowed_versions] = "#{ver}-#{packver}"
|
287
|
+
assert_equal(
|
288
|
+
verresult && packverresult,
|
289
|
+
@tpkg.package_meets_requirement?(pkg, req),
|
290
|
+
"allowed ver #{ver}, allowed package ver #{packver}")
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
#
|
295
|
+
# Tests for version_greater_than and version_less_than functionality
|
296
|
+
#
|
297
|
+
|
298
|
+
# > < >? <?
|
299
|
+
[['0.1', '0.5', true, false],
|
300
|
+
['1.0', '2.0', false, true],
|
301
|
+
['0.5', '2.0', true, true],
|
302
|
+
['0.5', '1.0', true, false],
|
303
|
+
['2.0', '3.0', false, true]].each do |testver|
|
304
|
+
gtver, ltver, gtverresult, ltverresult = testver
|
305
|
+
|
306
|
+
# Just :version_greater_than
|
307
|
+
req = { :name => 'testpkg' }
|
308
|
+
req[:version_greater_than] = gtver
|
309
|
+
assert_equal(
|
310
|
+
gtverresult,
|
311
|
+
@tpkg.package_meets_requirement?(pkg, req),
|
312
|
+
"ver > #{gtver}")
|
313
|
+
|
314
|
+
# Just :version_less_than
|
315
|
+
req.delete(:version_greater_than)
|
316
|
+
req[:version_less_than] = ltver
|
317
|
+
req.delete(:package_version_greater_than)
|
318
|
+
req.delete(:package_version_less_than)
|
319
|
+
assert_equal(
|
320
|
+
ltverresult,
|
321
|
+
@tpkg.package_meets_requirement?(pkg, req),
|
322
|
+
"version less than #{ltver}")
|
323
|
+
|
324
|
+
# Both :version_greater_than and :version_less_than
|
325
|
+
req[:version_greater_than] = gtver
|
326
|
+
req[:version_less_than] = ltver
|
327
|
+
req.delete(:package_version_greater_than)
|
328
|
+
req.delete(:package_version_less_than)
|
329
|
+
assert_equal(
|
330
|
+
gtverresult && ltverresult,
|
331
|
+
@tpkg.package_meets_requirement?(pkg, req),
|
332
|
+
"version greater than #{gtver}, less than #{ltver}")
|
333
|
+
end
|
334
|
+
|
335
|
+
FileUtils.rm_f(pkgfile)
|
336
|
+
|
337
|
+
# More complicated test for: Can't upgrade if package has higher version
|
338
|
+
# number but lower package version number
|
339
|
+
pkgfile = make_package(:output_directory => @tempoutdir, :change => {'version' => '2.3', 'package_version' => '2' }, :remove => ['operatingsystem', 'architecture'])
|
340
|
+
metadata = Tpkg::metadata_from_package(pkgfile)
|
341
|
+
pkg = { :metadata => metadata, :source => pkgfile }
|
342
|
+
req = { :name => 'testpkg' }
|
343
|
+
# version number is not equal to min or max version. So we don't care if min/max package version satisfied or not
|
344
|
+
req[:minimum_version] = '0.5'
|
345
|
+
req[:maximum_version] = '3.0'
|
346
|
+
req[:minimum_package_version] = '3'
|
347
|
+
req[:maximum_package_version] = '3'
|
348
|
+
assert(@tpkg.package_meets_requirement?(pkg, req))
|
349
|
+
req[:minimum_package_version] = '1'
|
350
|
+
req[:maximum_package_version] = '1'
|
351
|
+
assert(@tpkg.package_meets_requirement?(pkg, req))
|
352
|
+
# version is same as maximum_version, so we have to look at maximum_package_version
|
353
|
+
req[:minimum_version] = '0.5'
|
354
|
+
req[:maximum_version] = '2.3'
|
355
|
+
req[:minimum_package_version] = '1'
|
356
|
+
req[:maximum_package_version] = '1'
|
357
|
+
assert(!@tpkg.package_meets_requirement?(pkg, req))
|
358
|
+
req[:minimum_package_version] = '3'
|
359
|
+
req[:maximum_package_version] = '3'
|
360
|
+
assert(@tpkg.package_meets_requirement?(pkg, req))
|
361
|
+
# version is same as minimum_version, so we have to look at minimum_package_version
|
362
|
+
req[:minimum_version] = '2.3'
|
363
|
+
req[:maximum_version] = '3.0'
|
364
|
+
req[:minimum_package_version] = '3'
|
365
|
+
req[:maximum_package_version] = '5'
|
366
|
+
assert(!@tpkg.package_meets_requirement?(pkg, req))
|
367
|
+
req[:minimum_package_version] = '2'
|
368
|
+
req[:maximum_package_version] = '3'
|
369
|
+
assert(@tpkg.package_meets_requirement?(pkg, req))
|
370
|
+
|
371
|
+
FileUtils.rm_f(pkgfile)
|
372
|
+
|
373
|
+
#
|
374
|
+
# Test architecture and operatingsystem handling
|
375
|
+
#
|
376
|
+
|
377
|
+
req = { :name => 'testpkg' }
|
378
|
+
|
379
|
+
# Package with no OS specified
|
380
|
+
pkgfile = make_package(:output_directory => @tempoutdir, :remove => ['operatingsystem'], :change => {'architecture' => Facter['hardwaremodel'].value})
|
381
|
+
metadata = Tpkg::metadata_from_package(pkgfile)
|
382
|
+
pkg = { :metadata => metadata, :source => pkgfile }
|
383
|
+
assert(@tpkg.package_meets_requirement?(pkg, req))
|
384
|
+
FileUtils.rm_f(pkgfile)
|
385
|
+
|
386
|
+
# Package with one matching OS
|
387
|
+
pkgfile = make_package(:output_directory => @tempoutdir, :change => {'operatingsystem' => @tpkg.os.os, 'architecture' => Facter['hardwaremodel'].value})
|
388
|
+
metadata = Tpkg::metadata_from_package(pkgfile)
|
389
|
+
pkg = { :metadata => metadata, :source => pkgfile }
|
390
|
+
assert(@tpkg.package_meets_requirement?(pkg, req))
|
391
|
+
FileUtils.rm_f(pkgfile)
|
392
|
+
|
393
|
+
# Package with a matching OS in a list of OSs
|
394
|
+
pkgfile = make_package(:output_directory => @tempoutdir, :change => {'operatingsystem' => "RedHat,CentOS,#{@tpkg.os.os},FreeBSD,Solaris", 'architecture' => Facter['hardwaremodel'].value})
|
395
|
+
metadata = Tpkg::metadata_from_package(pkgfile)
|
396
|
+
pkg = { :metadata => metadata, :source => pkgfile }
|
397
|
+
assert(@tpkg.package_meets_requirement?(pkg, req))
|
398
|
+
FileUtils.rm_f(pkgfile)
|
399
|
+
|
400
|
+
# Package with one non-matching OS
|
401
|
+
pkgfile = make_package(:output_directory => @tempoutdir, :change => {'operatingsystem' => 'bogus_os', 'architecture' => Facter['hardwaremodel'].value})
|
402
|
+
metadata = Tpkg::metadata_from_package(pkgfile)
|
403
|
+
pkg = { :metadata => metadata, :source => pkgfile }
|
404
|
+
assert(!@tpkg.package_meets_requirement?(pkg, req))
|
405
|
+
FileUtils.rm_f(pkgfile)
|
406
|
+
|
407
|
+
# Package with a list of non-matching OSs
|
408
|
+
pkgfile = make_package(:output_directory => @tempoutdir, :change => {'operatingsystem' => 'bogus_os1,bogus_os2', 'architecture' => Facter['hardwaremodel'].value})
|
409
|
+
metadata = Tpkg::metadata_from_package(pkgfile)
|
410
|
+
pkg = { :metadata => metadata, :source => pkgfile }
|
411
|
+
assert(!@tpkg.package_meets_requirement?(pkg, req))
|
412
|
+
FileUtils.rm_f(pkgfile)
|
413
|
+
|
414
|
+
# Package with no architecture specified
|
415
|
+
pkgfile = make_package(:output_directory => @tempoutdir, :remove => ['architecture'], :change => {'operatingsystem' => @tpkg.os.os })
|
416
|
+
metadata = Tpkg::metadata_from_package(pkgfile)
|
417
|
+
pkg = { :metadata => metadata, :source => pkgfile }
|
418
|
+
assert(@tpkg.package_meets_requirement?(pkg, req))
|
419
|
+
FileUtils.rm_f(pkgfile)
|
420
|
+
|
421
|
+
# Package with one matching architecture
|
422
|
+
pkgfile = make_package(:output_directory => @tempoutdir, :change => {'operatingsystem' => @tpkg.os.os, 'architecture' => Facter['hardwaremodel'].value})
|
423
|
+
metadata = Tpkg::metadata_from_package(pkgfile)
|
424
|
+
pkg = { :metadata => metadata, :source => pkgfile }
|
425
|
+
assert(@tpkg.package_meets_requirement?(pkg, req))
|
426
|
+
FileUtils.rm_f(pkgfile)
|
427
|
+
|
428
|
+
# Package with a matching architecture in a list of architectures
|
429
|
+
pkgfile = make_package(:output_directory => @tempoutdir, :change => {'operatingsystem' => @tpkg.os.os, 'architecture' => "i386,x86_64,#{Facter['hardwaremodel'].value},sparc,powerpc"})
|
430
|
+
metadata = Tpkg::metadata_from_package(pkgfile)
|
431
|
+
pkg = { :metadata => metadata, :source => pkgfile }
|
432
|
+
assert(@tpkg.package_meets_requirement?(pkg, req))
|
433
|
+
FileUtils.rm_f(pkgfile)
|
434
|
+
|
435
|
+
# Package with one non-matching architecture
|
436
|
+
pkgfile = make_package(:output_directory => @tempoutdir, :change => {'operatingsystem' => @tpkg.os.os, 'architecture' => 'bogus_arch'})
|
437
|
+
metadata = Tpkg::metadata_from_package(pkgfile)
|
438
|
+
pkg = { :metadata => metadata, :source => pkgfile }
|
439
|
+
assert(!@tpkg.package_meets_requirement?(pkg, req))
|
440
|
+
FileUtils.rm_f(pkgfile)
|
441
|
+
|
442
|
+
# Package with a list of non-matching architectures
|
443
|
+
pkgfile = make_package(:output_directory => @tempoutdir, :change => {'operatingsystem' => @tpkg.os.os, 'architecture' => 'bogus_arch1,bogus_arch2'})
|
444
|
+
metadata = Tpkg::metadata_from_package(pkgfile)
|
445
|
+
pkg = { :metadata => metadata, :source => pkgfile }
|
446
|
+
assert(!@tpkg.package_meets_requirement?(pkg, req))
|
447
|
+
FileUtils.rm_f(pkgfile)
|
448
|
+
|
449
|
+
# Package with operatingsystem and arch specified as regex
|
450
|
+
pkgfile = make_package(:output_directory => @tempoutdir, :change => {'operatingsystem' => "RedHat|CentOS|Fedora|#{@tpkg.os.os}|Debian|Ubuntu|Solaris|FreeBSD|Darwin", 'architecture' => "i386|x86_64|#{Facter['hardwaremodel'].value}|sparc|powerpc"})
|
451
|
+
metadata = Tpkg::metadata_from_package(pkgfile)
|
452
|
+
pkg = { :metadata => metadata, :source => pkgfile }
|
453
|
+
assert(@tpkg.package_meets_requirement?(pkg, req))
|
454
|
+
end
|
455
|
+
|
456
|
+
def test_available_packages_that_meet_requirement
|
457
|
+
pkgfiles = []
|
458
|
+
['1.0', '1.1', '1.2', '1.3'].each do |ver|
|
459
|
+
pkgfiles << make_package(:output_directory => @tempoutdir, :change => {'version' => ver}, :remove => ['operatingsystem', 'architecture'])
|
460
|
+
end
|
461
|
+
|
462
|
+
Dir.mktmpdir('testbase') do |testbase|
|
463
|
+
tpkg = Tpkg.new(:base => testbase, :sources => pkgfiles)
|
464
|
+
|
465
|
+
pkgs = tpkg.available_packages_that_meet_requirement
|
466
|
+
nonnativepkgs = pkgs.select do |pkg|
|
467
|
+
pkg[:source] != :native_installed && pkg[:source] != :native_available
|
468
|
+
end
|
469
|
+
assert_equal(4, nonnativepkgs.length)
|
470
|
+
|
471
|
+
# Test that the caching logic stored the answer properly
|
472
|
+
assert_equal(pkgs, tpkg.instance_variable_get(:@available_packages_cache)[nil])
|
473
|
+
# And test that it returns the cached value
|
474
|
+
fakepkgs = pkgs.dup.pop
|
475
|
+
tpkg.instance_variable_get(:@available_packages_cache)[nil] = fakepkgs
|
476
|
+
assert_equal(fakepkgs, tpkg.available_packages_that_meet_requirement)
|
477
|
+
# Put things back to normal
|
478
|
+
tpkg.instance_variable_get(:@available_packages_cache)[nil] = pkgs
|
479
|
+
|
480
|
+
req = { :name => 'testpkg' }
|
481
|
+
|
482
|
+
req[:minimum_version] = '1.2'
|
483
|
+
req[:maximum_version] = '2.0'
|
484
|
+
pkgs = tpkg.available_packages_that_meet_requirement(req)
|
485
|
+
assert_equal(2, pkgs.length)
|
486
|
+
pkgs.each do |pkg|
|
487
|
+
assert(pkg[:metadata][:version].to_f >= 1.2)
|
488
|
+
end
|
489
|
+
|
490
|
+
req[:minimum_version] = '1.1'
|
491
|
+
req[:maximum_version] = '1.2'
|
492
|
+
pkgs = tpkg.available_packages_that_meet_requirement(req)
|
493
|
+
assert_equal(2, pkgs.length)
|
494
|
+
pkgs.each do |pkg|
|
495
|
+
assert(pkg[:metadata][:version].to_f >= 1.1)
|
496
|
+
assert(pkg[:metadata][:version].to_f <= 1.2)
|
497
|
+
end
|
498
|
+
|
499
|
+
# Test a package name which has no available packages
|
500
|
+
req[:name] = 'otherpkg'
|
501
|
+
pkgs = tpkg.available_packages_that_meet_requirement(req)
|
502
|
+
assert(pkgs.empty?)
|
503
|
+
|
504
|
+
# Users should be able to specify a dependency such that they indicate
|
505
|
+
# that the desired package has no package version.
|
506
|
+
pkgfiles << make_package(:output_directory => @tempoutdir, :change => {'version' => '2'}, :remove => ['operatingsystem', 'architecture', 'package_version'])
|
507
|
+
pkgfiles << make_package(:output_directory => @tempoutdir, :change => {'version' => '2', 'package_version' => '1'}, :remove => ['operatingsystem', 'architecture'])
|
508
|
+
pkgfiles << make_package(:output_directory => @tempoutdir, :change => {'version' => '2', 'package_version' => '112'}, :remove => ['operatingsystem', 'architecture'])
|
509
|
+
tpkg = Tpkg.new(:base => testbase, :sources => pkgfiles)
|
510
|
+
|
511
|
+
req = { :name => 'testpkg' }
|
512
|
+
|
513
|
+
# FIXME: These don't look like tests of
|
514
|
+
# available_packages_that_meet_requirement. I'm too lazy to find where
|
515
|
+
# the wildcard support is implemented, but it isn't in
|
516
|
+
# available_packages_that_meet_requirement.
|
517
|
+
# Followup: It's implemented in package_meets_requirement?
|
518
|
+
# Followup 2: And now test_package_meets_requirement has tests for
|
519
|
+
# allowed_versions, so these can probably go away.
|
520
|
+
|
521
|
+
# Should only match package of version 2 and NO package version
|
522
|
+
req[:allowed_versions] = '2'
|
523
|
+
pkgs = tpkg.available_packages_that_meet_requirement(req)
|
524
|
+
assert_equal(1, pkgs.length)
|
525
|
+
|
526
|
+
# Should match any packages that has a version number that starts with 2
|
527
|
+
req[:allowed_versions] = '2*'
|
528
|
+
pkgs = tpkg.available_packages_that_meet_requirement(req)
|
529
|
+
assert_equal(3, pkgs.length)
|
530
|
+
|
531
|
+
# Should match any packages that is version 2 AND has a package version number
|
532
|
+
req[:allowed_versions] = '2-*'
|
533
|
+
pkgs = tpkg.available_packages_that_meet_requirement(req)
|
534
|
+
assert_equal(2, pkgs.length)
|
535
|
+
|
536
|
+
# Should match any packages that is version 2 AND has a package version number that ends with 2
|
537
|
+
req[:allowed_versions] = '2-*2'
|
538
|
+
pkgs = tpkg.available_packages_that_meet_requirement(req)
|
539
|
+
assert_equal(1, pkgs.length)
|
540
|
+
end
|
541
|
+
|
542
|
+
pkgfiles.each { |pkgfile| FileUtils.rm_f(pkgfile) }
|
543
|
+
end
|
544
|
+
|
545
|
+
def test_best_solution
|
546
|
+
# Test that best_solution gives us the right answer using our test
|
547
|
+
# package set in a new, clean base
|
548
|
+
Dir.mktmpdir('testbase') do |testbase|
|
549
|
+
tpkg = Tpkg.new(:base => testbase, :sources => @pkgfiles)
|
550
|
+
solution_packages = tpkg.best_solution([{:name => 'a', :type => :tpkg}], {}, ['a'])
|
551
|
+
# We should end up with a-1.0, b-1.0 (the specific one, not the generic
|
552
|
+
# one), c-1.2 and d-1.2
|
553
|
+
assert_equal(4, solution_packages.length)
|
554
|
+
good = ['a-1.0-1.tpkg', "b-1.0-1-#{Metadata.clean_for_filename(tpkg.os.os)}.tpkg", 'c-1.2-1.tpkg', 'd-1.2-1.tpkg']
|
555
|
+
solution_packages.each { |pkg| assert(good.any? { |g| pkg[:source].include?(g) }) }
|
556
|
+
end
|
557
|
+
|
558
|
+
# Now run a test to verify that we prefer already installed packages
|
559
|
+
Dir.mktmpdir('testbase') do |testbase|
|
560
|
+
# First install an older version of a
|
561
|
+
older_apkg = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'a', 'version' => '0.9' }, :remove => ['operatingsystem', 'architecture'])
|
562
|
+
tpkg = Tpkg.new(:base => testbase, :sources => [older_apkg] + @pkgfiles)
|
563
|
+
tpkg.install(['a=0.9'], PASSPHRASE)
|
564
|
+
# Now request 'a' and verify that we get back the currently installed
|
565
|
+
# 'a' pkg rather than the newer one that is available from our test
|
566
|
+
# packages
|
567
|
+
requirements = []
|
568
|
+
packages = {}
|
569
|
+
tpkg.requirements_for_currently_installed_packages(requirements, packages)
|
570
|
+
requirements << {:name => 'a', :type => :tpkg}
|
571
|
+
solution_packages = tpkg.best_solution(requirements, packages, ['a'])
|
572
|
+
assert_equal(1, solution_packages.length)
|
573
|
+
assert_equal(:currently_installed, solution_packages.first[:source])
|
574
|
+
assert_equal('a', solution_packages.first[:metadata][:name])
|
575
|
+
assert_equal('0.9', solution_packages.first[:metadata][:version])
|
576
|
+
FileUtils.rm_f(older_apkg)
|
577
|
+
end
|
578
|
+
|
579
|
+
# Test that we don't prefer installed packages if :prefer is false
|
580
|
+
Dir.mktmpdir('testbase') do |testbase|
|
581
|
+
# First install an older version of d
|
582
|
+
older_dpkg = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'd', 'version' => '0.9' }, :remove => ['operatingsystem', 'architecture'])
|
583
|
+
tpkg = Tpkg.new(:base => testbase, :sources => [older_dpkg] + @pkgfiles)
|
584
|
+
tpkg.install(['d=0.9'], PASSPHRASE)
|
585
|
+
# Now request an update of 'd' and verify that we get back the newer
|
586
|
+
# available 'd' pkg rather than the currently installed package.
|
587
|
+
requirements = []
|
588
|
+
packages = {}
|
589
|
+
tpkg.requirements_for_currently_installed_packages(requirements, packages)
|
590
|
+
# Remove preference for currently installed package
|
591
|
+
packages['d'].each do |pkg|
|
592
|
+
if pkg[:source] == :currently_installed
|
593
|
+
pkg[:prefer] = false
|
594
|
+
end
|
595
|
+
end
|
596
|
+
solution_packages = tpkg.best_solution(requirements, packages, ['d'])
|
597
|
+
assert_equal(1, solution_packages.length)
|
598
|
+
assert(solution_packages.first[:source].include?('d-1.3-1.tpkg'))
|
599
|
+
FileUtils.rm_f(older_dpkg)
|
600
|
+
end
|
601
|
+
|
602
|
+
# Test that we don't prefer installed packages if :prefer is false
|
603
|
+
# This is a more complex test than the previous, as the 'a' package
|
604
|
+
# in our test @pkgfiles has dependencies, whereas the initial older
|
605
|
+
# version we install does not. The new dependencies could throw off
|
606
|
+
# the scoring process.
|
607
|
+
Dir.mktmpdir('testbase') do |testbase|
|
608
|
+
# First install an older version of a
|
609
|
+
older_apkg = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'a', 'version' => '0.9' }, :remove => ['operatingsystem', 'architecture'])
|
610
|
+
tpkg = Tpkg.new(:base => testbase, :sources => [older_apkg] + @pkgfiles)
|
611
|
+
tpkg.install(['a=0.9'], PASSPHRASE)
|
612
|
+
# Now request an update of 'a' and verify that we get back the newer
|
613
|
+
# available 'a' pkg rather than the currently installed package.
|
614
|
+
requirements = []
|
615
|
+
packages = {}
|
616
|
+
tpkg.requirements_for_currently_installed_packages(requirements, packages)
|
617
|
+
# Remove preference for currently installed package
|
618
|
+
packages['a'].each do |pkg|
|
619
|
+
if pkg[:source] == :currently_installed
|
620
|
+
pkg[:prefer] = false
|
621
|
+
end
|
622
|
+
end
|
623
|
+
solution_packages = tpkg.best_solution(requirements, packages, ['a'])
|
624
|
+
# The solution should pull in the newer 'a' and its dependencies
|
625
|
+
assert_equal(4, solution_packages.length)
|
626
|
+
selectedapkg = solution_packages.find{|pkg| pkg[:metadata][:name] == 'a'}
|
627
|
+
assert(selectedapkg[:source].include?('a-1.0-1.tpkg'))
|
628
|
+
FileUtils.rm_f(older_apkg)
|
629
|
+
end
|
630
|
+
|
631
|
+
# Test that we can handle simultaneous dependency on a native package and
|
632
|
+
# a tpkg with the same name. For this we need a native package that is
|
633
|
+
# generally available on systems that developers are likely to use, I'm
|
634
|
+
# going to use wget for now.
|
635
|
+
# FIXME: should have a better way of excluding platforms with no native
|
636
|
+
# package support
|
637
|
+
if @tpkg.os.os !~ /windows/
|
638
|
+
nativedep = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'nativedep' }, :dependencies => {'wget' => {'native' => true}}, :remove => ['operatingsystem', 'architecture'])
|
639
|
+
tpkgdep = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'tpkgdep' }, :dependencies => {'wget' => {}}, :remove => ['operatingsystem', 'architecture'])
|
640
|
+
wget = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'wget' }, :remove => ['operatingsystem', 'architecture'])
|
641
|
+
parent = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'parent' }, :dependencies => {'nativedep' => {}, 'tpkgdep' => {}}, :remove => ['operatingsystem', 'architecture'])
|
642
|
+
Dir.mktmpdir('testbase') do |testbase|
|
643
|
+
mixeddeppkgs = [nativedep, tpkgdep, wget, parent]
|
644
|
+
tpkg = Tpkg.new(:base => testbase, :sources => mixeddeppkgs)
|
645
|
+
solution_packages = tpkg.best_solution([{:name => 'parent', :type => :tpkg}], {}, ['parent'])
|
646
|
+
# The solution should include the four tpkgs plus a native wget
|
647
|
+
assert_equal(5, solution_packages.length)
|
648
|
+
assert(solution_packages.any? {|sp| sp[:metadata][:name] == 'wget' && (sp[:source] == :native_available || sp[:source] == :native_installed)})
|
649
|
+
assert(solution_packages.any? {|sp| sp[:metadata][:name] == 'wget' && sp[:source].include?('wget-1.0-1.tpkg')})
|
650
|
+
mixeddeppkgs.each do |mdp|
|
651
|
+
FileUtils.rm_f(mdp)
|
652
|
+
end
|
653
|
+
end
|
654
|
+
end
|
655
|
+
|
656
|
+
# Test with no valid solution, ensure it fails
|
657
|
+
Dir.mktmpdir('testbase') do |testbase|
|
658
|
+
tpkg = Tpkg.new(:base => testbase, :sources => @pkgfiles)
|
659
|
+
solution_packages = nil
|
660
|
+
assert_nothing_raised { solution_packages = tpkg.best_solution([{:name => 'a', :type => :tpkg}, {:name => 'c', :minimum_version => '1.3', :type => :tpkg}], {}, ['a', 'c']) }
|
661
|
+
assert_nil(solution_packages)
|
662
|
+
end
|
663
|
+
|
664
|
+
# The test recreates a set of circumstances that triggered a bug at one
|
665
|
+
# point. There are several versions of the requested package which depend
|
666
|
+
# on a non-existent package. This particular arrangement led to
|
667
|
+
# attempting to reference a nil value as a pkg.
|
668
|
+
Dir.mktmpdir('testbase') do |testbase|
|
669
|
+
baddep1 = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'baddep', 'version' => '1' }, :remove => ['operatingsystem', 'architecture'])
|
670
|
+
baddep2 = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'baddep', 'version' => '2' }, :dependencies => {'bogus' => {}}, :remove => ['operatingsystem', 'architecture'])
|
671
|
+
baddep3 = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'baddep', 'version' => '2' }, :dependencies => {'bogus' => {}}, :remove => ['operatingsystem', 'architecture'])
|
672
|
+
tpkg = Tpkg.new(:base => testbase, :sources => [baddep1, baddep2, baddep3])
|
673
|
+
solution_packages = nil
|
674
|
+
assert_nothing_raised { solution_packages = tpkg.best_solution([{:name => 'baddep', :type => :tpkg}], {}, ['baddep']) }
|
675
|
+
assert_equal(1, solution_packages.length)
|
676
|
+
assert(solution_packages.first[:source] == baddep1)
|
677
|
+
end
|
678
|
+
|
679
|
+
# This test recreates another set of circumstances that triggered a bug.
|
680
|
+
# The format of the packages argument to resolve_dependencies changed and
|
681
|
+
# the attempts to dup it in order to avoid messing up the state of callers
|
682
|
+
# of resolve_dependencies were no longer effective. Thus the state of
|
683
|
+
# callers of resolve_dependencies was messed up and it would fail to find
|
684
|
+
# valid solutions.
|
685
|
+
Dir.mktmpdir('testbase') do |testbase|
|
686
|
+
baddep1 = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'baddep', 'version' => '1' }, :dependencies => {'notbogus' => {}}, :remove => ['operatingsystem', 'architecture'])
|
687
|
+
baddep2 = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'baddep', 'version' => '2' }, :dependencies => {'notbogus' => {}, 'bogus' => {}}, :remove => ['operatingsystem', 'architecture'])
|
688
|
+
notbogus = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'notbogus', 'version' => '1' }, :remove => ['operatingsystem', 'architecture'])
|
689
|
+
bogus = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'bogus', 'version' => '1', 'operatingsystem' => 'bogusos' }, :remove => ['architecture'])
|
690
|
+
tpkg = Tpkg.new(:base => testbase, :sources => [baddep1, baddep2, notbogus, bogus])
|
691
|
+
solution_packages = nil
|
692
|
+
assert_nothing_raised { solution_packages = tpkg.best_solution([{:name => 'baddep', :type => :tpkg}], {}, ['baddep']) }
|
693
|
+
assert_equal(2, solution_packages.length)
|
694
|
+
assert(solution_packages.any? {|sp| sp[:source] == baddep1})
|
695
|
+
assert(solution_packages.any? {|sp| sp[:source] == notbogus})
|
696
|
+
end
|
697
|
+
end
|
698
|
+
|
699
|
+
# best_solution is a thin wrapper of this method, most of the testing
|
700
|
+
# is in test_best_solution
|
701
|
+
def test_resolve_dependencies
|
702
|
+
Dir.mktmpdir('testbase') do |testbase|
|
703
|
+
tpkg = Tpkg.new(:base => testbase, :sources => @pkgfiles)
|
704
|
+
|
705
|
+
result = tpkg.resolve_dependencies([{:name => 'a', :type => :tpkg}], {:tpkg => {}, :native => {}}, ['a'])
|
706
|
+
assert(result.has_key?(:solution))
|
707
|
+
solution = result[:solution]
|
708
|
+
|
709
|
+
# We should end up with a-1.0, b-1.0 (the specific one, not the generic
|
710
|
+
# one), c-1.2 and d-1.2
|
711
|
+
assert_equal(4, solution.length)
|
712
|
+
good = ['a-1.0-1.tpkg', "b-1.0-1-#{Metadata.clean_for_filename(tpkg.os.os)}.tpkg", 'c-1.2-1.tpkg', 'd-1.2-1.tpkg']
|
713
|
+
solution.each { |pkg| assert(good.any? { |g| pkg[:source].include?(g) }) }
|
714
|
+
end
|
715
|
+
end
|
716
|
+
|
717
|
+
# This method is only used by resolve_dependencies, so the testing
|
718
|
+
# here is minimal.
|
719
|
+
def test_check_solution
|
720
|
+
Dir.mktmpdir('testbase') do |testbase|
|
721
|
+
tpkg = Tpkg.new(:base => testbase, :sources => @pkgfiles)
|
722
|
+
|
723
|
+
solution = nil
|
724
|
+
requirements = [{:name => 'c', :minimum_version => '1.3', :type => :tpkg}, {:name => 'd', :minimum_version => '1.3', :type => :tpkg}]
|
725
|
+
packages = {:tpkg => {}, :native => {}}
|
726
|
+
requirements.each do |req|
|
727
|
+
packages[req[:type]][req[:name]] = tpkg.available_packages_that_meet_requirement(req)
|
728
|
+
end
|
729
|
+
core_packages = ['c']
|
730
|
+
number_of_possible_solutions_checked = 0
|
731
|
+
|
732
|
+
result = nil
|
733
|
+
# Check a valid solution
|
734
|
+
solution = {:pkgs => packages[:tpkg].values.flatten}
|
735
|
+
assert_nothing_raised { result = tpkg.check_solution(solution, requirements, packages, core_packages, number_of_possible_solutions_checked) }
|
736
|
+
assert(result.has_key?(:solution))
|
737
|
+
assert_equal(packages[:tpkg].values.flatten, result[:solution])
|
738
|
+
|
739
|
+
# Check an invalid solution
|
740
|
+
xpkgfile = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'x' }, :dependencies => {'y' => {}}, :remove => ['operatingsystem', 'architecture'])
|
741
|
+
metadata = Tpkg::metadata_from_package(xpkgfile)
|
742
|
+
xpkg = {:metadata => metadata}
|
743
|
+
solution[:pkgs] << xpkg
|
744
|
+
assert_nothing_raised { result = tpkg.check_solution(solution, requirements, packages, core_packages, number_of_possible_solutions_checked) }
|
745
|
+
assert(!result.has_key?(:solution))
|
746
|
+
assert(result.has_key?(:number_of_possible_solutions_checked))
|
747
|
+
assert(result[:number_of_possible_solutions_checked] > 0)
|
748
|
+
FileUtils.rm_f(xpkgfile)
|
749
|
+
end
|
750
|
+
end
|
751
|
+
|
752
|
+
def test_requirements_for_currently_installed_package
|
753
|
+
pkgfile = make_package(:output_directory => @tempoutdir, :remove => ['operatingsystem', 'architecture'])
|
754
|
+
pkgfile2 = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'testpkg2' }, :remove => ['package_version', 'operatingsystem', 'architecture'])
|
755
|
+
Dir.mktmpdir('testbase') do |testbase|
|
756
|
+
tpkg = Tpkg.new(:base => testbase, :sources => [pkgfile, pkgfile2])
|
757
|
+
tpkg.install(['testpkg'])
|
758
|
+
tpkg.install(['testpkg2'])
|
759
|
+
requirements = nil
|
760
|
+
assert_nothing_raised { requirements = tpkg.requirements_for_currently_installed_package('testpkg') }
|
761
|
+
assert_equal(1, requirements.length)
|
762
|
+
assert_equal('testpkg', requirements.first[:name])
|
763
|
+
assert_equal('1.0', requirements.first[:minimum_version])
|
764
|
+
assert_equal('1', requirements.first[:minimum_package_version])
|
765
|
+
assert_equal(:tpkg, requirements.first[:type])
|
766
|
+
assert_nothing_raised { requirements = tpkg.requirements_for_currently_installed_package('testpkg2') }
|
767
|
+
assert_equal(1, requirements.length)
|
768
|
+
assert_equal('testpkg2', requirements.first[:name])
|
769
|
+
assert_equal('1.0', requirements.first[:minimum_version])
|
770
|
+
assert_nil(requirements.first[:minimum_package_version])
|
771
|
+
assert_equal(:tpkg, requirements.first[:type])
|
772
|
+
end
|
773
|
+
FileUtils.rm_f(pkgfile)
|
774
|
+
FileUtils.rm_f(pkgfile2)
|
775
|
+
end
|
776
|
+
|
777
|
+
def test_requirements_for_currently_installed_packages
|
778
|
+
Dir.mktmpdir('testbase') do |testbase|
|
779
|
+
apkg = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'a', 'version' => '2.0' }, :remove => ['operatingsystem', 'architecture'])
|
780
|
+
tpkg = Tpkg.new(:base => testbase, :sources => [apkg])
|
781
|
+
tpkg.install(['a'], PASSPHRASE)
|
782
|
+
requirements = []
|
783
|
+
packages = {}
|
784
|
+
tpkg.requirements_for_currently_installed_packages(requirements, packages)
|
785
|
+
assert_equal(1, requirements.length)
|
786
|
+
assert_equal('a', requirements.first[:name])
|
787
|
+
assert_equal('2.0', requirements.first[:minimum_version])
|
788
|
+
assert_equal(:tpkg, requirements.first[:type])
|
789
|
+
# Given the way we set up the tpkg instance we should have two entries
|
790
|
+
# in packages, one for the installed copy of the package and one for the
|
791
|
+
# uninstalled copy
|
792
|
+
assert_equal(2, packages['a'].length)
|
793
|
+
assert(packages['a'].any? { |pkg| pkg[:source] == :currently_installed })
|
794
|
+
assert(packages['a'].any? { |pkg| pkg[:source].include?('a-2.0-1.tpkg') })
|
795
|
+
currently_installed_pkg = packages['a'].find { |pkg| pkg[:source] == :currently_installed }
|
796
|
+
assert(currently_installed_pkg[:prefer])
|
797
|
+
FileUtils.rm_f(apkg)
|
798
|
+
end
|
799
|
+
end
|
800
|
+
def test_parse_request
|
801
|
+
req = Tpkg::parse_request('a-2.0-1.tpkg')
|
802
|
+
assert_equal(3, req.length)
|
803
|
+
assert_equal('a', req[:name])
|
804
|
+
assert_equal('a-2.0-1.tpkg', req[:filename])
|
805
|
+
assert_equal(:tpkg, req[:type])
|
806
|
+
req = Tpkg::parse_request('a-b-c-2.0-1.tpkg')
|
807
|
+
assert_equal(3, req.length)
|
808
|
+
assert_equal('a-b-c', req[:name])
|
809
|
+
assert_equal('a-b-c-2.0-1.tpkg', req[:filename])
|
810
|
+
assert_equal(:tpkg, req[:type])
|
811
|
+
|
812
|
+
req = Tpkg::parse_request('a')
|
813
|
+
assert_equal(2, req.length)
|
814
|
+
assert_equal('a', req[:name])
|
815
|
+
assert_equal(:tpkg, req[:type])
|
816
|
+
|
817
|
+
# req = Tpkg::parse_request('a=1.0')
|
818
|
+
# assert_equal(4, req.length)
|
819
|
+
# assert_equal('a', req[:name])
|
820
|
+
# assert_equal('1.0', req[:minimum_version])
|
821
|
+
# assert_equal('1.0', req[:maximum_version])
|
822
|
+
# assert_equal(:tpkg, req[:type])
|
823
|
+
|
824
|
+
# req = Tpkg::parse_request('a=1.0=1')
|
825
|
+
# assert_equal(6, req.length)
|
826
|
+
# assert_equal('a', req[:name])
|
827
|
+
# assert_equal('1.0', req[:minimum_version])
|
828
|
+
# assert_equal('1.0', req[:maximum_version])
|
829
|
+
# assert_equal('1', req[:minimum_package_version])
|
830
|
+
# assert_equal('1', req[:maximum_package_version])
|
831
|
+
# assert_equal(:tpkg, req[:type])
|
832
|
+
|
833
|
+
['<', '<=', '=', '>=', '>'].each do |verequal|
|
834
|
+
req = Tpkg::parse_request("a#{verequal}1.0")
|
835
|
+
assert_equal('a', req[:name])
|
836
|
+
baseparts = 2 # req[:name] and req[:type]
|
837
|
+
verparts = nil
|
838
|
+
if verequal == '>='
|
839
|
+
verparts = 1
|
840
|
+
assert_equal('1.0', req[:minimum_version])
|
841
|
+
elsif verequal == '>'
|
842
|
+
verparts = 1
|
843
|
+
assert_equal('1.0', req[:version_greater_than])
|
844
|
+
elsif verequal == '='
|
845
|
+
verparts = 2
|
846
|
+
assert_equal('1.0', req[:minimum_version])
|
847
|
+
assert_equal('1.0', req[:maximum_version])
|
848
|
+
elsif verequal == '<'
|
849
|
+
verparts = 1
|
850
|
+
assert_equal('1.0', req[:version_less_than])
|
851
|
+
elsif verequal == '<='
|
852
|
+
verparts = 1
|
853
|
+
assert_equal('1.0', req[:maximum_version])
|
854
|
+
end
|
855
|
+
assert_equal(:tpkg, req[:type])
|
856
|
+
assert_equal(baseparts+verparts, req.length)
|
857
|
+
['<', '<=', '=', '>=', '>'].each do |packverequal|
|
858
|
+
req = Tpkg::parse_request("a#{verequal}1.0#{packverequal}1")
|
859
|
+
assert_equal('a', req[:name])
|
860
|
+
if verequal == '>='
|
861
|
+
assert_equal('1.0', req[:minimum_version])
|
862
|
+
elsif verequal == '>'
|
863
|
+
assert_equal('1.0', req[:version_greater_than])
|
864
|
+
elsif verequal == '='
|
865
|
+
assert_equal('1.0', req[:minimum_version])
|
866
|
+
assert_equal('1.0', req[:maximum_version])
|
867
|
+
elsif verequal == '<'
|
868
|
+
assert_equal('1.0', req[:version_less_than])
|
869
|
+
elsif verequal == '<='
|
870
|
+
assert_equal('1.0', req[:maximum_version])
|
871
|
+
end
|
872
|
+
packverparts = nil
|
873
|
+
if packverequal == '>='
|
874
|
+
packverparts = 1
|
875
|
+
assert_equal('1', req[:minimum_package_version])
|
876
|
+
elsif packverequal == '>'
|
877
|
+
packverparts = 1
|
878
|
+
assert_equal('1', req[:package_version_greater_than])
|
879
|
+
elsif packverequal == '='
|
880
|
+
packverparts = 2
|
881
|
+
assert_equal('1', req[:minimum_package_version])
|
882
|
+
assert_equal('1', req[:maximum_package_version])
|
883
|
+
elsif packverequal == '<'
|
884
|
+
packverparts = 1
|
885
|
+
assert_equal('1', req[:package_version_less_than])
|
886
|
+
elsif packverequal == '<='
|
887
|
+
packverparts = 1
|
888
|
+
assert_equal('1', req[:maximum_package_version])
|
889
|
+
end
|
890
|
+
assert_equal(:tpkg, req[:type])
|
891
|
+
assert_equal(baseparts+verparts+packverparts, req.length)
|
892
|
+
end
|
893
|
+
end
|
894
|
+
|
895
|
+
# parse_request should take the last two = components off the end of the
|
896
|
+
# string. I don't think it is too likely that package names will contain
|
897
|
+
# =, but better safe than sorry.
|
898
|
+
req = Tpkg::parse_request('a=b=c=1.0=1')
|
899
|
+
assert_equal(6, req.length)
|
900
|
+
assert_equal('a=b=c', req[:name])
|
901
|
+
assert_equal('1.0', req[:minimum_version])
|
902
|
+
assert_equal('1.0', req[:maximum_version])
|
903
|
+
assert_equal('1', req[:minimum_package_version])
|
904
|
+
assert_equal('1', req[:maximum_package_version])
|
905
|
+
assert_equal(:tpkg, req[:type])
|
906
|
+
|
907
|
+
req = Tpkg::parse_request('a=1.*')
|
908
|
+
assert_equal(3, req.length, req.inspect)
|
909
|
+
assert_equal('a', req[:name])
|
910
|
+
assert_equal('1.*', req[:allowed_versions])
|
911
|
+
assert_equal(:tpkg, req[:type])
|
912
|
+
|
913
|
+
req = Tpkg::parse_request('a=1.0-1.2.*')
|
914
|
+
assert_equal(3, req.length, req.inspect)
|
915
|
+
assert_equal('a', req[:name])
|
916
|
+
assert_equal('1.0-1.2.*', req[:allowed_versions])
|
917
|
+
assert_equal(:tpkg, req[:type])
|
918
|
+
|
919
|
+
# Test package with special character like "++"
|
920
|
+
req = Tpkg::parse_request('a++=1.0=1')
|
921
|
+
assert_equal(6, req.length)
|
922
|
+
assert_equal('a++', req[:name])
|
923
|
+
assert_equal('1.0', req[:minimum_version])
|
924
|
+
assert_equal('1.0', req[:maximum_version])
|
925
|
+
assert_equal('1', req[:minimum_package_version])
|
926
|
+
assert_equal('1', req[:maximum_package_version])
|
927
|
+
assert_equal(:tpkg, req[:type])
|
928
|
+
end
|
929
|
+
def test_parse_requests
|
930
|
+
[{:installed_only => true}, {:installed_only => false}, {}].each do |options|
|
931
|
+
# Test various package spec requests
|
932
|
+
Dir.mktmpdir('testbase') do |testbase|
|
933
|
+
tpkg = Tpkg.new(:base => testbase, :sources => @pkgfiles)
|
934
|
+
requirements = []
|
935
|
+
packages = {}
|
936
|
+
tpkg.parse_requests(['a'], requirements, packages, options)
|
937
|
+
assert_equal(1, requirements.length, options.inspect)
|
938
|
+
assert_equal(2, requirements.first.length, options.inspect)
|
939
|
+
assert_equal('a', requirements.first[:name], options.inspect)
|
940
|
+
assert_equal(:tpkg, requirements.first[:type], options.inspect)
|
941
|
+
if options[:installed_only] == true
|
942
|
+
assert_equal(0, packages['a'].length, options.inspect)
|
943
|
+
else
|
944
|
+
assert_equal(1, packages['a'].length, options.inspect)
|
945
|
+
end
|
946
|
+
end
|
947
|
+
|
948
|
+
Dir.mktmpdir('testbase') do |testbase|
|
949
|
+
tpkg = Tpkg.new(:base => testbase, :sources => @pkgfiles)
|
950
|
+
requirements = []
|
951
|
+
packages = {}
|
952
|
+
tpkg.parse_requests(['a=1.0'], requirements, packages, options)
|
953
|
+
assert_equal(1, requirements.length, options.inspect)
|
954
|
+
assert_equal(4, requirements.first.length, options.inspect)
|
955
|
+
assert_equal('a', requirements.first[:name], options.inspect)
|
956
|
+
assert_equal('1.0', requirements.first[:minimum_version], options.inspect)
|
957
|
+
assert_equal('1.0', requirements.first[:maximum_version], options.inspect)
|
958
|
+
assert_equal(:tpkg, requirements.first[:type], options.inspect)
|
959
|
+
if options[:installed_only] == true
|
960
|
+
assert_equal(0, packages['a'].length, options.inspect)
|
961
|
+
else
|
962
|
+
assert_equal(1, packages['a'].length, options.inspect)
|
963
|
+
end
|
964
|
+
end
|
965
|
+
|
966
|
+
Dir.mktmpdir('testbase') do |testbase|
|
967
|
+
tpkg = Tpkg.new(:base => testbase, :sources => @pkgfiles)
|
968
|
+
requirements = []
|
969
|
+
packages = {}
|
970
|
+
tpkg.parse_requests(['a=1.0=1'], requirements, packages, options)
|
971
|
+
assert_equal(1, requirements.length, options.inspect)
|
972
|
+
assert_equal(6, requirements.first.length, options.inspect)
|
973
|
+
assert_equal('a', requirements.first[:name], options.inspect)
|
974
|
+
assert_equal('1.0', requirements.first[:minimum_version], options.inspect)
|
975
|
+
assert_equal('1.0', requirements.first[:maximum_version], options.inspect)
|
976
|
+
assert_equal('1', requirements.first[:minimum_package_version], options.inspect)
|
977
|
+
assert_equal('1', requirements.first[:maximum_package_version], options.inspect)
|
978
|
+
assert_equal(:tpkg, requirements.first[:type], options.inspect)
|
979
|
+
if options[:installed_only] == true
|
980
|
+
assert_equal(0, packages['a'].length, options.inspect)
|
981
|
+
else
|
982
|
+
assert_equal(1, packages['a'].length, options.inspect)
|
983
|
+
end
|
984
|
+
end
|
985
|
+
|
986
|
+
# Test with a given filename (full path to the actual package) rather than a package spec
|
987
|
+
Dir.mktmpdir('testbase') do |testbase|
|
988
|
+
tpkg = Tpkg.new(:base => testbase, :sources => @pkgfiles)
|
989
|
+
apkg = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'a', 'version' => '2.0' }, :remove => ['operatingsystem', 'architecture'])
|
990
|
+
requirements = []
|
991
|
+
packages = {}
|
992
|
+
tpkg.parse_requests([apkg], requirements, packages, options)
|
993
|
+
assert_equal(1, requirements.length, options.inspect)
|
994
|
+
assert_equal(2, requirements.first.length, options.inspect) # should this be 6?
|
995
|
+
assert_equal('a', requirements.first[:name], options.inspect)
|
996
|
+
assert_equal(:tpkg, requirements.first[:type], options.inspect)
|
997
|
+
assert_equal(1, packages['a'].length, options.inspect)
|
998
|
+
FileUtils.rm_f(apkg)
|
999
|
+
end
|
1000
|
+
|
1001
|
+
# Test with a filename of a package that has been installed rather than a package spec
|
1002
|
+
Dir.mktmpdir('testbase') do |testbase|
|
1003
|
+
tpkg = Tpkg.new(:base => testbase, :sources => @pkgfiles)
|
1004
|
+
apkg = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'a', 'version' => '2.0' }, :remove => ['operatingsystem', 'architecture'])
|
1005
|
+
tpkg.install([apkg], PASSPHRASE)
|
1006
|
+
FileUtils.rm_f(apkg)
|
1007
|
+
requirements = []
|
1008
|
+
packages = {}
|
1009
|
+
tpkg.parse_requests([File.basename(apkg)], requirements, packages, options)
|
1010
|
+
assert_equal(1, requirements.length, options.inspect)
|
1011
|
+
assert_equal(3, requirements.first.length, options.inspect) # name, filename, type
|
1012
|
+
assert_equal('a', requirements.first[:name], options.inspect)
|
1013
|
+
assert_equal(File.basename(apkg), requirements.first[:filename], options.inspect)
|
1014
|
+
assert_equal(:tpkg, requirements.first[:type], options.inspect)
|
1015
|
+
assert_equal(1, packages['a'].length, options.inspect)
|
1016
|
+
end
|
1017
|
+
|
1018
|
+
# Test package with special character like "++"
|
1019
|
+
Dir.mktmpdir('testbase') do |testbase|
|
1020
|
+
apkg = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'a++', 'version' => '2.0' }, :remove => ['operatingsystem', 'architecture'])
|
1021
|
+
tpkg = Tpkg.new(:base => testbase, :sources => @pkgfiles + [apkg])
|
1022
|
+
requirements = []
|
1023
|
+
packages = {}
|
1024
|
+
tpkg.parse_requests([apkg], requirements, packages, options)
|
1025
|
+
assert_equal(1, requirements.length, options.inspect)
|
1026
|
+
assert_equal(2, requirements.first.length, options.inspect)
|
1027
|
+
assert_equal('a++', requirements.first[:name], options.inspect)
|
1028
|
+
assert_equal(:tpkg, requirements.first[:type], options.inspect)
|
1029
|
+
assert_equal(1, packages['a++'].length, options.inspect)
|
1030
|
+
|
1031
|
+
requirements = []
|
1032
|
+
packages = {}
|
1033
|
+
tpkg.parse_requests(["a++"], requirements, packages, options)
|
1034
|
+
assert_equal(1, requirements.length, options.inspect)
|
1035
|
+
assert_equal(2, requirements.first.length, options.inspect)
|
1036
|
+
assert_equal('a++', requirements.first[:name], options.inspect)
|
1037
|
+
assert_equal(:tpkg, requirements.first[:type], options.inspect)
|
1038
|
+
if options[:installed_only] == true
|
1039
|
+
assert_equal(0, packages['a++'].length, options.inspect)
|
1040
|
+
else
|
1041
|
+
assert_equal(1, packages['a++'].length, options.inspect)
|
1042
|
+
end
|
1043
|
+
end
|
1044
|
+
end
|
1045
|
+
end
|
1046
|
+
|
1047
|
+
def test_check_requests
|
1048
|
+
# check_requests does some additional checks for requests by
|
1049
|
+
# filename or URI, test those
|
1050
|
+
Dir.mktmpdir('testbase') do |testbase|
|
1051
|
+
tpkg = Tpkg.new(:base => testbase, :sources => @pkgfiles)
|
1052
|
+
requirements = []
|
1053
|
+
packages = {}
|
1054
|
+
|
1055
|
+
# First just check that it properly checks a package with dependencies
|
1056
|
+
apkg = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'a', 'version' => '2.0' }, :dependencies => {'b' => {}}, :remove => ['operatingsystem', 'architecture'])
|
1057
|
+
tpkg.parse_requests([apkg], requirements, packages)
|
1058
|
+
assert_nothing_raised { tpkg.check_requests(packages) }
|
1059
|
+
assert_equal(1, requirements.length)
|
1060
|
+
assert_equal(2, requirements.first.length)
|
1061
|
+
assert_equal('a', requirements.first[:name])
|
1062
|
+
assert_equal(:tpkg, requirements.first[:type])
|
1063
|
+
assert_equal(1, packages['a'].length)
|
1064
|
+
requirements.clear
|
1065
|
+
packages.clear
|
1066
|
+
FileUtils.rm_f(apkg)
|
1067
|
+
|
1068
|
+
# package dependencies on install when installing local package files
|
1069
|
+
# (i.e. not sourced from a server)
|
1070
|
+
# Check that tpkg accept list of local packages where one depends on another
|
1071
|
+
localapkg = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'locala', 'version' => '1.0' }, :remove => ['operatingsystem', 'architecture'])
|
1072
|
+
localbpkg = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'localb', 'version' => '1.0' }, :dependencies => {'locala' => {}}, :remove => ['operatingsystem', 'architecture'])
|
1073
|
+
localcpkg = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'localc', 'version' => '1.0' }, :dependencies => {'nonexisting' => {}}, :remove => ['operatingsystem', 'architecture'])
|
1074
|
+
tpkg.parse_requests([localapkg, localbpkg], requirements, packages)
|
1075
|
+
assert_nothing_raised { tpkg.check_requests(packages) }
|
1076
|
+
requirements.clear
|
1077
|
+
packages.clear
|
1078
|
+
tpkg.parse_requests([localbpkg, localapkg], requirements, packages)
|
1079
|
+
assert_nothing_raised { tpkg.check_requests(packages) }
|
1080
|
+
requirements.clear
|
1081
|
+
packages.clear
|
1082
|
+
# Should not be ok since localc depends on nonexisting package
|
1083
|
+
tpkg.parse_requests([localapkg, localbpkg, localcpkg], requirements, packages)
|
1084
|
+
assert_raise(RuntimeError) { tpkg.check_requests(packages) }
|
1085
|
+
requirements.clear
|
1086
|
+
packages.clear
|
1087
|
+
FileUtils.rm_f(localapkg)
|
1088
|
+
FileUtils.rm_f(localbpkg)
|
1089
|
+
|
1090
|
+
# Verify that it rejects a package that can't be installed on this
|
1091
|
+
# machine
|
1092
|
+
apkg = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'a', 'version' => '2.0', 'operatingsystem' => 'bogusos' }, :dependencies => {'b' => {}})
|
1093
|
+
tpkg.parse_requests([apkg], requirements, packages)
|
1094
|
+
assert_raise(RuntimeError) { tpkg.check_requests(packages) }
|
1095
|
+
requirements.clear
|
1096
|
+
packages.clear
|
1097
|
+
FileUtils.rm_f(apkg)
|
1098
|
+
|
1099
|
+
# Verify that it rejects a package with an unresolvable dependency
|
1100
|
+
apkg = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'a', 'version' => '2.0' }, :dependencies => {'x' => {}}, :remove => ['operatingsystem', 'architecture'])
|
1101
|
+
tpkg.parse_requests([apkg], requirements, packages)
|
1102
|
+
assert_raise(RuntimeError) { tpkg.check_requests(packages) }
|
1103
|
+
requirements.clear
|
1104
|
+
packages.clear
|
1105
|
+
FileUtils.rm_f(apkg)
|
1106
|
+
end
|
1107
|
+
end
|
1108
|
+
|
1109
|
+
def teardown
|
1110
|
+
@pkgfiles.each { |pkgfile| FileUtils.rm_f(pkgfile) }
|
1111
|
+
FileUtils.rm_rf(@tempoutdir)
|
1112
|
+
end
|
1113
|
+
end
|